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