Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spirv-builder takes optional path to target spec JSON file #55

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ pub struct SpirvBuilder {
extra_args: Vec<String>,
// Optional location of a known `rustc_codegen_spirv` dylib
rustc_codegen_spirv_location: Option<std::path::PathBuf>,
// Optional location of a known "target-spec" file
path_to_target_spec: Option<PathBuf>,

// `rustc_codegen_spirv::linker` codegen args
pub shader_panic_strategy: ShaderPanicStrategy,
Expand Down Expand Up @@ -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,

Expand All @@ -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<Path>) -> 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 {
Expand Down Expand Up @@ -793,11 +806,13 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {

// 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)),
);
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 {
Expand Down