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