Skip to content

Commit 101ae6d

Browse files
Add nix configuration for the rust-gpu toolchain (#3027)
* nix: Try providing cargo-rust-gpu to nix devs, naga branch * nix: Try providing cargo-rust-gpu to nix devs 2 * nix: Add exec with rust-gpu env script to flake * nix: override Path for rust gpu * nix: rust-gpu with `use-compiled-tools` to fix differences * nix: remove spirv-tools --------- Co-authored-by: firestar99 <[email protected]>
1 parent 0a15315 commit 101ae6d

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

.nix/flake.nix

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,47 @@
3434
inherit system overlays;
3535
};
3636

37-
rustc-wasm = pkgs.rust-bin.stable.latest.default.override {
37+
rustExtensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" ];
38+
rust = pkgs.rust-bin.stable.latest.default.override {
3839
targets = [ "wasm32-unknown-unknown" ];
39-
extensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" ];
40+
extensions = rustExtensions;
4041
};
4142

43+
rustGPUToolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
44+
extensions = rustExtensions ++ [ "rustc-dev" "llvm-tools" ];
45+
};
46+
rustGPUToolchainRustPlatform = pkgs.makeRustPlatform {
47+
cargo = rustGPUToolchainPkg;
48+
rustc = rustGPUToolchainPkg;
49+
};
50+
rustc_codegen_spirv = rustGPUToolchainRustPlatform.buildRustPackage (finalAttrs: {
51+
pname = "rustc_codegen_spirv";
52+
version = "0-unstable-2025-08-04";
53+
src = pkgs.fetchFromGitHub {
54+
owner = "Rust-GPU";
55+
repo = "rust-gpu";
56+
rev = "c12f216121820580731440ee79ebc7403d6ea04f";
57+
hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno=";
58+
};
59+
cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4=";
60+
cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-compiled-tools" "--no-default-features" ];
61+
doCheck = false;
62+
});
63+
rustGpuCargo = pkgs.writeShellScriptBin "cargo" ''
64+
#!${pkgs.lib.getExe pkgs.bash}
65+
66+
filtered_args=()
67+
for arg in "$@"; do
68+
case "$arg" in
69+
+nightly|+nightly-*) ;;
70+
*) filtered_args+=("$arg") ;;
71+
esac
72+
done
73+
74+
exec ${rustGPUToolchainPkg}/bin/cargo ${"\${filtered_args[@]}"}
75+
'';
76+
rustGpuPathOverride = "${rustGpuCargo}/bin:${rustGPUToolchainPkg}/bin";
77+
4278
libcef = pkgs.libcef.overrideAttrs (finalAttrs: previousAttrs: {
4379
version = "139.0.17";
4480
gitRevision = "6c347eb";
@@ -51,7 +87,6 @@
5187
strip $out/lib/*
5288
'';
5389
});
54-
5590
libcefPath = pkgs.runCommand "libcef-path" {} ''
5691
mkdir -p $out
5792
@@ -85,7 +120,7 @@
85120

86121
# Development tools that don't need to be in LD_LIBRARY_PATH
87122
buildTools = [
88-
rustc-wasm
123+
rust
89124
pkgs.nodejs
90125
pkgs.nodePackages.npm
91126
pkgs.binaryen
@@ -119,6 +154,9 @@
119154
CEF_PATH = libcefPath;
120155
XDG_DATA_DIRS="${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
121156

157+
RUST_GPU_PATH_OVERRIDE = rustGpuPathOverride;
158+
RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
159+
122160
shellHook = ''
123161
alias cargo='mold --run cargo'
124162
'';

0 commit comments

Comments
 (0)