mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-03-08 01:24:09 +01:00
lib.systems: Refactor rust.platform generation
In preparation for a future commit, refactor rust.platform somewhat. No functional changes intended. Most of the diff here is whitespace changes.
This commit is contained in:
parent
493a3b2177
commit
550a1b8eb5
1 changed files with 67 additions and 63 deletions
|
|
@ -417,62 +417,65 @@ let
|
|||
// args
|
||||
// {
|
||||
rust = rust // {
|
||||
# Once args.rustc.platform.target-family is deprecated and
|
||||
# removed, there will no longer be any need to modify any
|
||||
# values from args.rust.platform, so we can drop all the
|
||||
# "args ? rust" etc. checks, and merge args.rust.platform in
|
||||
# /after/.
|
||||
platform = rust.platform or { } // {
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
|
||||
arch =
|
||||
if rust ? platform then
|
||||
rust.platform.arch
|
||||
else if final.isAarch32 then
|
||||
"arm"
|
||||
else if final.isMips64 then
|
||||
"mips64" # never add "el" suffix
|
||||
else if final.isPower64 then
|
||||
"powerpc64" # never add "le" suffix
|
||||
else
|
||||
final.parsed.cpu.name;
|
||||
platform =
|
||||
rust.platform or { }
|
||||
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_os
|
||||
os =
|
||||
if rust ? platform then
|
||||
rust.platform.os or "none"
|
||||
else if final.isDarwin then
|
||||
"macos"
|
||||
else if final.isWasm && !final.isWasi then
|
||||
"unknown" # Needed for {wasm32,wasm64}-unknown-unknown.
|
||||
else
|
||||
final.parsed.kernel.name;
|
||||
# Once args.rustc.platform.target-family is deprecated and
|
||||
# removed, there will no longer be any need to modify any
|
||||
# values from args.rust.platform, so we can drop all the
|
||||
# "args ? rust" etc. checks, and merge args.rust.platform in
|
||||
# /after/.
|
||||
// {
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
|
||||
arch =
|
||||
if rust ? platform then
|
||||
rust.platform.arch
|
||||
else if final.isAarch32 then
|
||||
"arm"
|
||||
else if final.isMips64 then
|
||||
"mips64" # never add "el" suffix
|
||||
else if final.isPower64 then
|
||||
"powerpc64" # never add "le" suffix
|
||||
else
|
||||
final.parsed.cpu.name;
|
||||
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_family
|
||||
target-family =
|
||||
if args ? rust.platform.target-family then
|
||||
args.rust.platform.target-family
|
||||
else if args ? rustc.platform.target-family then
|
||||
(
|
||||
# Since https://github.com/rust-lang/rust/pull/84072
|
||||
# `target-family` is a list instead of single value.
|
||||
let
|
||||
f = args.rustc.platform.target-family;
|
||||
in
|
||||
if isList f then f else [ f ]
|
||||
)
|
||||
else
|
||||
optional final.isUnix "unix" ++ optional final.isWindows "windows" ++ optional final.isWasm "wasm";
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_os
|
||||
os =
|
||||
if rust ? platform then
|
||||
rust.platform.os or "none"
|
||||
else if final.isDarwin then
|
||||
"macos"
|
||||
else if final.isWasm && !final.isWasi then
|
||||
"unknown" # Needed for {wasm32,wasm64}-unknown-unknown.
|
||||
else
|
||||
final.parsed.kernel.name;
|
||||
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor
|
||||
vendor =
|
||||
let
|
||||
inherit (final.parsed) vendor;
|
||||
in
|
||||
rust.platform.vendor or {
|
||||
"w64" = "pc";
|
||||
}
|
||||
.${vendor.name} or vendor.name;
|
||||
};
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_family
|
||||
target-family =
|
||||
if args ? rust.platform.target-family then
|
||||
args.rust.platform.target-family
|
||||
else if args ? rustc.platform.target-family then
|
||||
(
|
||||
# Since https://github.com/rust-lang/rust/pull/84072
|
||||
# `target-family` is a list instead of single value.
|
||||
let
|
||||
f = args.rustc.platform.target-family;
|
||||
in
|
||||
if isList f then f else [ f ]
|
||||
)
|
||||
else
|
||||
optional final.isUnix "unix" ++ optional final.isWindows "windows" ++ optional final.isWasm "wasm";
|
||||
|
||||
# https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor
|
||||
vendor =
|
||||
let
|
||||
inherit (final.parsed) vendor;
|
||||
in
|
||||
rust.platform.vendor or {
|
||||
"w64" = "pc";
|
||||
}
|
||||
.${vendor.name} or vendor.name;
|
||||
};
|
||||
|
||||
# The name of the rust target, even if it is custom. Adjustments are
|
||||
# because rust has slightly different naming conventions than we do.
|
||||
|
|
@ -497,18 +500,19 @@ let
|
|||
"gnu"
|
||||
else
|
||||
abi.name;
|
||||
|
||||
inferred =
|
||||
# Rust uses `wasm32-wasip?` rather than `wasm32-unknown-wasi`.
|
||||
# We cannot know which subversion does the user want, and
|
||||
# currently use WASI 0.1 as default for compatibility. Custom
|
||||
# users can set `rust.rustcTarget` to override it.
|
||||
if final.isWasi then
|
||||
"${cpu_}-wasip1"
|
||||
else
|
||||
"${cpu_}-${vendor_}-${kernel.name}${optionalString (abi.name != "unknown") "-${abi_}"}";
|
||||
in
|
||||
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
|
||||
args.rust.rustcTarget or args.rustc.config or (
|
||||
# Rust uses `wasm32-wasip?` rather than `wasm32-unknown-wasi`.
|
||||
# We cannot know which subversion does the user want, and
|
||||
# currently use WASI 0.1 as default for compatibility. Custom
|
||||
# users can set `rust.rustcTarget` to override it.
|
||||
if final.isWasi then
|
||||
"${cpu_}-wasip1"
|
||||
else
|
||||
"${cpu_}-${vendor_}-${kernel.name}${optionalString (abi.name != "unknown") "-${abi_}"}"
|
||||
);
|
||||
args.rust.rustcTarget or args.rustc.config or inferred;
|
||||
|
||||
# The name of the rust target if it is standard, or the json file
|
||||
# containing the custom target spec.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue