at master 3.1 kB view raw
1{ 2 lib, 3 stdenv, 4 swift, 5 useSwiftDriver ? true, 6 swift-driver, 7 clang, 8}: 9 10stdenv.mkDerivation ( 11 swift._wrapperParams 12 // { 13 pname = "swift-wrapper"; 14 inherit (swift) version meta; 15 16 outputs = [ 17 "out" 18 "man" 19 ]; 20 21 # Wrapper and setup hook variables. 22 inherit swift; 23 inherit (swift) 24 swiftOs 25 swiftArch 26 swiftModuleSubdir 27 swiftLibSubdir 28 swiftStaticModuleSubdir 29 swiftStaticLibSubdir 30 ; 31 swiftDriver = lib.optionalString useSwiftDriver "${swift-driver}/bin/swift-driver"; 32 cc_wrapper = clang.override (prev: { 33 extraBuildCommands = 34 prev.extraBuildCommands 35 # We need to use the resource directory corresponding to Swift’s 36 # version of Clang instead of passing along the one from the 37 # `cc-wrapper` flags. 38 + '' 39 rm -r $out/resource-root 40 substituteInPlace $out/nix-support/cc-cflags \ 41 --replace-fail \ 42 "-resource-dir=$out/resource-root" \ 43 "-resource-dir=${lib.getLib swift}/lib/swift/clang" 44 '' 45 # We need the libc++ headers corresponding to the LLVM version of 46 # Swift’s Clang. 47 + lib.optionalString (clang.libcxx != null) '' 48 include -isystem "${lib.getDev swift}/include/c++/v1" > $out/nix-support/libcxx-cxxflags 49 ''; 50 }); 51 52 env.darwinMinVersion = lib.optionalString stdenv.targetPlatform.isDarwin ( 53 stdenv.targetPlatform.darwinMinVersion 54 ); 55 56 passAsFile = [ "buildCommand" ]; 57 buildCommand = '' 58 mkdir -p $out/bin $out/nix-support 59 60 # Symlink all Swift binaries first. 61 # NOTE: This specifically omits clang binaries. We want to hide these for 62 # private use by Swift only. 63 ln -s -t $out/bin/ $swift/bin/swift* 64 65 # Replace specific binaries with wrappers. 66 for executable in swift swiftc swift-frontend; do 67 export prog=$swift/bin/$executable 68 rm $out/bin/$executable 69 substituteAll '${./wrapper.sh}' $out/bin/$executable 70 chmod a+x $out/bin/$executable 71 done 72 73 ${lib.optionalString useSwiftDriver '' 74 # Symlink swift-driver executables. 75 ln -s -t $out/bin/ ${swift-driver}/bin/* 76 ''} 77 78 ln -s ${swift.man} $man 79 80 # This link is here because various tools (swiftpm) check for stdlib 81 # relative to the swift compiler. It's fine if this is for build-time 82 # stuff, but we should patch all cases were it would end up in an output. 83 ln -s ${swift.lib}/lib $out/lib 84 85 substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook 86 87 # Propagate any propagated inputs from the unwrapped Swift compiler, if any. 88 if [ -e "$swift/nix-support" ]; then 89 for input in "$swift/nix-support/"*propagated*; do 90 cp "$input" "$out/nix-support/$(basename "$input")" 91 done 92 fi 93 ''; 94 95 passthru = { 96 inherit swift; 97 inherit (swift) 98 swiftOs 99 swiftArch 100 swiftModuleSubdir 101 swiftLibSubdir 102 tests 103 ; 104 }; 105 } 106)