From 60ac986e4973ad43734fff355496de5dc3a8d508 Mon Sep 17 00:00:00 2001 From: dramforever Date: Wed, 25 Feb 2026 11:09:26 +0800 Subject: [PATCH] lib.systems: rust: Make rustcTargetSpec the primary entrypoint Make rustcTargetSpec the primary entrypoint for setting a custom target, and wire up all the other stuff so they are hopefully as working and as broken as before. In particular, to specify a custom target, the user now just specifies rust.rustcTargetSpec. rust.platform and rust.cargoShortTarget are populated from rust.rustcTargetSpec now. In addition, rust.rustcTarget defaults to rust.cargoShortTarget. (rust.rustcTarget and rust.cargoShortTarget really should always be the same, but I think we can deal with that later). This allows the user to more easily control the basename of rust.rustcTargetSpec by passing e.g. "${./rust}/mips64el_mips3-unknown-linux-gnuabi64.json", which allows cc-rs and in turn std to work. --- lib/systems/default.nix | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 972f78c17375..b4f6c13feafa 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -418,7 +418,12 @@ let // { rust = rust // { platform = - rust.platform or { } + rust.platform or ( + if lib.hasSuffix ".json" (rust.rustcTargetSpec or "") then + lib.importJSON rust.rustcTargetSpec + else + { } + ) # Once args.rustc.platform.target-family is deprecated and # removed, there will no longer be any need to modify any @@ -477,9 +482,10 @@ let .${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. - rustcTarget = + # The name of the rust target if it is standard, or the json file + # containing the custom target spec. Adjustments are because rust has + # slightly different naming conventions than we do. + rustcTargetSpec = let inherit (final.parsed) cpu kernel abi; cpu_ = @@ -502,28 +508,28 @@ let 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 + # 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.rustcTargetSpec` to override it. "${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 inferred; - - # The name of the rust target if it is standard, or the json file - # containing the custom target spec. - rustcTargetSpec = - rust.rustcTargetSpec or ( + args.rust.rustcTargetSpec or args.rustc.config or ( if rust ? platform then - builtins.toFile (final.rust.rustcTarget + ".json") (toJSON rust.platform) + # TODO: This breaks cc-rs and thus std support, so maybe remove support? + builtins.toFile (rust.rustcTarget or inferred + ".json") (toJSON rust.platform) else - final.rust.rustcTarget + args.rust.rustcTarget or inferred ); + # Do not use rustcTarget. Use rustcTargetSpec or cargoShortTarget. + # TODO: Remove all in-tree usages, and deprecate + rustcTarget = rust.rustcTarget or final.rust.cargoShortTarget; + # The name of the rust target if it is standard, or the # basename of the file containing the custom target spec, # without the .json extension.