Skip to content

Commit c92b3dc

Browse files
committed
Move force overwrite lockfile v4 to v3 flag into cargo-gpu
1 parent f3fe48f commit c92b3dc

File tree

4 files changed

+69
-29
lines changed

4 files changed

+69
-29
lines changed

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ pub struct ShaderCrateBuilderParams<W, T, C, O, E> {
2828
pub build: SpirvBuilder,
2929
/// Parameters of the codegen backend installation for the shader crate.
3030
pub install: InstallParams,
31+
/// There is a tricky situation where a shader crate that depends on workspace config can have
32+
/// a different `Cargo.lock` lockfile version from the the workspace's `Cargo.lock`. This can
33+
/// prevent builds when an old Rust toolchain doesn't recognise the newer lockfile version.
34+
///
35+
/// The ideal way to resolve this would be to match the shader crate's toolchain with the
36+
/// workspace's toolchain. However, that is not always possible. Another solution is to
37+
/// `exclude = [...]` the problematic shader crate from the workspace. This also may not be a
38+
/// suitable solution if there are a number of shader crates all sharing similar config and
39+
/// you don't want to have to copy/paste and maintain that config across all the shaders.
40+
///
41+
/// So a somewhat hacky workaround is to overwrite lockfile versions. Enabling this flag
42+
/// will only come into effect if there are a mix of v3/v4 lockfiles. It will also
43+
/// only overwrite versions for the duration of a build. It will attempt to return the versions
44+
/// to their original values once the build is finished. However, of course, unexpected errors
45+
/// can occur and the overwritten values can remain. Hence why this behaviour is not enabled by
46+
/// default.
47+
///
48+
/// This hack is possible because the change from v3 to v4 only involves a minor change to the
49+
/// way source URLs are encoded. See these PRs for more details:
50+
/// * <https://github.com/rust-lang/cargo/pull/12280>
51+
/// * <https://github.com/rust-lang/cargo/pull/14595>
52+
pub force_overwrite_lockfiles_v4_to_v3: bool,
3153
/// Writer of user output.
3254
pub writer: W,
3355
/// Callbacks to halt toolchain installation.
@@ -51,13 +73,27 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
5173
Self { install, ..self }
5274
}
5375

