Skip to content

Commit 4821a5a

Browse files
committed
wgsl: hide naga behind feature
1 parent 6f9d7cc commit 4821a5a

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

crates/rustc_codegen_spirv/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use-compiled-tools = ["spirv-tools/use-compiled-tools"]
2929
# and will likely produce compile errors when built against a different toolchain.
3030
# Enable this feature to be able to experiment with other versions.
3131
skip-toolchain-check = []
32+
naga = ["dep:naga"]
3233

3334
[dependencies]
3435
# HACK(eddyb) these only exist to unify features across dependency trees,
@@ -60,7 +61,7 @@ itertools = "0.10.5"
6061
tracing.workspace = true
6162
tracing-subscriber.workspace = true
6263
tracing-tree = "0.3.0"
63-
naga = { version = "25.0.1", features = ["spv-in", "wgsl-out"] }
64+
naga = { version = "25.0.1", features = ["spv-in", "wgsl-out"], optional = true }
6465

6566
# required for cargo gpu to resolve the needed target specs
6667
rustc_codegen_spirv-target-specs.workspace = true

crates/rustc_codegen_spirv/src/link.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ fn post_link_single_module(
313313
drop(save_modules_timer);
314314
}
315315

316-
if let Some(transpile) = should_transpile(sess) {
317-
transpile(sess, cg_args, &spv_binary, out_filename).ok();
316+
if let Ok(transpile) = should_transpile(sess) {
317+
if let Some(transpile) = transpile {
318+
transpile(sess, cg_args, &spv_binary, out_filename).ok();
319+
}
318320
}
319321
}
320322

crates/rustc_codegen_spirv/src/naga_transpile.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ pub type NagaTranspile = fn(
1111
out_filename: &Path,
1212
) -> Result<(), ErrorGuaranteed>;
1313

14-
pub fn should_transpile(sess: &Session) -> Option<NagaTranspile> {
14+
pub fn should_transpile(sess: &Session) -> Result<Option<NagaTranspile>, ErrorGuaranteed> {
1515
let target = SpirvTargetEnv::parse_triple(sess.opts.target_triple.tuple())
1616
.expect("parsing should fail earlier");
17-
match target {
18-
SpirvTargetEnv::Wgsl => Some(transpile::wgsl_transpile),
19-
_ => None,
20-
}
17+
let result: Result<Option<NagaTranspile>, ()> = match target {
18+
#[cfg(feature = "naga")]
19+
SpirvTargetEnv::Wgsl => Ok(Some(transpile::wgsl_transpile)),
20+
#[cfg(not(feature = "naga"))]
21+
SpirvTargetEnv::Wgsl => Err(()),
22+
_ => Ok(None),
23+
};
24+
result.map_err(|_| {
25+
sess.dcx().err(format!(
26+
"Target {} requires feature \"naga\" on rustc_codegen_spirv",
27+
target.target_triple()
28+
))
29+
})
2130
}
2231

32+
#[cfg(feature = "naga")]
2333
mod transpile {
2434
use crate::codegen_cx::CodegenArgs;
2535
use naga::error::ShaderError;

tests/compiletests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use-compiled-tools = ["rustc_codegen_spirv/use-compiled-tools"]
1515

1616
[dependencies]
1717
compiletest = { version = "0.11.2", package = "compiletest_rs" }
18-
rustc_codegen_spirv = { workspace = true }
18+
rustc_codegen_spirv = { workspace = true, features = ["naga"] }
1919
rustc_codegen_spirv-target-specs = { workspace = true, features = ["dir_path"] }
2020
clap = { version = "4", features = ["derive"] }
2121
itertools = "0.10.5"

0 commit comments

Comments
 (0)