about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/swift/swift-driver/default.nix
blob: d69a4da0eb3e161fea5ff61a6ebeb181ffa6aed6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ lib
, stdenv
, callPackage
, fetchpatch
, swift
, swiftpm
, swiftpm2nix
, Foundation
, XCTest
, sqlite
, ncurses
, substituteAll
}:
let
  sources = callPackage ../sources.nix { };
  generated = swiftpm2nix.helpers ./generated;

  # On Darwin, we only want ncurses in the linker search path, because headers
  # are part of libsystem. Adding its headers to the search path causes strange
  # mixing and errors.
  # TODO: Find a better way to prevent this conflict.
  ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses;
in
stdenv.mkDerivation {
  pname = "swift-driver";

  inherit (sources) version;
  src = sources.swift-driver;

  nativeBuildInputs = [ swift swiftpm ];
  buildInputs = [
    Foundation
    XCTest
    sqlite
    ncursesInput
  ];

  patches = [
    ./patches/nix-resource-root.patch
    ./patches/disable-catalyst.patch
    ./patches/linux-fix-linking.patch
    # TODO: Replace with branch patch once merged:
    # https://github.com/apple/swift-driver/pull/1197
    (fetchpatch {
      url = "https://github.com/apple/swift-driver/commit/d3ef9cdf4871a58eddec7ff0e28fe611130da3f9.patch";
      hash = "sha256-eVBaKN6uzj48ZnHtwGV0k5ChKjak1tDCyE+wTdyGq2c=";
    })
    # Prevent a warning about SDK directories we don't have.
    (substituteAll {
      src = ./patches/prevent-sdk-dirs-warnings.patch;
      inherit (builtins) storeDir;
    })
  ];

  configurePhase = generated.configure + ''
    swiftpmMakeMutable swift-tools-support-core
    patch -p1 -d .build/checkouts/swift-tools-support-core -i ${./patches/force-unwrap-file-handles.patch}
  '';

  # TODO: Tests depend on indexstore-db being provided by an existing Swift
  # toolchain. (ie. looks for `../lib/libIndexStore.so` relative to swiftc.
  #doCheck = true;

  # TODO: Darwin-specific installation includes more, but not sure why.
  installPhase = ''
    binPath="$(swiftpmBinPath)"
    mkdir -p $out/bin
    for executable in swift-driver swift-help swift-build-sdk-interfaces; do
      cp $binPath/$executable $out/bin/
    done
  '';

  meta = {
    description = "Swift compiler driver";
    homepage = "https://github.com/apple/swift-driver";
    platforms = with lib.platforms; linux ++ darwin;
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ];
  };
}