1{
2 lib,
3 stdenv,
4 swift,
5 useSwiftDriver ? true,
6 swift-driver,
7}:
8
9stdenv.mkDerivation (
10 swift._wrapperParams
11 // {
12 pname = "swift-wrapper";
13 inherit (swift) version meta;
14
15 outputs = [
16 "out"
17 "man"
18 ];
19
20 # Wrapper and setup hook variables.
21 inherit swift;
22 inherit (swift)
23 swiftOs
24 swiftArch
25 swiftModuleSubdir
26 swiftLibSubdir
27 swiftStaticModuleSubdir
28 swiftStaticLibSubdir
29 ;
30 swiftDriver = lib.optionalString useSwiftDriver "${swift-driver}/bin/swift-driver";
31
32 env.darwinMinVersion = lib.optionalString stdenv.targetPlatform.isDarwin (
33 stdenv.targetPlatform.darwinMinVersion
34 );
35
36 passAsFile = [ "buildCommand" ];
37 buildCommand = ''
38 mkdir -p $out/bin $out/nix-support
39
40 # Symlink all Swift binaries first.
41 # NOTE: This specifically omits clang binaries. We want to hide these for
42 # private use by Swift only.
43 ln -s -t $out/bin/ $swift/bin/swift*
44
45 # Replace specific binaries with wrappers.
46 for executable in swift swiftc swift-frontend; do
47 export prog=$swift/bin/$executable
48 rm $out/bin/$executable
49 substituteAll '${./wrapper.sh}' $out/bin/$executable
50 chmod a+x $out/bin/$executable
51 done
52
53 ${lib.optionalString useSwiftDriver ''
54 # Symlink swift-driver executables.
55 ln -s -t $out/bin/ ${swift-driver}/bin/*
56 ''}
57
58 ln -s ${swift.man} $man
59
60 # This link is here because various tools (swiftpm) check for stdlib
61 # relative to the swift compiler. It's fine if this is for build-time
62 # stuff, but we should patch all cases were it would end up in an output.
63 ln -s ${swift.lib}/lib $out/lib
64
65 substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook
66
67 # Propagate any propagated inputs from the unwrapped Swift compiler, if any.
68 if [ -e "$swift/nix-support" ]; then
69 for input in "$swift/nix-support/"*propagated*; do
70 cp "$input" "$out/nix-support/$(basename "$input")"
71 done
72 fi
73 '';
74
75 passthru = {
76 inherit swift;
77 inherit (swift)
78 swiftOs
79 swiftArch
80 swiftModuleSubdir
81 swiftLibSubdir
82 ;
83 };
84 }
85)