Merge pull request #182031 from obsidiansystems/rust-platform-respect-fields

build-support/rust/lib: make arch and os functions respect target JSON
This commit is contained in:
John Ericson 2022-07-19 18:57:21 -04:00 committed by GitHub
commit 22ee997512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;
}