nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 callPackage,
5 fetchpatch,
6 swift,
7 swiftpm,
8 swiftpm2nix,
9 Foundation,
10 XCTest,
11 sqlite,
12 ncurses,
13 clang,
14 replaceVars,
15}:
16let
17 sources = callPackage ../sources.nix { };
18 generated = swiftpm2nix.helpers ./generated;
19
20 # On Darwin, we only want ncurses in the linker search path, because headers
21 # are part of libsystem. Adding its headers to the search path causes strange
22 # mixing and errors.
23 # TODO: Find a better way to prevent this conflict.
24 ncursesInput = if stdenv.hostPlatform.isDarwin then ncurses.out else ncurses;
25in
26stdenv.mkDerivation {
27 pname = "swift-driver";
28
29 inherit (sources) version;
30 src = sources.swift-driver;
31
32 nativeBuildInputs = [
33 swift
34 swiftpm
35 ];
36 buildInputs = [
37 Foundation
38 XCTest
39 sqlite
40 ncursesInput
41 ];
42
43 patches = [
44 ./patches/disable-catalyst.patch
45 (replaceVars ./patches/linux-fix-linking.patch {
46 inherit clang;
47 })
48 # TODO: Replace with branch patch once merged:
49 # https://github.com/apple/swift-driver/pull/1197
50 (fetchpatch {
51 url = "https://github.com/apple/swift-driver/commit/d3ef9cdf4871a58eddec7ff0e28fe611130da3f9.patch";
52 hash = "sha256-eVBaKN6uzj48ZnHtwGV0k5ChKjak1tDCyE+wTdyGq2c=";
53 })
54 # Prevent a warning about SDK directories we don't have.
55 (replaceVars ./patches/prevent-sdk-dirs-warnings.patch {
56 inherit (builtins) storeDir;
57 })
58 ];
59
60 configurePhase = generated.configure;
61
62 # TODO: Tests depend on indexstore-db being provided by an existing Swift
63 # toolchain. (ie. looks for `../lib/libIndexStore.so` relative to swiftc.
64 #doCheck = true;
65
66 # TODO: Darwin-specific installation includes more, but not sure why.
67 installPhase = ''
68 binPath="$(swiftpmBinPath)"
69 mkdir -p $out/bin
70 for executable in swift-driver swift-help swift-build-sdk-interfaces; do
71 cp $binPath/$executable $out/bin/
72 done
73 '';
74
75 meta = {
76 description = "Swift compiler driver";
77 homepage = "https://github.com/apple/swift-driver";
78 platforms = with lib.platforms; linux ++ darwin;
79 license = lib.licenses.asl20;
80 teams = [ lib.teams.swift ];
81 };
82}