Skip to content

Commit e574460

Browse files
authored
Various small fixes for Graphite (#80)
* report path of shader crate when it can't be found * fix git parsing with no `?` in url * update spirv-builder * install: remove RUSTFLAGS env var
1 parent d097aa1 commit e574460

File tree

5 files changed

+141
-8
lines changed

5 files changed

+141
-8
lines changed

Cargo.lock

Lines changed: 82 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude = [
1313
resolver = "2"
1414

1515
[workspace.dependencies]
16-
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "86fc48032c4cd4afb74f1d81ae859711d20386a1", default-features = false }
16+
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "e6d017d5504c4441a84edcc27f4eca61de6fc8cf", default-features = false }
1717
anyhow = "1.0.94"
1818
clap = { version = "4.5.37", features = ["derive"] }
1919
crossterm = "0.28.1"

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ semver.workspace = true
2727

2828
[dev-dependencies]
2929
test-log.workspace = true
30+
cargo_metadata = { workspace = true, features = ["builder"] }
3031

3132
[lints]
3233
workspace = true

crates/cargo-gpu/src/install.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ package = "rustc_codegen_spirv"
284284
.current_dir(&install_dir)
285285
.arg(format!("+{toolchain_channel}"))
286286
.args(["build", "--release"])
287-
.env_remove("RUSTC");
287+
.env_remove("RUSTC")
288+
.env_remove("RUSTFLAGS");
288289
if source.is_path() {
289290
build_command.args(["-p", "rustc_codegen_spirv", "--lib"]);
290291
}

crates/cargo-gpu/src/spirv_source.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ impl SpirvSource {
8888
Self::CratesIO(Version::parse(rust_gpu_version)?)
8989
}
9090
} else {
91-
Self::get_rust_gpu_deps_from_shader(shader_crate_path)
92-
.context("get_rust_gpu_deps_from_shader")?
91+
Self::get_rust_gpu_deps_from_shader(shader_crate_path).with_context(|| {
92+
format!(
93+
"get spirv-std dependency from shader crate '{}'",
94+
shader_crate_path.display()
95+
)
96+
})?
9397
};
9498
Ok(source)
9599
}
@@ -144,8 +148,8 @@ impl SpirvSource {
144148
let parse_git = || {
145149
let link = &source.repr.get(4..)?;
146150
let sharp_index = link.find('#')?;
147-
let question_mark_index = link.find('?')?;
148-
let url = link.get(..question_mark_index)?.to_owned();
151+
let url_end = link.find('?').unwrap_or(sharp_index);
152+
let url = link.get(..url_end)?.to_owned();
149153
let rev = link.get(sharp_index + 1..)?.to_owned();
150154
Some(Self::Git { url, rev })
151155
};
@@ -244,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
244248
#[cfg(test)]
245249
mod test {
246250
use super::*;
251+
use cargo_metadata::{PackageBuilder, PackageId, Source};
247252

248253
#[test_log::test]
249254
fn parsing_spirv_std_dep_for_shader_template() {
@@ -277,4 +282,50 @@ mod test {
277282
.unwrap();
278283
assert_eq!("https___github_com_Rust-GPU_rust-gpu+86fc4803", &name);
279284
}
285+
286+
#[test_log::test]
287+
fn parse_git_with_rev() {
288+
let source = parse_git(
289+
"git+https://github.com/Rust-GPU/rust-gpu?rev=86fc48032c4cd4afb74f1d81ae859711d20386a1#86fc4803",
290+
);
291+
assert_eq!(
292+
source,
293+
SpirvSource::Git {
294+
url: "https://github.com/Rust-GPU/rust-gpu".to_owned(),
295+
rev: "86fc4803".to_owned(),
296+
}
297+
)
298+
}
299+
300+
#[test_log::test]
301+
fn parse_git_no_question_mark() {
302+
// taken directly from Graphite
303+
let source = parse_git(
304+
"git+https://github.com/Rust-GPU/rust-gpu.git#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421",
305+
);
306+
assert_eq!(
307+
source,
308+
SpirvSource::Git {
309+
url: "https://github.com/Rust-GPU/rust-gpu.git".to_owned(),
310+
rev: "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421".to_owned(),
311+
}
312+
)
313+
}
314+
315+
fn parse_git(source: &str) -> SpirvSource {
316+
let package = PackageBuilder::new(
317+
"spirv-std",
318+
Version::new(0, 9, 0),
319+
PackageId {
320+
repr: "".to_owned(),
321+
},
322+
"",
323+
)
324+
.source(Some(Source {
325+
repr: source.to_owned(),
326+
}))
327+
.build()
328+
.unwrap();
329+
SpirvSource::parse_spirv_std_source_and_version(&package).unwrap()
330+
}
280331
}

0 commit comments

Comments
 (0)