rust: allow linker to be different from compiler
This commit is contained in:
parent
7fe20b9162
commit
b8076b893e
2 changed files with 12 additions and 8 deletions
|
@ -66,10 +66,10 @@
|
|||
|
||||
cargoConfig = ''
|
||||
[target."${stdenv.buildPlatform.rust.rustcTarget}"]
|
||||
"linker" = "${rust.envVars.ccForBuild}"
|
||||
"linker" = "${rust.envVars.linkerForBuild}"
|
||||
${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
|
||||
[target."${stdenv.hostPlatform.rust.rustcTarget}"]
|
||||
"linker" = "${rust.envVars.ccForHost}"
|
||||
"linker" = "${rust.envVars.linkerForHost}"
|
||||
''}
|
||||
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]
|
||||
'';
|
||||
|
|
|
@ -14,8 +14,11 @@ rec {
|
|||
envVars = let
|
||||
ccForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
|
||||
cxxForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
|
||||
linkerForBuild = ccForBuild;
|
||||
|
||||
ccForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
||||
cxxForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
|
||||
linkerForHost = ccForHost;
|
||||
|
||||
# Unfortunately we must use the dangerous `targetPackages` here
|
||||
# because hooks are artificially phase-shifted one slot earlier
|
||||
|
@ -23,6 +26,7 @@ rec {
|
|||
# a targetPlatform to them).
|
||||
ccForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc";
|
||||
cxxForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++";
|
||||
linkerForTarget = ccForTarget;
|
||||
|
||||
rustBuildPlatform = stdenv.buildPlatform.rust.rustcTarget;
|
||||
rustBuildPlatformSpec = stdenv.buildPlatform.rust.rustcTargetSpec;
|
||||
|
@ -32,9 +36,9 @@ rec {
|
|||
rustTargetPlatformSpec = stdenv.targetPlatform.rust.rustcTargetSpec;
|
||||
in {
|
||||
inherit
|
||||
ccForBuild cxxForBuild rustBuildPlatform rustBuildPlatformSpec
|
||||
ccForHost cxxForHost rustHostPlatform rustHostPlatformSpec
|
||||
ccForTarget cxxForTarget rustTargetPlatform rustTargetPlatformSpec;
|
||||
ccForBuild cxxForBuild linkerForBuild rustBuildPlatform rustBuildPlatformSpec
|
||||
ccForHost cxxForHost linkerForHost rustHostPlatform rustHostPlatformSpec
|
||||
ccForTarget cxxForTarget linkerForTarget rustTargetPlatform rustTargetPlatformSpec;
|
||||
|
||||
# Prefix this onto a command invocation in order to set the
|
||||
# variables needed by cargo.
|
||||
|
@ -50,15 +54,15 @@ rec {
|
|||
+ lib.optionalString (rustTargetPlatform != rustHostPlatform) ''
|
||||
"CC_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${ccForTarget}" \
|
||||
"CXX_${stdenv.targetPlatform.rust.cargoEnvVarTarget}=${cxxForTarget}" \
|
||||
"CARGO_TARGET_${stdenv.targetPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForTarget}" \
|
||||
"CARGO_TARGET_${stdenv.targetPlatform.rust.cargoEnvVarTarget}_LINKER=${linkerForTarget}" \
|
||||
'' + ''
|
||||
"CC_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${ccForHost}" \
|
||||
"CXX_${stdenv.hostPlatform.rust.cargoEnvVarTarget}=${cxxForHost}" \
|
||||
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForHost}" \
|
||||
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER=${linkerForHost}" \
|
||||
'' + ''
|
||||
"CC_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${ccForBuild}" \
|
||||
"CXX_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${cxxForBuild}" \
|
||||
"CARGO_TARGET_${stdenv.buildPlatform.rust.cargoEnvVarTarget}_LINKER=${ccForBuild}" \
|
||||
"CARGO_TARGET_${stdenv.buildPlatform.rust.cargoEnvVarTarget}_LINKER=${linkerForBuild}" \
|
||||
"CARGO_BUILD_TARGET=${rustBuildPlatform}" \
|
||||
"HOST_CC=${buildPackages.stdenv.cc}/bin/cc" \
|
||||
"HOST_CXX=${buildPackages.stdenv.cc}/bin/c++" \
|
||||
|
|
Loading…
Reference in a new issue