Skip to content

Commit c27f621

Browse files
committed
spirv-builder cmd: add rustc specific args like --crate-type, removes crate type requirement from shader crates
1 parent 2cc756e commit c27f621

File tree

1 file changed

+9
-0
lines changed
  • crates/spirv-builder/src

1 file changed

+9
-0
lines changed

crates/spirv-builder/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ pub struct SpirvBuilder {
406406
/// The cargo command to run, formatted like `cargo {cargo_cmd} ...`. Defaults to `rustc`.
407407
#[cfg_attr(feature = "clap", clap(skip))]
408408
pub cargo_cmd: Option<String>,
409+
/// Whether the cargo command set in `cargo_cmd` behaves like `cargo rustc` and allows passing args such as
410+
/// `--crate-type dylib`. Defaults to true if `cargo_cmd` is `None` or `Some("rustc")`.
411+
#[cfg_attr(feature = "clap", clap(skip))]
412+
pub cargo_cmd_like_rustc: Option<bool>,
409413
/// Whether to print build.rs cargo metadata (e.g. cargo:rustc-env=var=val). Defaults to [`MetadataPrintout::None`].
410414
/// Within build scripts, set it to [`MetadataPrintout::DependencyOnly`] or [`MetadataPrintout::Full`] to ensure the build script is rerun on code changes.
411415
#[cfg_attr(feature = "clap", clap(skip))]
@@ -502,6 +506,7 @@ impl Default for SpirvBuilder {
502506
Self {
503507
path_to_crate: None,
504508
cargo_cmd: None,
509+
cargo_cmd_like_rustc: None,
505510
print_metadata: MetadataPrintout::default(),
506511
release: true,
507512
target: None,
@@ -1006,6 +1011,7 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
10061011
}
10071012

10081013
let cargo_cmd = builder.cargo_cmd.as_ref().map_or("rustc", |s| s.as_str());
1014+
let cargo_cmd_like_rustc = builder.cargo_cmd_like_rustc.unwrap_or(cargo_cmd == "rustc");
10091015
let profile = if builder.release { "release" } else { "dev" };
10101016
cargo.args([
10111017
cargo_cmd,
@@ -1016,6 +1022,9 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
10161022
"--profile",
10171023
profile,
10181024
]);
1025+
if cargo_cmd_like_rustc {
1026+
cargo.args(["--crate-type", "dylib"]);
1027+
}
10191028

10201029
if let Ok(extra_cargoflags) = tracked_env_var_get("RUSTGPU_CARGOFLAGS") {
10211030
cargo.args(extra_cargoflags.split_whitespace());

0 commit comments

Comments
 (0)