|
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 _; |
4 | 8 |
|
5 | 9 | use anyhow::Context as _; |
6 | | -use rustc_codegen_spirv_cache::user_output; |
7 | 10 | 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}; |
10 | 13 |
|
11 | 14 | /// `Cargo.lock` manifest version 4 became the default in Rust 1.83.0. Conflicting manifest |
12 | 15 | /// versions between the workspace and the shader crate, can cause problems. |
13 | 16 | const RUST_VERSION_THAT_USES_V4_CARGO_LOCKS: Version = Version::new(1, 83, 0); |
14 | 17 |
|
15 | 18 | /// Cargo dependency for `spirv-builder` and the rust toolchain channel. |
16 | 19 | #[derive(Debug, Clone)] |
| 20 | +#[expect(clippy::module_name_repetitions, reason = "such naming is intentional")] |
| 21 | +#[non_exhaustive] |
17 | 22 | pub struct LockfileMismatchHandler { |
18 | 23 | /// `Cargo.lock`s that have had their manifest versions changed by us and need changing back. |
19 | 24 | pub cargo_lock_files_with_changed_manifest_versions: Vec<std::path::PathBuf>, |
20 | 25 | } |
21 | 26 |
|
22 | 27 | impl LockfileMismatchHandler { |
23 | 28 | /// Create instance |
| 29 | + #[inline] |
24 | 30 | pub fn new( |
25 | 31 | shader_crate_path: &std::path::Path, |
26 | 32 | toolchain_channel: &str, |
@@ -198,9 +204,10 @@ impl LockfileMismatchHandler { |
198 | 204 | Ok(()) |
199 | 205 | } |
200 | 206 |
|
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<()> { |
204 | 211 | for offending_cargo_lock in &self.cargo_lock_files_with_changed_manifest_versions { |
205 | 212 | log::debug!("Reverting: {}", offending_cargo_lock.display()); |
206 | 213 | Self::replace_cargo_lock_manifest_version(offending_cargo_lock, "3", "4") |
@@ -266,6 +273,7 @@ impl LockfileMismatchHandler { |
266 | 273 | } |
267 | 274 |
|
268 | 275 | impl Drop for LockfileMismatchHandler { |
| 276 | + #[inline] |
269 | 277 | fn drop(&mut self) { |
270 | 278 | let result = self.revert_cargo_lock_manifest_versions(); |
271 | 279 | if let Err(error) = result { |
|
0 commit comments