Skip to content

Commit 3f65b3c

Browse files
committed
old toolchain support
1 parent fc31784 commit 3f65b3c

File tree

5 files changed

+23
-42
lines changed

5 files changed

+23
-42
lines changed

Cargo.lock

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude = [
1313
resolver = "2"
1414

1515
[workspace.dependencies]
16-
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "e040ab9c296f2c0f1555051d4b574969329715ec", default-features = false }
16+
spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu.git", rev = "eca83dfbfc0aae5c72f1e3f53081f5ccb72c27a4", default-features = false }
1717
anyhow = "1.0.94"
1818
clap = { version = "4.5.37", features = ["derive"] }
1919
crossterm = "0.28.1"
@@ -27,6 +27,7 @@ toml = "0.8.19"
2727
tempdir = "0.3.7"
2828
test-log = "0.2.16"
2929
cargo_metadata = "0.19.2"
30+
semver = "1.0.26"
3031

3132
[workspace.lints.rust]
3233
missing_docs = "warn"

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ relative-path.workspace = true
2222
serde.workspace = true
2323
serde_json.workspace = true
2424
crossterm.workspace = true
25-
version_check = "0.9.5"
25+
semver.workspace = true
2626

2727
[dev-dependencies]
2828
test-log.workspace = true

crates/cargo-gpu/src/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use crate::args::BuildArgs;
66
use crate::linkage::Linkage;
7+
use crate::lockfile::LockfileMismatchHandler;
78
use crate::{install::Install, target_spec_dir};
89
use anyhow::Context as _;
910
use spirv_builder::ModuleResult;
@@ -27,6 +28,14 @@ impl Build {
2728
pub fn run(&mut self) -> anyhow::Result<()> {
2829
let (rustc_codegen_spirv_location, toolchain_channel) = self.install.run()?;
2930

31+
let _lockfile_mismatch_handler = LockfileMismatchHandler::new(
32+
&self.install.spirv_install.shader_crate,
33+
&toolchain_channel,
34+
self.install
35+
.spirv_install
36+
.force_overwrite_lockfiles_v4_to_v3,
37+
)?;
38+
3039
let builder = &mut self.build_args.spirv_builder;
3140
builder.rustc_codegen_spirv_location = Some(rustc_codegen_spirv_location);
3241
builder.toolchain_overwrite = Some(toolchain_channel);

crates/cargo-gpu/src/lockfile.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
//! Then ensure that the relevant Rust toolchain and components are installed.
33
44
use anyhow::Context as _;
5+
use semver::Version;
6+
use spirv_builder::query_rustc_version;
57
use std::io::Write as _;
68

79
/// `Cargo.lock` manifest version 4 became the default in Rust 1.83.0. Conflicting manifest
810
/// versions between the workspace and the shader crate, can cause problems.
9-
const RUST_VERSION_THAT_USES_V4_CARGO_LOCKS: &str = "1.83.0";
11+
const RUST_VERSION_THAT_USES_V4_CARGO_LOCKS: Version = Version::new(1, 83, 0);
1012

1113
/// Cargo dependency for `spirv-builder` and the rust toolchain channel.
1214
#[derive(Debug, Clone)]
@@ -58,12 +60,8 @@ impl LockfileMismatchHandler {
5860
is_force_overwrite_lockfiles_v4_to_v3: bool,
5961
) -> anyhow::Result<Option<std::path::PathBuf>> {
6062
log::debug!("Ensuring no v3/v4 `Cargo.lock` conflicts from workspace Rust...");
61-
let workspace_rust_version =
62-
Self::get_rustc_version(None).context("reading rustc version")?;
63-
if version_check::Version::at_least(
64-
&workspace_rust_version,
65-
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS,
66-
) {
63+
let workspace_rust_version = query_rustc_version(None).context("reading rustc version")?;
64+
if workspace_rust_version >= RUST_VERSION_THAT_USES_V4_CARGO_LOCKS {
6765
log::debug!(
6866
"user's Rust is v{workspace_rust_version}, so no v3/v4 conflicts possible."
6967
);
@@ -91,11 +89,8 @@ impl LockfileMismatchHandler {
9189
) -> anyhow::Result<Option<std::path::PathBuf>> {
9290
log::debug!("Ensuring no v3/v4 `Cargo.lock` conflicts from shader's Rust...");
9391
let shader_rust_version =
94-
Self::get_rustc_version(Some(channel)).context("getting rustc version")?;
95-
if version_check::Version::at_least(
96-
&shader_rust_version,
97-
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS,
98-
) {
92+
query_rustc_version(Some(channel)).context("getting rustc version")?;
93+
if shader_rust_version >= RUST_VERSION_THAT_USES_V4_CARGO_LOCKS {
9994
log::debug!("shader's Rust is v{shader_rust_version}, so no v3/v4 conflicts possible.");
10095
return Ok(None);
10196
}
@@ -266,25 +261,6 @@ impl LockfileMismatchHandler {
266261
);
267262
std::process::exit(1);
268263
}
269-
270-
/// Get the version of `rustc`.
271-
fn get_rustc_version(maybe_toolchain: Option<&str>) -> anyhow::Result<version_check::Version> {
272-
let mut maybe_current_env_toolchain: Option<std::ffi::OsString> = None;
273-
if let Some(toolchain) = maybe_toolchain {
274-
maybe_current_env_toolchain = std::env::var_os("RUSTUP_TOOLCHAIN");
275-
std::env::set_var("RUSTUP_TOOLCHAIN", toolchain);
276-
}
277-
278-
let Some(version) = version_check::Version::read() else {
279-
anyhow::bail!("Couldn't get `rustc --version`");
280-
};
281-
282-
if let Some(current_env_toolchain) = maybe_current_env_toolchain {
283-
std::env::set_var("RUSTUP_TOOLCHAIN", current_env_toolchain);
284-
}
285-
286-
Ok(version)
287-
}
288264
}
289265

290266
impl Drop for LockfileMismatchHandler {

0 commit comments

Comments
 (0)