Skip to content

Commit 75bbe25

Browse files
timon-schellingFirestar99
authored andcommitted
Add exec with rust-gpu env script to flake
1 parent 202a44d commit 75bbe25

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

.nix/flake.nix

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@
3535
};
3636

3737
rustExtensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" ];
38-
3938
rust = pkgs.rust-bin.stable.latest.default.override {
4039
targets = [ "wasm32-unknown-unknown" ];
4140
extensions = rustExtensions;
4241
};
4342

44-
rustNightlyPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
43+
rustGPUToolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
4544
extensions = rustExtensions ++ [ "rustc-dev" "llvm-tools" ];
4645
};
47-
48-
rustPlatformNightly = pkgs.makeRustPlatform {
49-
cargo = rustNightlyPkg;
50-
rustc = rustNightlyPkg;
46+
rustGPUToolchainRustPlatform = pkgs.makeRustPlatform {
47+
cargo = rustGPUToolchainPkg;
48+
rustc = rustGPUToolchainPkg;
5149
};
52-
53-
rustc_codegen_spirv = rustPlatformNightly.buildRustPackage (finalAttrs: {
50+
rustc_codegen_spirv = rustGPUToolchainRustPlatform.buildRustPackage (finalAttrs: {
5451
pname = "rustc_codegen_spirv";
5552
version = "0-unstable-2025-08-04";
5653
src = pkgs.fetchFromGitHub {
@@ -60,33 +57,29 @@
6057
hash = "sha256-AFt3Nc+NqK8DxNUhDBcOUmk3XDVcoToVeFIMYNszdbY=";
6158
};
6259
cargoHash = "sha256-en3BYJWQabH064xeAwYQrvcr6EuWg/QjvsG+Jd6HHCk";
63-
6460
cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-installed-tools" "--no-default-features" ];
65-
6661
doCheck = false;
6762
});
6863

69-
cargoGpuPkg = rustPlatformNightly.buildRustPackage (finalAttrs: {
70-
pname = "cargo-gpu";
71-
version = "0-unstable-2025-07-24";
72-
src = pkgs.fetchFromGitHub {
73-
owner = "Rust-GPU";
74-
repo = "cargo-gpu";
75-
rev = "a2ad3574dd32142ff661994e0d79448a45d18f47";
76-
hash = "sha256-YGu9Cuw+pcN9/rCuCxImouzsQ3ScHF+cW6zgxMm0XGI=";
77-
};
78-
cargoHash = "sha256-tyad9kO90uwAnMQYa09takIBXifrumSx2C4rpSK95aM=";
64+
# Wrapper script for running rust commands with the rust toolchain used by rust-gpu.
65+
# For example `rust-gpu cargo --version` or `rust-gpu rustc --version`.
66+
execWithRustGPUEnvironment = pkgs.writeShellScriptBin "rust-gpu" ''
67+
#!${pkgs.lib.getExe pkgs.bash}
7968
80-
doCheck = false;
81-
});
69+
filtered_args=()
70+
for arg in "$@"; do
71+
case "$arg" in
72+
+nightly|+nightly-*) ;;
73+
*) filtered_args+=("$arg") ;;
74+
esac
75+
done
8276
83-
cargoNightlyPkg = pkgs.writeShellScriptBin "cargo-nightly" ''
84-
#!${pkgs.bash}/bin/bash
77+
export PATH="${pkgs.lib.makeBinPath [ rustGPUToolchainPkg pkgs.spirv-tools ]}:$PATH"
78+
export RUSTC_CODEGEN_SPIRV_PATH="${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so"
8579
86-
exec ${rustNightlyPkg}/bin/cargo $@
80+
exec ${"\${filtered_args[@]}"}
8781
'';
8882

89-
9083
libcef = pkgs.libcef.overrideAttrs (finalAttrs: previousAttrs: {
9184
version = "139.0.17";
9285
gitRevision = "6c347eb";
@@ -99,7 +92,6 @@
9992
strip $out/lib/*
10093
'';
10194
});
102-
10395
libcefPath = pkgs.runCommand "libcef-path" {} ''
10496
mkdir -p $out
10597
@@ -146,9 +138,7 @@
146138
# Linker
147139
pkgs.mold
148140

149-
pkgs.spirv-tools
150-
cargoNightlyPkg
151-
cargoGpuPkg
141+
execWithRustGPUEnvironment
152142
];
153143
# Development tools that don't need to be in LD_LIBRARY_PATH
154144
devTools = with pkgs; [
@@ -171,8 +161,6 @@
171161
CEF_PATH = libcefPath;
172162
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";
173163

174-
RUSTC_CODEGEN_SPIRV="${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
175-
176164
shellHook = ''
177165
alias cargo='mold --run cargo'
178166
'';

0 commit comments

Comments
 (0)