rust: Add support for managing target JSON in Nix

This commit is contained in:
John Ericson
2020-10-14 03:37:29 +00:00
parent 6866f26c89
commit c0df12de5d
8 changed files with 71 additions and 13 deletions

View File

@@ -24,7 +24,8 @@
if platform.isDarwin then "macos"
else platform.parsed.kernel.name;
# Target triple. Rust has slightly different naming conventions than we use.
# Returns the name of the rust target, even if it is custom. Adjustments are
# because rust has slightly different naming conventions than we do.
toRustTarget = platform: with platform.parsed; let
cpu_ = platform.rustc.arch or {
"armv7a" = "armv7";
@@ -34,6 +35,13 @@
in platform.rustc.config
or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}";
# Returns the name of the rust target if it is standard, or the json file
# containing the custom target spec.
toRustTargetSpec = platform:
if (platform.rustc.arch or {}) ? custom
then builtins.toFile (platform.rustc.config + ".json") (builtins.toJSON platform.rustc.arch.custom)
else toRustTarget platform;
# This just contains tools for now. But it would conceivably contain
# libraries too, say if we picked some default/recommended versions from
# `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for

View File

@@ -70,9 +70,9 @@ in stdenv.mkDerivation rec {
"--set=build.cargo=${rustPlatform.rust.cargo}/bin/cargo"
"--enable-rpath"
"--enable-vendor"
"--build=${rust.toRustTarget stdenv.buildPlatform}"
"--host=${rust.toRustTarget stdenv.hostPlatform}"
"--target=${rust.toRustTarget stdenv.targetPlatform}"
"--build=${rust.toRustTargetSpec stdenv.buildPlatform}"
"--host=${rust.toRustTargetSpec stdenv.hostPlatform}"
"--target=${rust.toRustTargetSpec stdenv.targetPlatform}"
"${setBuild}.cc=${ccForBuild}"
"${setHost}.cc=${ccForHost}"