Skip to content

Commit bf32a23

Browse files
committed
Move lockfile manifest version mismatch handling out of CLI
1 parent fb64091 commit bf32a23

File tree

11 files changed

+78
-19
lines changed

11 files changed

+78
-19
lines changed

Cargo.lock

Lines changed: 11 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: 1 addition & 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-build",
45
"crates/cargo-gpu",
56
"crates/xtask",
67
]

crates/cargo-gpu-build/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cargo-gpu-build"
3+
description = "Builder of `rust-gpu` shader crates"
4+
version.workspace = true
5+
edition.workspace = true
6+
repository.workspace = true
7+
keywords.workspace = true
8+
license.workspace = true
9+
10+
[dependencies]
11+
rustc_codegen_spirv-cache = { path = "../rustc_codegen_spirv-cache" }
12+
anyhow.workspace = true
13+
semver.workspace = true
14+
log.workspace = true
15+
16+
[lints]
17+
workspace = true

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Rust GPU shader crate builder.
2+
//!
3+
//! This library allows you to easily compile your `rust-gpu` shaders,
4+
//! without requiring you to fix your entire project to a specific toolchain.
5+
//!
6+
//! # How it works
7+
//!
8+
//! This library manages installations of `rustc_codegen_spirv`
9+
//! using [`rustc_codegen_spirv-cache`](spirv_cache) crate.
10+
//!
11+
//! Then is uses [`spirv-builder`](spirv_builder) crate
12+
//! to pass the many additional parameters required to configure rustc and our codegen backend,
13+
//! but provide you with a toolchain-agnostic version that you may use from stable rustc.
14+
15+
#![expect(clippy::missing_errors_doc, reason = "temporary allow this")] // TODO: remove this & fix documentation
16+
#![expect(clippy::pub_use, reason = "part of public API")]
17+
18+
pub use rustc_codegen_spirv_cache as spirv_cache;
19+
pub use rustc_codegen_spirv_cache::spirv_builder;
20+
21+
pub mod lockfile;

crates/cargo-gpu/src/lockfile.rs renamed to crates/cargo-gpu-build/src/lockfile.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
//! Handles lockfile version conflicts and downgrades. Stable uses lockfile v4, but rust-gpu
2-
//! v0.9.0 uses an old toolchain requiring v3 and will refuse to build with a v4 lockfile being
3-
//! present. This module takes care of warning the user and potentially downgrading the lockfile.
1+
//! Handles lockfile version conflicts and downgrades.
2+
//!
3+
//! Stable uses lockfile v4, but rust-gpu v0.9.0 uses an old toolchain requiring v3
4+
//! and will refuse to build with a v4 lockfile being present.
5+
//! This module takes care of warning the user and potentially downgrading the lockfile.
6+
7+
use std::io::Write as _;
48

59
use anyhow::Context as _;
6-
use rustc_codegen_spirv_cache::user_output;
710
use semver::Version;
8-
use spirv_builder::query_rustc_version;
9-
use std::io::Write as _;
11+
12+
use crate::{spirv_builder::query_rustc_version, spirv_cache::user_output};
1013

1114
/// `Cargo.lock` manifest version 4 became the default in Rust 1.83.0. Conflicting manifest
1215
/// versions between the workspace and the shader crate, can cause problems.
1316
const RUST_VERSION_THAT_USES_V4_CARGO_LOCKS: Version = Version::new(1, 83, 0);
1417

1518
/// Cargo dependency for `spirv-builder` and the rust toolchain channel.
1619
#[derive(Debug, Clone)]
20+
#[expect(clippy::module_name_repetitions, reason = "such naming is intentional")]
21+
#[non_exhaustive]
1722
pub struct LockfileMismatchHandler {
1823
/// `Cargo.lock`s that have had their manifest versions changed by us and need changing back.
1924
pub cargo_lock_files_with_changed_manifest_versions: Vec<std::path::PathBuf>,
2025
}
2126

2227
impl LockfileMismatchHandler {
2328
/// Create instance
29+
#[inline]
2430
pub fn new(
2531
shader_crate_path: &std::path::Path,
2632
toolchain_channel: &str,
@@ -198,9 +204,10 @@ impl LockfileMismatchHandler {
198204
Ok(())
199205
}
200206

201-
/// Once all install and builds have completed put their manifest versions back to how they
202-
/// were.
203-
pub fn revert_cargo_lock_manifest_versions(&self) -> anyhow::Result<()> {
207+
/// Once all install and builds have completed put their manifest versions back
208+
/// to how they were.
209+
#[inline]
210+
pub fn revert_cargo_lock_manifest_versions(&mut self) -> anyhow::Result<()> {
204211
for offending_cargo_lock in &self.cargo_lock_files_with_changed_manifest_versions {
205212
log::debug!("Reverting: {}", offending_cargo_lock.display());
206213
Self::replace_cargo_lock_manifest_version(offending_cargo_lock, "3", "4")
@@ -266,6 +273,7 @@ impl LockfileMismatchHandler {
266273
}
267274

268275
impl Drop for LockfileMismatchHandler {
276+
#[inline]
269277
fn drop(&mut self) {
270278
let result = self.revert_cargo_lock_manifest_versions();
271279
if let Err(error) = result {

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license.workspace = true
1010
default-run = "cargo-gpu"
1111

1212
[dependencies]
13-
rustc_codegen_spirv-cache = { path = "../rustc_codegen_spirv-cache", default-features = false }
13+
cargo-gpu-build = { path = "../cargo-gpu-build", default-features = false }
1414
cargo_metadata.workspace = true
1515
anyhow.workspace = true
1616
spirv-builder = { workspace = true, features = ["clap", "watch"] }

crates/cargo-gpu/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use std::{io::Write as _, path::PathBuf};
77

88
use anyhow::Context as _;
9-
use rustc_codegen_spirv_cache::user_output;
9+
use cargo_gpu_build::{lockfile::LockfileMismatchHandler, spirv_cache::user_output};
1010
use spirv_builder::{CompileResult, ModuleResult, SpirvBuilder};
1111

12-
use crate::{linkage::Linkage, lockfile::LockfileMismatchHandler, Install};
12+
use crate::{linkage::Linkage, Install};
1313

1414
/// Args for just a build
1515
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]

crates/cargo-gpu/src/dump_usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Convenience function for internal use. Dumps all the CLI usage instructions. Useful for
22
//! updating the README.
33
4-
use rustc_codegen_spirv_cache::user_output;
4+
use cargo_gpu_build::spirv_cache::user_output;
55

66
use crate::Cli;
77

crates/cargo-gpu/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ mod build;
5656
mod config;
5757
mod dump_usage;
5858
mod linkage;
59-
mod lockfile;
6059
mod metadata;
6160
mod show;
6261
mod test;
6362

64-
pub use rustc_codegen_spirv_cache::backend::*;
63+
pub use cargo_gpu_build::spirv_cache::backend::*;
6564
pub use spirv_builder;
6665

6766
/// All of the available subcommands for `cargo gpu`

crates/cargo-gpu/src/show.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{fs, path::Path};
44

55
use anyhow::bail;
6-
use rustc_codegen_spirv_cache::{
6+
use cargo_gpu_build::spirv_cache::{
77
cache::cache_dir,
88
spirv_source::{query_metadata, SpirvSource},
99
target_specs::update_target_specs_files,

0 commit comments

Comments
 (0)