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