@@ -130,7 +130,13 @@ pub use prebuilt::*;
130
130
// ----------------------------------------------------------------------------------------------------------------------------------------------
131
131
// Common
132
132
133
- const NEXT_MINOR_VERSION : u8 = 3 ;
133
+ // List of minor versions with the highest known patch number for each.
134
+ //
135
+ // We could have this just be a list of patch numbers, letting the index be the minor version. However it's more readable to include the
136
+ // minor versions as well.
137
+ //
138
+ // Note that when the patch version is `0`, then the patch number is not included in Godot versioning, i.e. `4.1.0` is displayed as `4.1`.
139
+ const HIGHEST_PATCH_VERSIONS : & [ ( u8 , u8 ) ] = & [ ( 0 , 4 ) , ( 1 , 4 ) , ( 2 , 2 ) , ( 3 , 0 ) ] ;
134
140
135
141
pub fn clear_dir ( dir : & Path , watch : & mut StopWatch ) {
136
142
if dir. exists ( ) {
@@ -148,8 +154,10 @@ pub fn emit_godot_version_cfg() {
148
154
..
149
155
} = get_godot_version ( ) ;
150
156
157
+ // This could also be done as `KNOWN_API_VERSIONS.len() - 1`, but this is more explicit.
158
+ let max = HIGHEST_PATCH_VERSIONS . last ( ) . unwrap ( ) . 0 ;
159
+
151
160
// Start at 1; checking for "since/before 4.0" makes no sense
152
- let max = NEXT_MINOR_VERSION ;
153
161
for m in 1 ..=minor {
154
162
println ! ( r#"cargo:rustc-cfg=since_api="{major}.{m}""# ) ;
155
163
}
@@ -166,6 +174,28 @@ pub fn emit_godot_version_cfg() {
166
174
} else {
167
175
println ! ( r#"cargo:rustc-cfg=gdextension_exact_api="{major}.{minor}""# ) ;
168
176
}
177
+
178
+ // Emit `rustc-check-cfg` so cargo doesn't complain when we use the cfgs.
179
+ for ( minor, highest_patch) in HIGHEST_PATCH_VERSIONS {
180
+ if * minor > 0 {
181
+ println ! ( r#"cargo::rustc-check-cfg=cfg(since_api, values("4.{minor}"))"# ) ;
182
+ println ! ( r#"cargo::rustc-check-cfg=cfg(before_api, values("4.{minor}"))"# ) ;
183
+ }
184
+
185
+ println ! ( r#"cargo::rustc-check-cfg=cfg(gdextension_minor_api, values("4.{minor}"))"# ) ;
186
+
187
+ for patch in 0 ..=* highest_patch {
188
+ if patch == 0 {
189
+ println ! (
190
+ r#"cargo::rustc-check-cfg=cfg(gdextension_exact_api, values("4.{minor}"))"#
191
+ ) ;
192
+ } else {
193
+ println ! (
194
+ r#"cargo::rustc-check-cfg=cfg(gdextension_exact_api, values("4.{minor}.{patch}"))"#
195
+ ) ;
196
+ }
197
+ }
198
+ }
169
199
}
170
200
171
201
// Function for safely removal of build directory. Workaround for errors happening during CI builds:
@@ -189,6 +219,29 @@ pub fn remove_dir_all_reliable(path: &Path) {
189
219
}
190
220
}
191
221
}
222
+
223
+ // Duplicates code from `make_gdext_build_struct` in `godot-codegen/generator/gdext_build_struct.rs`.
224
+ pub fn before_api ( major_minor : & str ) -> bool {
225
+ let mut parts = major_minor. split ( '.' ) ;
226
+ let queried_major = parts
227
+ . next ( )
228
+ . unwrap ( )
229
+ . parse :: < u8 > ( )
230
+ . expect ( "invalid major version" ) ;
231
+ let queried_minor = parts
232
+ . next ( )
233
+ . unwrap ( )
234
+ . parse :: < u8 > ( )
235
+ . expect ( "invalid minor version" ) ;
236
+ assert_eq ! ( queried_major, 4 , "major version must be 4" ) ;
237
+ let godot_version = get_godot_version ( ) ;
238
+ godot_version. minor < queried_minor
239
+ }
240
+
241
+ pub fn since_api ( major_minor : & str ) -> bool {
242
+ !before_api ( major_minor)
243
+ }
244
+
192
245
//
193
246
// pub fn write_module_file(path: &Path) {
194
247
// let code = quote! {
0 commit comments