@@ -28,6 +28,28 @@ pub struct ShaderCrateBuilderParams<W, T, C, O, E> {
28
28
pub build : SpirvBuilder ,
29
29
/// Parameters of the codegen backend installation for the shader crate.
30
30
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 ,
31
53
/// Writer of user output.
32
54
pub writer : W ,
33
55
/// Callbacks to halt toolchain installation.
@@ -51,13 +73,27 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
51
73
Self { install, ..self }
52
74
}
53
75
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
+
54
89
/// Replaces the writer of user output.
55
90
#[ inline]
56
91
#[ must_use]
57
92
pub fn writer < NW > ( self , writer : NW ) -> ShaderCrateBuilderParams < NW , T , C , O , E > {
58
93
ShaderCrateBuilderParams {
59
94
build : self . build ,
60
95
install : self . install ,
96
+ force_overwrite_lockfiles_v4_to_v3 : self . force_overwrite_lockfiles_v4_to_v3 ,
61
97
writer,
62
98
halt : self . halt ,
63
99
stdio_cfg : self . stdio_cfg ,
@@ -74,6 +110,7 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
74
110
ShaderCrateBuilderParams {
75
111
build : self . build ,
76
112
install : self . install ,
113
+ force_overwrite_lockfiles_v4_to_v3 : self . force_overwrite_lockfiles_v4_to_v3 ,
77
114
writer : self . writer ,
78
115
halt,
79
116
stdio_cfg : self . stdio_cfg ,
@@ -90,6 +127,7 @@ impl<W, T, C, O, E> ShaderCrateBuilderParams<W, T, C, O, E> {
90
127
ShaderCrateBuilderParams {
91
128
build : self . build ,
92
129
install : self . install ,
130
+ force_overwrite_lockfiles_v4_to_v3 : self . force_overwrite_lockfiles_v4_to_v3 ,
93
131
writer : self . writer ,
94
132
halt : self . halt ,
95
133
stdio_cfg,
@@ -122,6 +160,7 @@ impl Default for DefaultShaderCrateBuilderParams {
122
160
Self {
123
161
build : SpirvBuilder :: default ( ) ,
124
162
install : InstallParams :: default ( ) ,
163
+ force_overwrite_lockfiles_v4_to_v3 : false ,
125
164
writer : io:: stdout ( ) ,
126
165
halt : HaltToolchainInstallation :: noop ( ) ,
127
166
stdio_cfg : StdioCfg :: inherit ( ) ,
@@ -172,6 +211,7 @@ where
172
211
let ShaderCrateBuilderParams {
173
212
mut build,
174
213
install,
214
+ force_overwrite_lockfiles_v4_to_v3,
175
215
mut writer,
176
216
halt,
177
217
mut stdio_cfg,
@@ -202,7 +242,7 @@ where
202
242
let lockfile_mismatch_handler = LockfileMismatchHandler :: new (
203
243
& backend_to_install. shader_crate ,
204
244
& backend. toolchain_channel ,
205
- backend_to_install . params . force_overwrite_lockfiles_v4_to_v3 ,
245
+ force_overwrite_lockfiles_v4_to_v3,
206
246
) ?;
207
247
208
248
#[ expect( clippy:: unreachable, reason = "target was already set" ) ]
0 commit comments