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 swiftpmMakeMutable swift-tools-support-core
62 patch -p1 -d .build/checkouts/swift-tools-support-core -i ${
63 fetchpatch {
64 url = "https://github.com/apple/swift-tools-support-core/commit/990afca47e75cce136d2f59e464577e68a164035.patch";
65 hash = "sha256-PLzWsp+syiUBHhEFS8+WyUcSae5p0Lhk7SSRdNvfouE=";
66 includes = [ "Sources/TSCBasic/FileSystem.swift" ];
67 }
68 }
69 '';
70
71 # TODO: Tests depend on indexstore-db being provided by an existing Swift
72 # toolchain. (ie. looks for `../lib/libIndexStore.so` relative to swiftc.
73 #doCheck = true;
74
75 # TODO: Darwin-specific installation includes more, but not sure why.
76 installPhase = ''
77 binPath="$(swiftpmBinPath)"
78 mkdir -p $out/bin
79 for executable in swift-driver swift-help swift-build-sdk-interfaces; do
80 cp $binPath/$executable $out/bin/
81 done
82 '';
83
84 meta = {
85 description = "Swift compiler driver";
86 homepage = "https://github.com/apple/swift-driver";
87 platforms = with lib.platforms; linux ++ darwin;
88 license = lib.licenses.asl20;
89 teams = [ lib.teams.swift ];
90 };
91}