@@ -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" ) ]
0 commit comments