From 0852f8eb8481cfa310a131017a0e73f2333c8bba Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 15 Aug 2024 11:05:15 +0200 Subject: [PATCH] rustc: expose platform lists Previously, it wasn't possible to access the list of platforms we can build Rust programs for outside of buildRustPackage. This was a problem for packages that have optional Rust components, like gstreamer or Meson, as there was no way to only build the Rust parts for supported platforms. Now it's possible to get that information from rustc's passthru. --- .../rust/build-rust-package/default.nix | 17 ++-------- .../rust/rustc-wrapper/default.nix | 4 ++- pkgs/development/compilers/rust/binary.nix | 31 +++++++++++++++++++ pkgs/development/compilers/rust/rustc.nix | 19 +++--------- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 40b7a6181232..d2f90be8240c 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -151,23 +151,10 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg strictDeps = true; meta = meta // { - badPlatforms = meta.badPlatforms or [] ++ [ - # Rust is currently unable to target the n32 ABI - lib.systems.inspect.patterns.isMips64n32 - ]; - } // lib.optionalAttrs (rustc.meta ? platforms) { + badPlatforms = meta.badPlatforms or [] ++ rustc.badTargetPlatforms; # default to Rust's platforms platforms = lib.intersectLists meta.platforms or lib.platforms.all - (rustc.meta.platforms ++ [ - # Platforms without host tools from - # https://doc.rust-lang.org/nightly/rustc/platform-support.html - "armv7a-darwin" - "armv5tel-linux" "armv7a-linux" "m68k-linux" "mips-linux" - "mips64-linux" "mipsel-linux" "mips64el-linux" "riscv32-linux" - "armv6l-netbsd" "mipsel-netbsd" "riscv64-netbsd" - "x86_64-redox" - "wasm32-wasi" - ]); + rustc.targetPlatforms; }; }) diff --git a/pkgs/build-support/rust/rustc-wrapper/default.nix b/pkgs/build-support/rust/rustc-wrapper/default.nix index 0defa6355029..0b16740ae5bb 100644 --- a/pkgs/build-support/rust/rustc-wrapper/default.nix +++ b/pkgs/build-support/rust/rustc-wrapper/default.nix @@ -30,7 +30,9 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" { }; passthru = { - inherit (rustc-unwrapped) pname version src llvm llvmPackages; + inherit (rustc-unwrapped) + pname version src llvm llvmPackages + tier1TargetPlatforms targetPlatforms badTargetPlatforms; unwrapped = rustc-unwrapped; }; diff --git a/pkgs/development/compilers/rust/binary.nix b/pkgs/development/compilers/rust/binary.nix index 10e944515df7..f972a932f308 100644 --- a/pkgs/development/compilers/rust/binary.nix +++ b/pkgs/development/compilers/rust/binary.nix @@ -61,6 +61,37 @@ rec { dontStrip = true; setupHooks = ./setup-hook.sh; + + passthru = rec { + tier1TargetPlatforms = [ + # Platforms with host tools from + # https://doc.rust-lang.org/nightly/rustc/platform-support.html + "x86_64-darwin" "i686-darwin" "aarch64-darwin" + "i686-freebsd" "x86_64-freebsd" + "x86_64-solaris" + "aarch64-linux" "armv6l-linux" "armv7l-linux" "i686-linux" + "loongarch64-linux" "powerpc64-linux" "powerpc64le-linux" + "riscv64-linux" "s390x-linux" "x86_64-linux" + "aarch64-netbsd" "armv7l-netbsd" "i686-netbsd" "powerpc-netbsd" + "x86_64-netbsd" + "i686-openbsd" "x86_64-openbsd" + "i686-windows" "x86_64-windows" + ]; + targetPlatforms = tier1TargetPlatforms ++ [ + # Platforms without host tools from + # https://doc.rust-lang.org/nightly/rustc/platform-support.html + "armv7a-darwin" + "armv5tel-linux" "armv7a-linux" "m68k-linux" "mips-linux" + "mips64-linux" "mipsel-linux" "mips64el-linux" "riscv32-linux" + "armv6l-netbsd" "mipsel-netbsd" "riscv64-netbsd" + "x86_64-redox" + "wasm32-wasi" + ]; + badTargetPlatforms = [ + # Rust is currently unable to target the n32 ABI + lib.systems.inspect.patterns.isMips64n32 + ]; + }; }; rustc = wrapRustc rustc-unwrapped; diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index 509f255fda78..9fcc2ca923fb 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -303,6 +303,7 @@ in stdenv.mkDerivation (finalAttrs: { passthru = { llvm = llvmShared; inherit llvmPackages; + inherit (rustc) tier1TargetPlatforms targetPlatforms badTargetPlatforms; tests = { inherit fd ripgrep wezterm; } // lib.optionalAttrs stdenv.hostPlatform.isLinux { inherit firefox thunderbird; }; @@ -313,19 +314,9 @@ in stdenv.mkDerivation (finalAttrs: { description = "Safe, concurrent, practical language"; maintainers = with maintainers; [ havvy ] ++ teams.rust.members; license = [ licenses.mit licenses.asl20 ]; - platforms = [ - # Platforms with host tools from - # https://doc.rust-lang.org/nightly/rustc/platform-support.html - "x86_64-darwin" "i686-darwin" "aarch64-darwin" - "i686-freebsd" "x86_64-freebsd" - "x86_64-solaris" - "aarch64-linux" "armv6l-linux" "armv7l-linux" "i686-linux" - "loongarch64-linux" "powerpc64-linux" "powerpc64le-linux" - "riscv64-linux" "s390x-linux" "x86_64-linux" - "aarch64-netbsd" "armv7l-netbsd" "i686-netbsd" "powerpc-netbsd" - "x86_64-netbsd" - "i686-openbsd" "x86_64-openbsd" - "i686-windows" "x86_64-windows" - ]; + platforms = rustc.tier1TargetPlatforms; + # If rustc can't target a platform, we also can't build rustc for + # that platform. + badPlatforms = rustc.badTargetPlatforms; }; })