Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

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

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
dunce.workspace = true

[dev-dependencies]
tempfile.workspace = true
test-log.workspace = true
cargo_metadata = { workspace = true, features = ["builder"] }
cargo-util-schemas = "0.8.2"
Expand Down
4 changes: 2 additions & 2 deletions crates/cargo-gpu/src/spirv_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ mod test {
source,
SpirvSource::Git {
url: "https://github.com/Rust-GPU/rust-gpu".to_owned(),
rev: "86fc48032c4cd4afb74f1d81ae859711d20386a1".to_owned()
rev: "2aa4d4f8a8ba73103501562cfca17b8163e5a887".to_owned()
}
);
}
Expand All @@ -281,7 +281,7 @@ mod test {
.to_str()
.map(std::string::ToString::to_string)
.unwrap();
assert_eq!("https___github_com_Rust-GPU_rust-gpu+86fc4803", &name);
assert_eq!("https___github_com_Rust-GPU_rust-gpu+2aa4d4f8", &name);
}

#[test_log::test]
Expand Down
25 changes: 15 additions & 10 deletions crates/cargo-gpu/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! utilities for tests
#![cfg(test)]

use crate::cache_dir;
use std::io::Write as _;
use std::{cell::RefCell, io::Write as _};

fn copy_dir_all(
src: impl AsRef<std::path::Path>,
Expand All @@ -26,10 +25,18 @@ pub fn shader_crate_template_path() -> std::path::PathBuf {
project_base.join("../shader-crate-template")
}

thread_local! {
static TEMPDIR: RefCell<Option<tempfile::TempDir>> = RefCell::new(Some(
tempfile::TempDir::with_prefix("shader_crate").unwrap(),
));
}

pub fn shader_crate_test_path() -> std::path::PathBuf {
let shader_crate_path = crate::cache_dir().unwrap().join("shader_crate");
copy_dir_all(shader_crate_template_path(), shader_crate_path.clone()).unwrap();
shader_crate_path
TEMPDIR.with_borrow(|tempdir| {
let shader_crate_path = tempdir.as_ref().unwrap().path();
copy_dir_all(shader_crate_template_path(), shader_crate_path).unwrap();
shader_crate_path.to_path_buf()
})
}

pub fn overwrite_shader_cargo_toml(shader_crate_path: &std::path::Path) -> std::fs::File {
Expand All @@ -45,9 +52,7 @@ pub fn overwrite_shader_cargo_toml(shader_crate_path: &std::path::Path) -> std::
}

pub fn tests_teardown() {
let cache_dir = cache_dir().unwrap();
if !cache_dir.exists() {
return;
}
std::fs::remove_dir_all(cache_dir).unwrap();
TEMPDIR.with_borrow_mut(|tempdir| {
tempdir.take().unwrap().close().unwrap();
});
}
11 changes: 5 additions & 6 deletions crates/shader-crate-template/Cargo.lock

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

10 changes: 1 addition & 9 deletions crates/shader-crate-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ crate-type = ["rlib", "cdylib"]
# Dependencies for CPU and GPU code
[dependencies]
# TODO: use a simple crate version once v0.10.0 is released
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "86fc48032c4cd4afb74f1d81ae859711d20386a1" }

# Dependencies for GPU code
[target.'cfg(target_arch = "spirv")'.dependencies]
glam = { version = "0.29", default-features = false, features = ["libm"] }

# Dependencies for CPU code
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
glam = { version = "0.29", features = ["std"] }
spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "2aa4d4f8a8ba73103501562cfca17b8163e5a887" }

[package.metadata.rust-gpu.build]
# Where to output the compiled shader. Defaults to where `cargo gpu` is called from.
Expand Down
2 changes: 1 addition & 1 deletion crates/shader-crate-template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Contains an example vertex shader, fragment shader.
#![no_std]
use glam::{Vec2, Vec4};
use spirv_std::glam::{Vec2, Vec4};
use spirv_std::spirv;

pub const CLIP_SPACE_COORD_QUAD_CCW: [Vec4; 6] = {
Expand Down