76+
/// Sets whether to force overwriting lockfiles from v4 to v3.
77+
#[inline]
78+
#[must_use]
79+
pub fn force_overwrite_lockfiles_v4_to_v3(
80+
self,
81+
force_overwrite_lockfiles_v4_to_v3: bool,
82+
) -> Self {
83+
Self {
84+
force_overwrite_lockfiles_v4_to_v3,
85+
..self
86+
}
87+
}
88+
5489
/// Replaces the writer of user output.
5590
#[inline]
5691
#[must_use]
5792
pub fn writer<NW>(self, writer: NW) -> ShaderCrateBuilderParams<NW, T, C, O, E> {
5893
ShaderCrateBuilderParams {
5994
build: self.build,
6095
install: self.install,
96+
force_overwrite_lockfiles_v4_to_v3: self.force_overwrite_lockfiles_v4_to_v3,
6197
writer,
6298
halt: self.halt,
6399
stdio_cfg: self.stdio_cfg,
@@ -74,6 +110,7 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
74110
ShaderCrateBuilderParams {
75111
build: self.build,
76112
install: self.install,
113+
force_overwrite_lockfiles_v4_to_v3: self.force_overwrite_lockfiles_v4_to_v3,
77114
writer: self.writer,
78115
halt,
79116
stdio_cfg: self.stdio_cfg,
@@ -90,6 +127,7 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
90127
ShaderCrateBuilderParams {
91128
build: self.build,
92129
install: self.install,
130+
force_overwrite_lockfiles_v4_to_v3: self.force_overwrite_lockfiles_v4_to_v3,
93131
writer: self.writer,
94132
halt: self.halt,
95133
stdio_cfg,
@@ -122,6 +160,7 @@ impl Default for DefaultShaderCrateBuilderParams {
122160
Self {
123161
build: SpirvBuilder::default(),
124162
install: InstallParams::default(),
163+
force_overwrite_lockfiles_v4_to_v3: false,
125164
writer: io::stdout(),
126165
halt: HaltToolchainInstallation::noop(),
127166
stdio_cfg: StdioCfg::inherit(),
@@ -172,6 +211,7 @@ where
172211
let ShaderCrateBuilderParams {
173212
mut build,
174213
install,
214+
force_overwrite_lockfiles_v4_to_v3,
175215
mut writer,
176216
halt,
177217
mut stdio_cfg,
@@ -202,7 +242,7 @@ where
202242
let lockfile_mismatch_handler = LockfileMismatchHandler::new(
203243
&backend_to_install.shader_crate,
204244
&backend.toolchain_channel,
205-
backend_to_install.params.force_overwrite_lockfiles_v4_to_v3,
245+
force_overwrite_lockfiles_v4_to_v3,
206246
)?;
207247

208248
#[expect(clippy::unreachable, reason = "target was already set")]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl LockfileMismatchHandler {
6969
})
7070
}
7171

72-
/// See docs for [`force_overwrite_lockfiles_v4_to_v3`](crate::cache::install::InstallParams::force_overwrite_lockfiles_v4_to_v3)
72+
/// See docs for [`force_overwrite_lockfiles_v4_to_v3`](field@crate::build::ShaderCrateBuilderParams::force_overwrite_lockfiles_v4_to_v3)
7373
/// flag for why we do this.
7474
fn ensure_workspace_rust_version_does_not_conflict_with_shader(
7575
shader_crate_path: &Path,
@@ -97,7 +97,7 @@ impl LockfileMismatchHandler {
9797
}
9898
}
9999

100-
/// See docs for [`force_overwrite_lockfiles_v4_to_v3`](crate::cache::install::InstallParams::force_overwrite_lockfiles_v4_to_v3)
100+
/// See docs for [`force_overwrite_lockfiles_v4_to_v3`](field@crate::build::ShaderCrateBuilderParams::force_overwrite_lockfiles_v4_to_v3)
101101
/// flag for why we do this.
102102
fn ensure_shader_rust_version_does_not_conflict_with_any_cargo_locks(
103103
shader_crate_path: &Path,
@@ -335,7 +335,7 @@ pub enum LockfileMismatchError {
335335
/// Conflicting lockfile manifest versions detected, with advice on how to resolve them
336336
/// by setting the [`force_overwrite_lockfiles_v4_to_v3`] flag.
337337
///
338-
/// [`force_overwrite_lockfiles_v4_to_v3`]: crate::spirv_cache::backend::InstallParams::force_overwrite_lockfiles_v4_to_v3
338+
/// [`force_overwrite_lockfiles_v4_to_v3`]: field@crate::build::ShaderCrateBuilderParams::force_overwrite_lockfiles_v4_to_v3
339339
#[error(
340340
r#"conflicting `Cargo.lock` versions detected ⚠️
341341

crates/cargo-gpu/src/build.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ pub struct InstallArgs {
5656
#[serde(flatten)]
5757
pub backend: Install,
5858

59+
/// There is a tricky situation where a shader crate that depends on workspace config can have
60+
/// a different `Cargo.lock` lockfile version from the the workspace's `Cargo.lock`. This can
61+
/// prevent builds when an old Rust toolchain doesn't recognise the newer lockfile version.
62+
///
63+
/// The ideal way to resolve this would be to match the shader crate's toolchain with the
64+
/// workspace's toolchain. However, that is not always possible. Another solution is to
65+
/// `exclude = [...]` the problematic shader crate from the workspace. This also may not be a
66+
/// suitable solution if there are a number of shader crates all sharing similar config and
67+
/// you don't want to have to copy/paste and maintain that config across all the shaders.
68+
///
69+
/// So a somewhat hacky workaround is to overwrite lockfile versions. Enabling this flag
70+
/// will only come into effect if there are a mix of v3/v4 lockfiles. It will also
71+
/// only overwrite versions for the duration of a build. It will attempt to return the versions
72+
/// to their original values once the build is finished. However, of course, unexpected errors
73+
/// can occur and the overwritten values can remain. Hence why this behaviour is not enabled by
74+
/// default.
75+
///
76+
/// This hack is possible because the change from v3 to v4 only involves a minor change to the
77+
/// way source URLs are encoded. See these PRs for more details:
78+
/// * <https://github.com/rust-lang/cargo/pull/12280>
79+
/// * <https://github.com/rust-lang/cargo/pull/14595>
80+
#[clap(long, action, verbatim_doc_comment)]
81+
pub force_overwrite_lockfiles_v4_to_v3: bool,
82+
5983
/// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
6084
#[clap(long, action)]
6185
pub auto_install_rust_toolchain: bool,
@@ -87,6 +111,7 @@ impl Build {
87111
let halt = ask_for_user_consent(self.install.auto_install_rust_toolchain);
88112
let crate_builder_params = ShaderCrateBuilderParams::from(self.build.spirv_builder.clone())
89113
.install(self.install.backend.params.clone())
114+
.force_overwrite_lockfiles_v4_to_v3(self.install.force_overwrite_lockfiles_v4_to_v3)
90115
.halt(halt);
91116
let crate_builder = ShaderCrateBuilder::new(crate_builder_params)?;
92117

crates/rustc_codegen_spirv-cache/src/backend.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,6 @@ pub struct InstallParams {
143143
/// saves about 200MiB of disk space.
144144
#[cfg_attr(feature = "clap", clap(long = "no-clear-target", default_value = "true", action = clap::ArgAction::SetFalse))]
145145
pub clear_target: bool,
146-
147-
/// There is a tricky situation where a shader crate that depends on workspace config can have
148-
/// a different `Cargo.lock` lockfile version from the the workspace's `Cargo.lock`. This can
149-
/// prevent builds when an old Rust toolchain doesn't recognise the newer lockfile version.
150-
///
151-
/// The ideal way to resolve this would be to match the shader crate's toolchain with the
152-
/// workspace's toolchain. However, that is not always possible. Another solution is to
153-
/// `exclude = [...]` the problematic shader crate from the workspace. This also may not be a
154-
/// suitable solution if there are a number of shader crates all sharing similar config and
155-
/// you don't want to have to copy/paste and maintain that config across all the shaders.
156-
///
157-
/// So a somewhat hacky workaround is to overwrite lockfile versions. Enabling this flag
158-
/// will only come into effect if there are a mix of v3/v4 lockfiles. It will also
159-
/// only overwrite versions for the duration of a build. It will attempt to return the versions
160-
/// to their original values once the build is finished. However, of course, unexpected errors
161-
/// can occur and the overwritten values can remain. Hence why this behaviour is not enabled by
162-
/// default.
163-
///
164-
/// This hack is possible because the change from v3 to v4 only involves a minor change to the
165-
/// way source URLs are encoded. See these PRs for more details:
166-
/// * <https://github.com/rust-lang/cargo/pull/12280>
167-
/// * <https://github.com/rust-lang/cargo/pull/14595>
168-
#[cfg_attr(feature = "clap", clap(long, action, verbatim_doc_comment))]
169-
pub force_overwrite_lockfiles_v4_to_v3: bool,
170146
}
171147

172148
impl Default for InstallParams {
@@ -177,7 +153,6 @@ impl Default for InstallParams {
177153
spirv_builder_version: None,
178154
rebuild_codegen: false,
179155
clear_target: true,
180-
force_overwrite_lockfiles_v4_to_v3: false,
181156
}
182157
}
183158
}

0 commit comments

Comments
 (0)