Unverified Commit 0852f8eb authored by Alyssa Ross's avatar Alyssa Ross
Browse files

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.
parent ce191662
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -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;
  };
})
+3 −1
Original line number Diff line number Diff line
@@ -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;
  };

+31 −0
Original line number Diff line number Diff line
@@ -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;
+5 −14
Original line number Diff line number Diff line
@@ -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;
  };
})