Skip to content

Commit e5539ed

Browse files
committed
Decouple SpirvSource, add error types for it
1 parent 6c052f3 commit e5539ed

File tree

19 files changed

+731
-493
lines changed

19 files changed

+731
-493
lines changed

Cargo.lock

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
"crates/rustc_codegen_spirv-cache",
4+
"crates/cargo-gpu-test-utils",
45
"crates/cargo-gpu-cache",
56
"crates/cargo-gpu",
67
"crates/xtask",
@@ -24,6 +25,7 @@ license = "MIT OR Apache-2.0"
2425
[workspace.dependencies]
2526
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "3df836eb9d7b01344f52737bf9a310d1fb5a0c26", default-features = false }
2627
anyhow = "1.0.98"
28+
thiserror = "2.0.12"
2729
clap = { version = "4.5.41", features = ["derive"] }
2830
crossterm = "0.29.0"
2931
directories = "6.0.0"

crates/cargo-gpu-cache/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ semver.workspace = true
2323
dunce.workspace = true
2424

2525
[dev-dependencies]
26+
cargo-gpu-test-utils = { path = "../cargo-gpu-test-utils" }
2627
test-log.workspace = true
27-
tempfile.workspace = true
2828
cargo_metadata = { workspace = true, features = ["builder"] }
2929
cargo-util-schemas.workspace = true
3030

crates/cargo-gpu-cache/src/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,16 @@ impl Build {
204204
mod test {
205205
#![cfg(feature = "clap")]
206206

207+
use cargo_gpu_test_utils::{shader_crate_template_path, tests_teardown};
207208
use clap::Parser as _;
208209

209210
use crate::{Cli, Command};
210211

211212
#[test_log::test]
212213
fn builder_from_params() {
213-
crate::test::tests_teardown();
214+
tests_teardown();
214215

215-
let shader_crate_path = crate::test::shader_crate_template_path();
216+
let shader_crate_path = shader_crate_template_path();
216217
let output_dir = shader_crate_path.join("shaders");
217218

218219
let args = [

crates/cargo-gpu-cache/src/config.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ impl Config {
8787

8888
#[cfg(test)]
8989
mod test {
90-
use super::*;
91-
9290
use std::io::Write as _;
9391

92+
use cargo_gpu_test_utils::{overwrite_shader_cargo_toml, shader_crate_test_path};
93+
94+
use super::*;
95+
9496
#[test_log::test]
9597
fn booleans_from_cli() {
96-
let shader_crate_path = crate::test::shader_crate_test_path();
98+
let shader_crate_path = shader_crate_test_path();
9799

98100
let args = Config::clap_command_with_cargo_config(
99101
&shader_crate_path,
@@ -111,8 +113,8 @@ mod test {
111113

112114
#[test_log::test]
113115
fn booleans_from_cargo() {
114-
let shader_crate_path = crate::test::shader_crate_test_path();
115-
let mut file = crate::test::overwrite_shader_cargo_toml(&shader_crate_path);
116+
let shader_crate_path = shader_crate_test_path();
117+
let mut file = overwrite_shader_cargo_toml(&shader_crate_path);
116118
file.write_all(
117119
[
118120
"[package.metadata.rust-gpu.build]",
@@ -131,8 +133,8 @@ mod test {
131133
}
132134

133135
fn update_cargo_output_dir() -> std::path::PathBuf {
134-
let shader_crate_path = crate::test::shader_crate_test_path();
135-
let mut file = crate::test::overwrite_shader_cargo_toml(&shader_crate_path);
136+
let shader_crate_path = shader_crate_test_path();
137+
let mut file = overwrite_shader_cargo_toml(&shader_crate_path);
136138
file.write_all(
137139
[
138140
"[package.metadata.rust-gpu.build]",
@@ -176,8 +178,8 @@ mod test {
176178

177179
#[test_log::test]
178180
fn arrays_from_cargo() {
179-
let shader_crate_path = crate::test::shader_crate_test_path();
180-
let mut file = crate::test::overwrite_shader_cargo_toml(&shader_crate_path);
181+
let shader_crate_path = shader_crate_test_path();
182+
let mut file = overwrite_shader_cargo_toml(&shader_crate_path);
181183
file.write_all(
182184
[
183185
"[package.metadata.rust-gpu.build]",
@@ -200,7 +202,7 @@ mod test {
200202

201203
#[test_log::test]
202204
fn rename_manifest_parse() {
203-
let shader_crate_path = crate::test::shader_crate_test_path();
205+
let shader_crate_path = shader_crate_test_path();
204206

205207
let args = Config::clap_command_with_cargo_config(
206208
&shader_crate_path,

crates/cargo-gpu-cache/src/install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use std::path::{Path, PathBuf};
44

55
use anyhow::Context as _;
6-
use rustc_codegen_spirv_cache::cache_dir;
6+
use rustc_codegen_spirv_cache::{
7+
cache::cache_dir,
8+
metadata::{query_metadata, MetadataExt as _},
9+
spirv_source::{get_channel_from_rustc_codegen_spirv_build_script, SpirvSource},
10+
};
711
use spirv_builder::SpirvBuilder;
812

9-
use crate::spirv_source::SpirvSource;
10-
use crate::spirv_source::{
11-
get_channel_from_rustc_codegen_spirv_build_script, query_metadata, FindPackage as _,
12-
};
1313
use crate::target_specs::update_target_specs_files;
1414

1515
/// Represents a functional backend installation, whether it was cached or just installed.

crates/cargo-gpu-cache/src/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ mod linkage;
5252
mod lockfile;
5353
mod metadata;
5454
mod show;
55-
mod spirv_source;
5655
mod target_specs;
57-
mod test;
5856

5957
pub use install::*;
6058
pub use spirv_builder;
@@ -162,16 +160,3 @@ pub struct Cli {
162160
#[cfg_attr(feature = "clap", clap(subcommand))]
163161
pub command: Command,
164162
}
165-
166-
/// Returns a string suitable to use as a directory.
167-
///
168-
/// Created from the spirv-builder source dep and the rustc channel.
169-
fn to_dirname(text: &str) -> String {
170-
text.replace(
171-
[std::path::MAIN_SEPARATOR, '\\', '/', '.', ':', '@', '='],
172-
"_",
173-
)
174-
.split(['{', '}', ' ', '\n', '"', '\''])
175-
.collect::<Vec<_>>()
176-
.concat()
177-
}

crates/cargo-gpu-cache/src/show.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
use std::{fs, path::Path};
44

55
use anyhow::bail;
6-
use rustc_codegen_spirv_cache::cache_dir;
7-
8-
use crate::{
9-
spirv_source::{query_metadata, SpirvSource},
10-
target_specs::update_target_specs_files,
6+
use rustc_codegen_spirv_cache::{
7+
cache::cache_dir, metadata::query_metadata, spirv_source::SpirvSource,
118
};
129

10+
use crate::target_specs::update_target_specs_files;
11+
1312
/// Show the computed source of the spirv-std dependency.
1413
#[derive(Clone, Debug)]
1514
#[cfg_attr(feature = "clap", derive(clap::Parser))]

0 commit comments

Comments
 (0)