From 89ded215ebfb582a3e8267b11ab4baec8ffbd50d Mon Sep 17 00:00:00 2001 From: Schell Carl Scivally Date: Tue, 12 Nov 2024 12:44:44 +1300 Subject: [PATCH 1/2] feat: spirv-builder takes optional path to target spec JSON file --- crates/spirv-builder/src/lib.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index fc80e10636..0f13693a89 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -303,6 +303,8 @@ pub struct SpirvBuilder { extra_args: Vec, // Optional location of a known `rustc_codegen_spirv` dylib rustc_codegen_spirv_location: Option, + // Optional location of a known "target-spec" file + path_to_target_spec: Option, // `rustc_codegen_spirv::linker` codegen args pub shader_panic_strategy: ShaderPanicStrategy, @@ -333,6 +335,7 @@ impl SpirvBuilder { extensions: Vec::new(), extra_args: Vec::new(), rustc_codegen_spirv_location: None, + path_to_target_spec: None, shader_panic_strategy: ShaderPanicStrategy::SilentExit, @@ -348,6 +351,16 @@ impl SpirvBuilder { } } + /// Sets the path of the "target specification" file. + /// + /// For more info on "target specification" see + /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html). + #[must_use] + pub fn target_spec(mut self, p: impl AsRef) -> Self { + self.path_to_target_spec = Some(p.as_ref().to_path_buf()); + self + } + /// Whether to print build.rs cargo metadata (e.g. cargo:rustc-env=var=val). Defaults to [`MetadataPrintout::Full`]. #[must_use] pub fn print_metadata(mut self, v: MetadataPrintout) -> Self { @@ -794,9 +807,11 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { // FIXME(eddyb) consider moving `target-specs` into `rustc_codegen_spirv_types`. // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative. cargo.arg("--target").arg( - Path::new(env!("CARGO_MANIFEST_DIR")) - .join("target-specs") - .join(format!("{}.json", builder.target)), + builder.path_to_target_spec.clone().unwrap_or_else(|| { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("target-specs") + .join(format!("{}.json", builder.target)) + }), ); if let Some(default_features) = builder.shader_crate_features.default_features { From 0e83fe8f9bd206f715138217ee3e8f365b70723c Mon Sep 17 00:00:00 2001 From: Schell Carl Scivally Date: Tue, 12 Nov 2024 13:47:14 +1300 Subject: [PATCH 2/2] fmt --- crates/spirv-builder/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 0f13693a89..46483050e5 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -352,8 +352,8 @@ impl SpirvBuilder { } /// Sets the path of the "target specification" file. - /// - /// For more info on "target specification" see + /// + /// For more info on "target specification" see /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html). #[must_use] pub fn target_spec(mut self, p: impl AsRef) -> Self { @@ -806,13 +806,13 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { // FIXME(eddyb) consider moving `target-specs` into `rustc_codegen_spirv_types`. // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative. - cargo.arg("--target").arg( - builder.path_to_target_spec.clone().unwrap_or_else(|| { + cargo + .arg("--target") + .arg(builder.path_to_target_spec.clone().unwrap_or_else(|| { PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("target-specs") .join(format!("{}.json", builder.target)) - }), - ); + })); if let Some(default_features) = builder.shader_crate_features.default_features { if !default_features {