Skip to content

Commit

Permalink
Support CI tests for old rust-gpu versions
Browse files Browse the repository at this point in the history
Adds `rust-gpu` versions, `0.8.0` and `0.9.0` to the Linux matrix
on CI tests. `0.7.0` has a probably minor dependency error, but
it's also 18 months old and there probably aren't many users of it.

Notes:
* Adds a version arg to: `just build-shader-template 0.8.0`.
* Offers a new CLI arg to workaround a bug where conflicting v3/v4
  versions of `Cargo.lock` files (between the shader and workspace)
  cause a build error. See `force_overwrite_lockfiles_v4_to_v3` arg.
  • Loading branch information
tombh committed Jan 28, 2025
1 parent 2da63bc commit 23ab263
Show file tree
Hide file tree
Showing 16 changed files with 525 additions and 135 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
rust-gpu-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.
#
# `0.7.0` currently fails building `spirv-builder-cli` with:
# """
# 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:
Expand All @@ -35,7 +52,7 @@ jobs:
rustup update
- run: cargo test
- name: Run a full build
run: just build-shader-template
run: just build-shader-template ${{ matrix.rust-gpu-version }}


lints:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ flamegraph.svg

# Compiled shader assets from running tests
crates/shader-crate-template/shaders

# Build artefacts used by CI tests
tmp/*
31 changes: 19 additions & 12 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 @@ -23,6 +23,7 @@ toml.workspace = true
chrono.workspace = true
http.workspace = true
crossterm.workspace = true
version_check = "0.9.5"

[dev-dependencies]
test-log.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/cargo-gpu/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub struct Build {

impl Build {
/// Entrypoint
pub fn run(&mut self) -> anyhow::Result<()> {
let spirv_builder_cli_path = self.install.run()?;
pub fn run(&mut self) -> anyhow::Result<Vec<std::path::PathBuf>> {
let (spirv_builder_cli_path, cargo_lock_files_to_revert) = self.install.run()?;

// Ensure the shader output dir exists
log::debug!(
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Build {
std::fs::remove_file(spirv_manifest)?;
}

Ok(())
Ok(cargo_lock_files_to_revert)
}
}

Expand Down
10 changes: 7 additions & 3 deletions crates/cargo-gpu/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ pub struct Install {

impl Install {
/// Returns a [`SpirvCLI`] instance, responsible for ensuring the right version of the `spirv-builder-cli` crate.
fn spirv_cli(&self, shader_crate_path: &std::path::PathBuf) -> anyhow::Result<SpirvCli> {
fn spirv_cli(&self, shader_crate_path: &std::path::Path) -> anyhow::Result<SpirvCli> {
SpirvCli::new(
shader_crate_path,
self.spirv_install.spirv_builder_source.clone(),
self.spirv_install.spirv_builder_version.clone(),
self.spirv_install.rust_toolchain.clone(),
self.spirv_install.auto_install_rust_toolchain,
self.spirv_install.force_overwrite_lockfiles_v4_to_v3,
)
}

Expand Down Expand Up @@ -170,7 +171,7 @@ impl Install {
}

/// Install the binary pair and return the paths, (dylib, cli).
pub fn run(&mut self) -> anyhow::Result<std::path::PathBuf> {
pub fn run(&mut self) -> anyhow::Result<(std::path::PathBuf, Vec<std::path::PathBuf>)> {
// Ensure the cache dir exists
let cache_dir = cache_dir()?;
log::info!("cache directory is '{}'", cache_dir.display());
Expand Down Expand Up @@ -266,7 +267,10 @@ impl Install {

self.spirv_install.dylib_path = dest_dylib_path;

Ok(dest_cli_path)
Ok((
dest_cli_path,
spirv_version.cargo_lock_files_with_changed_manifest_versions,
))
}

/// The `spirv-builder` crate from the main `rust-gpu` repo hasn't always been setup to
Expand Down
40 changes: 21 additions & 19 deletions crates/cargo-gpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ fn run() -> anyhow::Result<()> {
"installing with final merged arguments: {:#?}",
command.install
);
let _: std::path::PathBuf = command.install.run()?;
let (_, cargo_lock_files_to_revert) = command.install.run()?;
spirv_cli::SpirvCli::revert_cargo_lock_manifest_versions(cargo_lock_files_to_revert)?;
}
Command::Build(build) => {
let shader_crate_path = build.install.spirv_install.shader_crate;
let mut command =
config::Config::clap_command_with_cargo_config(&shader_crate_path, env_args)?;
log::debug!("building with final merged arguments: {command:#?}");
command.run()?;
let cargo_lock_files_to_revert = command.run()?;
spirv_cli::SpirvCli::revert_cargo_lock_manifest_versions(cargo_lock_files_to_revert)?;
}
Command::Show(show) => show.run()?,
Command::DumpUsage => dump_full_usage_for_readme()?,
Expand Down Expand Up @@ -265,6 +267,23 @@ mod test {
use crate::cache_dir;
use std::io::Write as _;

fn copy_dir_all(
src: impl AsRef<std::path::Path>,
dst: impl AsRef<std::path::Path>,
) -> anyhow::Result<()> {
std::fs::create_dir_all(&dst)?;
for maybe_entry in std::fs::read_dir(src)? {
let entry = maybe_entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
} else {
std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}

pub fn shader_crate_template_path() -> std::path::PathBuf {
let project_base = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
project_base.join("../shader-crate-template")
Expand Down Expand Up @@ -295,21 +314,4 @@ mod test {
}
std::fs::remove_dir_all(cache_dir).unwrap();
}

pub fn copy_dir_all(
src: impl AsRef<std::path::Path>,
dst: impl AsRef<std::path::Path>,
) -> anyhow::Result<()> {
std::fs::create_dir_all(&dst)?;
for maybe_entry in std::fs::read_dir(src)? {
let entry = maybe_entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
} else {
std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}
}
Loading

0 comments on commit 23ab263

Please sign in to comment.