Skip to content

Commit cb11fc7

Browse files
committed
target_specs: replace include_str! with absolute path constant
1 parent 269515e commit cb11fc7

File tree

6 files changed

+14
-78
lines changed

6 files changed

+14
-78
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv-types/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pub use rspirv::spirv::Capability;
55
mod compile_result;
66
pub use compile_result::*;
77

8-
pub mod target_specs;
9-
pub use target_specs::TARGET_SPECS;
10-
118
// HACK(eddyb) allows downstream crates to access the correct version directly.
129
pub use serde;
1310
pub use serde_json;
11+
12+
/// directory with all the `target-specs` jsons for our codegen backend
13+
pub const TARGET_SPEC_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target-specs");

crates/rustc_codegen_spirv-types/src/target_specs.rs

Lines changed: 0 additions & 63 deletions
This file was deleted.

crates/spirv-builder/src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use std::process::{Command, Stdio};
8989
use thiserror::Error;
9090

9191
pub use rustc_codegen_spirv_types::Capability;
92-
pub use rustc_codegen_spirv_types::TARGET_SPECS;
92+
pub use rustc_codegen_spirv_types::TARGET_SPEC_DIR;
9393
pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult};
9494

9595
#[derive(Debug, Error)]
@@ -974,13 +974,12 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
974974
// target_spec jsons, some later version requires them, some earlier
975975
// version fails with them (notably our 0.9.0 release)
976976
if toolchain_rustc_version >= Version::new(1, 76, 0) {
977-
cargo
978-
.arg("--target")
979-
.arg(builder.path_to_target_spec.clone().unwrap_or_else(|| {
980-
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
981-
.join("target-specs")
982-
.join(format!("{}.json", target))
983-
}));
977+
cargo.arg("--target").arg(
978+
builder
979+
.path_to_target_spec
980+
.clone()
981+
.unwrap_or_else(|| PathBuf::from(format!("{}/{}.json", TARGET_SPEC_DIR, target))),
982+
);
984983
} else {
985984
cargo.arg("--target").arg(target);
986985
}

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ use-compiled-tools = ["rustc_codegen_spirv/use-compiled-tools"]
1616
[dependencies]
1717
compiletest = { version = "0.9.0", package = "compiletest_rs" }
1818
rustc_codegen_spirv.workspace = true
19+
rustc_codegen_spirv-types.workspace = true
1920
clap = { version = "4", features = ["derive"] }
2021
itertools = "0.10.5"

tests/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clap::Parser;
22
use itertools::Itertools as _;
3+
use rustc_codegen_spirv_types::TARGET_SPEC_DIR;
34
use std::{
45
env, io,
56
path::{Path, PathBuf},
@@ -30,10 +31,7 @@ impl Opt {
3031
const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-";
3132

3233
fn target_spec_json(target: &str) -> String {
33-
format!(
34-
"{}/../crates/rustc_codegen_spirv-types/target-specs/{target}.json",
35-
env!("CARGO_MANIFEST_DIR")
36-
)
34+
format!("{TARGET_SPEC_DIR}/{target}.json")
3735
}
3836

3937
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)