9 # These environment variables must be set when using `cargo-c` and
10 # several other tools which do not deal well with cross
11 # compilation. The symptom of the problem they fix is errors due
12 # to buildPlatform CFLAGS being passed to the
13 # hostPlatform-targeted compiler -- for example, `-m64` being
14 # passed on a build=x86_64/host=aarch64 compilation.
17 ccForBuild = "${pkgsBuildHost.stdenv.cc}/bin/${pkgsBuildHost.stdenv.cc.targetPrefix}cc";
18 cxxForBuild = "${pkgsBuildHost.stdenv.cc}/bin/${pkgsBuildHost.stdenv.cc.targetPrefix}c++";
20 ccForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
21 cxxForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
23 # Unfortunately we must use the dangerous `pkgsTargetTarget` here
24 # because hooks are artificially phase-shifted one slot earlier
25 # (they go in nativeBuildInputs, so the hostPlatform looks like
26 # a targetPlatform to them).
27 ccForTarget = "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}cc";
28 cxxForTarget = "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}c++";
30 rustBuildPlatform = stdenv.buildPlatform.rust.rustcTarget;
31 rustBuildPlatformSpec = stdenv.buildPlatform.rust.rustcTargetSpec;
32 rustHostPlatform = stdenv.hostPlatform.rust.rustcTarget;
33 rustHostPlatformSpec = stdenv.hostPlatform.rust.rustcTargetSpec;
34 rustTargetPlatform = stdenv.targetPlatform.rust.rustcTarget;
35 rustTargetPlatformSpec = stdenv.targetPlatform.rust.rustcTargetSpec;
38 ccForBuild cxxForBuild rustBuildPlatform rustBuildPlatformSpec
39 ccForHost cxxForHost rustHostPlatform rustHostPlatformSpec
40 ccForTarget cxxForTarget rustTargetPlatform rustTargetPlatformSpec;
42 # Prefix this onto a command invocation in order to set the
43 # variables needed by cargo.
47 "CC_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${ccForBuild}" \
48 "CXX_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${cxxForBuild}" \
49 "CARGO_TARGET_${stdenv.buildPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForBuild}" \
50 "CARGO_BUILD_TARGET=${rustBuildPlatform}" \
51 "HOST_CC=${pkgsBuildHost.stdenv.cc}/bin/cc" \
52 "HOST_CXX=${pkgsBuildHost.stdenv.cc}/bin/c++" \
54 "CC_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${ccForHost}" \
55 "CXX_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${cxxForHost}" \
56 "CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForHost}" \
58 # Due to a bug in how splicing and pkgsTargetTarget works, in
59 # situations where pkgsTargetTarget is irrelevant
60 # pkgsTargetTarget.stdenv.cc is often simply wrong. We must omit
61 # the following lines when rustTargetPlatform collides with
63 + lib.optionalString (rustTargetPlatform != rustHostPlatform) ''
64 "CC_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${ccForTarget}" \
65 "CXX_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${cxxForTarget}" \
66 "CARGO_TARGET_${stdenv.targetPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForTarget}" \
69 } // lib.mapAttrs (old: new: platform:
70 lib.warn "`rust.${old} platform` is deprecated. Use `platform.rust.${lib.showAttrPath new}` instead."
71 lib.getAttrFromPath new platform.rust)
73 toTargetArch = [ "platform" "arch" ];
74 toTargetOs = [ "platform" "os" ];
75 toTargetFamily = [ "platform" "target-family" ];
76 toTargetVendor = [ "platform" "vendor" ];
77 toRustTarget = [ "rustcTarget" ];
78 toRustTargetSpec = [ "rustcTargetSpec" ];
79 toRustTargetSpecShort = [ "cargoShortTarget" ];
80 toRustTargetForUseInEnvVars = [ "cargoEnvVarTarget" ];
81 IsNoStdTarget = [ "isNoStdTarget" ];