Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at master 69 lines 2.3 kB view raw
1{ 2 lib, 3 runCommand, 4 rustc-unwrapped, 5 sysroot ? null, 6}: 7 8runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" 9 { 10 preferLocalBuild = true; 11 strictDeps = true; 12 inherit (rustc-unwrapped) outputs; 13 14 env = { 15 sysroot = lib.optionalString (sysroot != null) "--sysroot ${sysroot}"; 16 17 # Upstream rustc still assumes that musl = static[1]. The fix for 18 # this is to disable crt-static by default for non-static musl 19 # targets. 20 # 21 # Even though Cargo will build build.rs files for the build platform, 22 # cross-compiling _from_ musl appears to work fine, so we only need 23 # to do this when rustc's target platform is dynamically linked musl. 24 # 25 # [1]: https://github.com/rust-lang/compiler-team/issues/422 26 # 27 # WARNING: using defaultArgs is dangerous, as it will apply to all 28 # targets used by this compiler (host and target). This means 29 # that it can't be used to set arguments that should only be 30 # applied to the target. It's fine to do this for -crt-static, 31 # because rustc does not support +crt-static host platforms 32 # anyway. 33 defaultArgs = lib.optionalString ( 34 with rustc-unwrapped.stdenv.targetPlatform; isMusl && !isStatic 35 ) "-C target-feature=-crt-static"; 36 }; 37 38 passthru = { 39 inherit (rustc-unwrapped) 40 pname 41 version 42 src 43 llvm 44 llvmPackages 45 targetPlatforms 46 targetPlatformsWithHostTools 47 badTargetPlatforms 48 ; 49 unwrapped = rustc-unwrapped; 50 }; 51 52 meta = rustc-unwrapped.meta // { 53 description = "${rustc-unwrapped.meta.description} (wrapper script)"; 54 priority = 10; 55 }; 56 } 57 '' 58 mkdir -p $out/bin 59 ln -s ${rustc-unwrapped}/bin/* $out/bin 60 rm $out/bin/{rustc,rustdoc} 61 prog=${rustc-unwrapped}/bin/rustc extraFlagsVar=NIX_RUSTFLAGS \ 62 substituteAll ${./rustc-wrapper.sh} $out/bin/rustc 63 prog=${rustc-unwrapped}/bin/rustdoc extraFlagsVar=NIX_RUSTDOCFLAGS \ 64 substituteAll ${./rustc-wrapper.sh} $out/bin/rustdoc 65 chmod +x $out/bin/{rustc,rustdoc} 66 ${lib.concatMapStrings (output: "ln -s ${rustc-unwrapped.${output}} \$${output}\n") ( 67 lib.remove "out" rustc-unwrapped.outputs 68 )} 69 ''