Skip to content

Various small fixes for Graphite #80

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

Merged
merged 4 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
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
84 changes: 82 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = [
resolver = "2"

[workspace.dependencies]
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "86fc48032c4cd4afb74f1d81ae859711d20386a1", default-features = false }
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "e6d017d5504c4441a84edcc27f4eca61de6fc8cf", default-features = false }
anyhow = "1.0.94"
clap = { version = "4.5.37", features = ["derive"] }
crossterm = "0.28.1"
Expand Down
1 change: 1 addition & 0 deletions crates/cargo-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ semver.workspace = true

[dev-dependencies]
test-log.workspace = true
cargo_metadata = { workspace = true, features = ["builder"] }

[lints]
workspace = true
3 changes: 2 additions & 1 deletion crates/cargo-gpu/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ package = "rustc_codegen_spirv"
.current_dir(&install_dir)
.arg(format!("+{toolchain_channel}"))
.args(["build", "--release"])
.env_remove("RUSTC");
.env_remove("RUSTC")
.env_remove("RUSTFLAGS");
if source.is_path() {
build_command.args(["-p", "rustc_codegen_spirv", "--lib"]);
}
Expand Down
59 changes: 55 additions & 4 deletions crates/cargo-gpu/src/spirv_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ impl SpirvSource {
Self::CratesIO(Version::parse(rust_gpu_version)?)
}
} else {
Self::get_rust_gpu_deps_from_shader(shader_crate_path)
.context("get_rust_gpu_deps_from_shader")?
Self::get_rust_gpu_deps_from_shader(shader_crate_path).with_context(|| {
format!(
"get spirv-std dependency from shader crate '{}'",
shader_crate_path.display()
)
})?
};
Ok(source)
}
Expand Down Expand Up @@ -144,8 +148,8 @@ impl SpirvSource {
let parse_git = || {
let link = &source.repr.get(4..)?;
let sharp_index = link.find('#')?;
let question_mark_index = link.find('?')?;
let url = link.get(..question_mark_index)?.to_owned();
let url_end = link.find('?').unwrap_or(sharp_index);
let url = link.get(..url_end)?.to_owned();
let rev = link.get(sharp_index + 1..)?.to_owned();
Some(Self::Git { url, rev })
};
Expand Down Expand Up @@ -244,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
#[cfg(test)]
mod test {
use super::*;
use cargo_metadata::{PackageBuilder, PackageId, Source};

#[test_log::test]
fn parsing_spirv_std_dep_for_shader_template() {
Expand Down Expand Up @@ -277,4 +282,50 @@ mod test {
.unwrap();
assert_eq!("https___github_com_Rust-GPU_rust-gpu+86fc4803", &name);
}

#[test_log::test]
fn parse_git_with_rev() {
let source = parse_git(
"git+https://github.com/Rust-GPU/rust-gpu?rev=86fc48032c4cd4afb74f1d81ae859711d20386a1#86fc4803",
);
assert_eq!(
source,
SpirvSource::Git {
url: "https://github.com/Rust-GPU/rust-gpu".to_owned(),
rev: "86fc4803".to_owned(),
}
)
}

#[test_log::test]
fn parse_git_no_question_mark() {
// taken directly from Graphite
let source = parse_git(
"git+https://github.com/Rust-GPU/rust-gpu.git#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421",
);
assert_eq!(
source,
SpirvSource::Git {
url: "https://github.com/Rust-GPU/rust-gpu.git".to_owned(),
rev: "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421".to_owned(),
}
)
}

fn parse_git(source: &str) -> SpirvSource {
let package = PackageBuilder::new(
"spirv-std",
Version::new(0, 9, 0),
PackageId {
repr: "".to_owned(),
},
"",
)
.source(Some(Source {
repr: source.to_owned(),
}))
.build()
.unwrap();
SpirvSource::parse_spirv_std_source_and_version(&package).unwrap()
}
}
Loading