From d661fb5787810fffee8e1688848a5981e9c18dca Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 12:14:56 +0100 Subject: [PATCH 1/7] ci: split main test between `test-os` and `test-rust-gpu-versions` jobs --- .github/workflows/push.yaml | 55 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 82929b56..8e028752 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -5,13 +5,14 @@ on: branches: - main pull_request: + workflow_dispatch: env: # For setup-rust, see https://github.com/moonrepo/setup-rust/issues/22 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: - install-and-build-shaders: + test-os: strategy: fail-fast: false matrix: @@ -19,49 +20,59 @@ jobs: - ubuntu-latest - macos-latest - windows-latest - rust-gpu-version: [latest] - include: + runs-on: ${{ matrix.os }} + env: + RUST_LOG: debug + steps: + - uses: actions/checkout@v4 + - uses: cargo-bins/cargo-binstall@main + - run: cargo binstall cargo-nextest + - run: cargo fetch --locked + - name: shader-crate-template cargo fetch --locked + run: | + cd ./crates/shader-crate-template + cargo fetch --locked + - run: cargo nextest run + - name: Run a full build + run: cargo xtask test-build + + test-rust-gpu-releases: + strategy: + fail-fast: false + matrix: + rust-gpu-version: # As well as testing on each OS, we also want to test to make sure we're still supporting # older versions of `rust-gpu`. However, we can assume that these tests are already okay # across platforms, so we only need to test on Linux, the chepeast in terms of minutes. # # `0.7.0` currently fails building `spirv-builder-cli` with: # """ - # package `is_terminal_polyfill v1.70.1` cannot be built because it requires rustc + # package `is_terminal_polyfill v1.70.1` cannot be built because it requires rustc # 1.70.0 or newer, while the currently active rustc version is 1.69.0-nightly # """ # It's probably easily fixable. But also `0.7.0` was released in April 2023, so there's # unlikely many users of it? - - os: ubuntu-latest - rust-gpu-version: 0.8.0 - - os: ubuntu-latest - rust-gpu-version: 0.9.0 - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash + - 0.8.0 + - 0.9.0 + runs-on: ubuntu-latest env: RUST_LOG: debug steps: - uses: actions/checkout@v4 - - name: Fetch root dependencies - run: cargo fetch --locked - - name: Fetch shader-crate-template dependencies - run: | - cd ./crates/shader-crate-template - cargo fetch --locked - - run: cargo test - name: Run a full build run: cargo xtask test-build --rust-gpu-version ${{ matrix.rust-gpu-version }} - + lints: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: cargo-bins/cargo-binstall@main - - name: Install cargo-shear - run: cargo binstall cargo-shear + - run: cargo binstall cargo-shear - run: cargo fetch --locked - run: cargo clippy -- --deny warnings - run: cargo fmt --check - run: cargo shear + +defaults: + run: + shell: bash From cc8f32214368ea1c4a3ffa26e25054233b5e999c Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 12:32:15 +0100 Subject: [PATCH 2/7] ci: add `test_success` job --- .github/workflows/push.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 8e028752..3f0bd481 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -62,7 +62,7 @@ jobs: - name: Run a full build run: cargo xtask test-build --rust-gpu-version ${{ matrix.rust-gpu-version }} - lints: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -73,6 +73,21 @@ jobs: - run: cargo fmt --check - run: cargo shear + # This allows us to have a single job we can branch protect on, rather than needing + # to update the branch protection rules when the test matrix changes + test_success: + runs-on: ubuntu-24.04 + needs: [test-os, test-rust-gpu-releases, lint] + # Hack for buggy GitHub Actions behavior with skipped checks: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks + if: ${{ always() }} + steps: + # Another hack is to actually check the status of the dependencies or else it'll fall through + - run: | + echo "Checking statuses..." + [[ "${{ needs.test-os.result }}" == "success" ]] || exit 1 + [[ "${{ needs.test-rust-gpu-releases.result }}" == "success" ]] || exit 1 + [[ "${{ needs.lint.result }}" == "success" ]] || exit 1 + defaults: run: shell: bash From 0355069566e700c7bce4ed973c0572abc65aff49 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 7 Nov 2025 13:32:14 +0100 Subject: [PATCH 3/7] xtask: support git revs for `rust_gpu_version` arg --- crates/xtask/src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 8eec0beb..90abe02e 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -132,7 +132,19 @@ impl ShaderCrateTemplateCargoTomlWriter { fn replace_spirv_std_version(&mut self, version: String) -> anyhow::Result<()> { let dependencies = self.get_cargo_dependencies_table(); let spirv_std = dependencies.get_mut("spirv-std").unwrap(); - *spirv_std = toml::Value::String(version); + if version.contains('.') { + // semver + *spirv_std = toml::Value::String(version); + } else { + // git rev + *spirv_std = toml::Value::Table(toml::Table::from_iter([ + ( + "git".to_owned(), + toml::Value::String("https://github.com/Rust-GPU/rust-gpu".to_owned()), + ), + ("rev".to_owned(), toml::Value::String(version)), + ])); + } self.write_shader_crate_cargo_toml_changes()?; Ok(()) } From 8411e9bfe344a74f0b75abaccd39adc00611f5c1 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 12:27:21 +0100 Subject: [PATCH 4/7] ci: test revs where target spec changed --- .github/workflows/push.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index 3f0bd481..cc44e24f 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -54,6 +54,20 @@ jobs: # unlikely many users of it? - 0.8.0 - 0.9.0 + + # target spec introduction + # last version before + - cc752312c3de6813a41189e46476d5c1be5e0bbe + # first version + - 02cefd101014f66b79dffb20a2c2b5b7c9038401 + # target specs change again just a few commits later + - bbb61f58b3d24f3f64745050eb214b90bf6dcce9 + + # just after target specs v2 refactor + # before + - a547c6e45266d613d9fec673e869d7a96181e47b + # after + - 2326b87fe1542eeb898065e36ac949307b55386d runs-on: ubuntu-latest env: RUST_LOG: debug From b3ba30c1dc78fe2ca74d7d56049b21d062d37444 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 12:48:58 +0100 Subject: [PATCH 5/7] HACK: force indexmap = "=2.11.4" while I wait for crates.io perms on spirt --- crates/cargo-gpu/src/install.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/cargo-gpu/src/install.rs b/crates/cargo-gpu/src/install.rs index c66c6b65..17e92ca2 100644 --- a/crates/cargo-gpu/src/install.rs +++ b/crates/cargo-gpu/src/install.rs @@ -196,6 +196,11 @@ edition = "2021" [dependencies.spirv-builder] package = "rustc_codegen_spirv" {version_spec} + +[dependencies] +elsa = {{ version = "=1.11.2", features = ["indexmap"] }} +indexmap = "1.7.0" +indexmap2 = {{ package = "indexmap", version = "=2.11.4" }} "# ); std::fs::write(checkout.join("Cargo.toml"), cargo_toml) From facdffcb245383bd3a5993077337eb58ef343970 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 14:56:23 +0100 Subject: [PATCH 6/7] xtask: allow setting glam version --- crates/xtask/src/main.rs | 124 ++++++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 34 deletions(-) diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 90abe02e..5beb1671 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -8,6 +8,7 @@ use anyhow::Context as _; use clap::Parser as _; +use std::borrow::Cow; /// Path to the shader crate const SHADER_CRATE_PATH: &str = "crates/shader-crate-template"; @@ -20,6 +21,9 @@ enum Cli { /// Build using the specified version of `spirv-std`. #[clap(long)] rust_gpu_version: Option, + /// The version of glam to use + #[clap(long)] + glam_version: Option, }, } @@ -128,52 +132,104 @@ impl ShaderCrateTemplateCargoTomlWriter { Ok(()) } + /// Add or replace a dependency in the shader-crate-template + fn set_dependency( + &mut self, + package: String, + version: DependencyVersion, + ) -> anyhow::Result<()> { + if let Some(version) = version.to_toml() { + let dependencies = self.get_cargo_dependencies_table(); + dependencies.insert(package, version); + self.write_shader_crate_cargo_toml_changes()?; + } + Ok(()) + } + /// Replace the `spirv-std` dependency version - fn replace_spirv_std_version(&mut self, version: String) -> anyhow::Result<()> { - let dependencies = self.get_cargo_dependencies_table(); - let spirv_std = dependencies.get_mut("spirv-std").unwrap(); - if version.contains('.') { - // semver - *spirv_std = toml::Value::String(version); + fn set_spirv_std_version(&mut self, version: &str) -> anyhow::Result<()> { + self.set_dependency( + "spirv-std".into(), + DependencyVersion::parse( + version.into(), + "https://github.com/Rust-GPU/rust-gpu".into(), + ), + ) + } + + /// Replace the `glam` dependency version + fn set_dependency_glam(&mut self, version: &str) -> anyhow::Result<()> { + self.set_dependency( + "glam".into(), + DependencyVersion::parse( + version.into(), + "https://github.com/bitshifter/glam-rs".into(), + ), + ) + } +} + +/// The version of a dependency +pub enum DependencyVersion<'a> { + /// Don't change anything, don't replace the dependency nor add it when it's not there. + Latest, + /// A version dependency for crates.io + Crates(Cow<'a, str>), + /// A git dependency on a specific rev + Git { + /// git repo + git: Cow<'a, str>, + /// git commit revision + rev: Cow<'a, str>, + }, +} + +impl<'a> DependencyVersion<'a> { + /// Try to parse a version from a string + pub fn parse(version: Cow<'a, str>, git: Cow<'a, str>) -> Self { + if version == "latest" { + Self::Latest + } else if version.contains('.') { + Self::Crates(version) } else { - // git rev - *spirv_std = toml::Value::Table(toml::Table::from_iter([ - ( - "git".to_owned(), - toml::Value::String("https://github.com/Rust-GPU/rust-gpu".to_owned()), - ), - ("rev".to_owned(), toml::Value::String(version)), - ])); + Self::Git { git, rev: version } + } + } + + /// Convert this version to a toml value, may fail if we want the latest version + pub fn to_toml(&self) -> Option { + match self { + Self::Latest => None, + Self::Crates(version) => Some(toml::Value::String(version.to_string())), + Self::Git { git, rev } => Some(toml::Value::Table(toml::Table::from_iter([ + ("git".to_owned(), toml::Value::String(git.to_string())), + ("rev".to_owned(), toml::Value::String(rev.to_string())), + ]))), } - self.write_shader_crate_cargo_toml_changes()?; - Ok(()) } } /// Run the xtask. -fn main() { +fn main() -> anyhow::Result<()> { env_logger::builder().init(); - let cli = Cli::parse(); - - match cli { + match &cli { Cli::TestBuild { rust_gpu_version: maybe_rust_gpu_version, + glam_version, } => { log::info!("installing cargo gpu"); - cmd(["cargo", "install", "--path", "crates/cargo-gpu"]).unwrap(); + cmd(["cargo", "install", "--path", "crates/cargo-gpu"])?; log::info!("setup project"); - let dir = tempfile::TempDir::with_prefix("test-shader-output").unwrap(); let mut overwriter = ShaderCrateTemplateCargoTomlWriter::new(); - overwriter.replace_output_dir(dir.path()).unwrap(); - - if let Some(rust_gpu_version) = maybe_rust_gpu_version { - if rust_gpu_version != "latest" { - overwriter - .replace_spirv_std_version(rust_gpu_version) - .unwrap(); - } + let dir = tempfile::TempDir::with_prefix("test-shader-output")?; + overwriter.replace_output_dir(dir.path())?; + if let Some(rust_gpu_version) = maybe_rust_gpu_version.as_ref() { + overwriter.set_spirv_std_version(&rust_gpu_version)?; + } + if let Some(glam_version) = glam_version.as_ref() { + overwriter.set_dependency_glam(&glam_version)?; } log::info!("building with auto-install"); @@ -186,12 +242,12 @@ fn main() { "--auto-install-rust-toolchain", "--rebuild-codegen", "--force-overwrite-lockfiles-v4-to-v3", - ]) - .unwrap(); + ])?; - cmd(["ls", "-lah", dir.path().to_str().unwrap()]).unwrap(); + cmd(["ls", "-lah", dir.path().to_str().unwrap()])?; //NOTE: manifest.json is the default value here, which should be valid - cmd(["cat", dir.path().join("manifest.json").to_str().unwrap()]).unwrap(); + cmd(["cat", dir.path().join("manifest.json").to_str().unwrap()])?; } } + Ok(()) } From 8533bee48ed3b2c33b4567247b533d31dfdd8701 Mon Sep 17 00:00:00 2001 From: firestar99 Date: Fri, 12 Dec 2025 15:01:44 +0100 Subject: [PATCH 7/7] ci: fix glam version to 0.30.7 where needed --- .github/workflows/push.yaml | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index cc44e24f..8c4c3bba 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -40,7 +40,8 @@ jobs: strategy: fail-fast: false matrix: - rust-gpu-version: + glam-version: [latest] + include: # As well as testing on each OS, we also want to test to make sure we're still supporting # older versions of `rust-gpu`. However, we can assume that these tests are already okay # across platforms, so we only need to test on Linux, the chepeast in terms of minutes. @@ -52,29 +53,49 @@ jobs: # """ # It's probably easily fixable. But also `0.7.0` was released in April 2023, so there's # unlikely many users of it? - - 0.8.0 - - 0.9.0 + - rust-gpu-version: 0.8.0 + - rust-gpu-version: 0.9.0 # target spec introduction # last version before - - cc752312c3de6813a41189e46476d5c1be5e0bbe - # first version - - 02cefd101014f66b79dffb20a2c2b5b7c9038401 + # * fails: compiler too old, `serde` using `#[diagnostic]` +# - rust-gpu-version: cc752312c3de6813a41189e46476d5c1be5e0bbe +# glam-version: 0.30.7 + # first version requiring target specs + # * fails: target spec mismatch! + # * resolution: Since this is just a few commits, I'd be fine ignoring it. +# - rust-gpu-version: 02cefd101014f66b79dffb20a2c2b5b7c9038401 +# glam-version: 0.30.7 # target specs change again just a few commits later - - bbb61f58b3d24f3f64745050eb214b90bf6dcce9 + # * fails: compiler too old, `proc-macro2` using `Literal::byte_character`. + # * resolution: want to support, can't be bothered to hack in old proc-macro2 versions +# - rust-gpu-version: bbb61f58b3d24f3f64745050eb214b90bf6dcce9 +# glam-version: 0.30.7 + + # testing rustc 1.5 months later + - rust-gpu-version: eea8998df9dc2fd8e7a65c5b5b7ae20c238a665a + glam-version: 0.30.7 # just after target specs v2 refactor # before - - a547c6e45266d613d9fec673e869d7a96181e47b + - rust-gpu-version: a547c6e45266d613d9fec673e869d7a96181e47b + glam-version: 0.30.7 # after - - 2326b87fe1542eeb898065e36ac949307b55386d + - rust-gpu-version: 2326b87fe1542eeb898065e36ac949307b55386d + glam-version: 0.30.7 + + # glam semver breakage due to vector type refactor + # before, glam fixed to 0.30.7 in this commit + - rust-gpu-version: f79c4181a5dc2d37303947b113f190930c6c1ce6 + # after, glam >0.30.8 + - rust-gpu-version: e767f24f2565baf1a71bbaf84d453d181cab2417 runs-on: ubuntu-latest env: RUST_LOG: debug steps: - uses: actions/checkout@v4 - name: Run a full build - run: cargo xtask test-build --rust-gpu-version ${{ matrix.rust-gpu-version }} + run: cargo xtask test-build --rust-gpu-version ${{ matrix.rust-gpu-version }} --glam-version ${{ matrix.glam-version }} lint: runs-on: ubuntu-latest