build-support/rust/lib: make arch and os functions respect target JSON

This commit is contained in:
John Ericson 2022-01-13 00:12:11 +00:00
parent 838618957b
commit 39811b1da9

View file

@ -3,12 +3,14 @@
rec {
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
toTargetArch = platform:
if platform.isAarch32 then "arm"
/**/ if platform ? rustc.platform then platform.rustc.platform.arch
else if platform.isAarch32 then "arm"
else platform.parsed.cpu.name;
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_os
toTargetOs = platform:
if platform.isDarwin then "macos"
/**/ if platform ? rustc.platform then platform.rustc.platform.os or "none"
else if platform.isDarwin then "macos"
else platform.parsed.kernel.name;
# Returns the name of the rust target, even if it is custom. Adjustments are
@ -31,7 +33,7 @@ rec {
# 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 or {}) ? platform
if platform ? rustc.platform
then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform)
else toRustTarget platform;
}