@@ -11,18 +11,7 @@ use std::path::Path;
11
11
12
12
pub use watch:: StopWatch ;
13
13
14
- #[ cfg( feature = "api-4-0" ) ]
15
- use prebuilt_4_0 as godot4_prebuilt;
16
- #[ cfg( feature = "api-4-1" ) ]
17
- use prebuilt_4_1 as godot4_prebuilt;
18
-
19
- // If none of the api-* features are provided, use default prebuilt version (typically latest Godot stable release).
20
- #[ cfg( not( any(
21
- feature = "api-4-0" , //
22
- feature = "api-4-1" , //
23
- feature = "api-custom" , //
24
- ) ) ) ]
25
- use prebuilt_4_2 as godot4_prebuilt;
14
+ mod import;
26
15
27
16
// This is outside of `godot_version` to allow us to use it even when we don't have the `api-custom`
28
17
// feature enabled.
@@ -45,7 +34,7 @@ pub struct GodotVersion {
45
34
}
46
35
47
36
// ----------------------------------------------------------------------------------------------------------------------------------------------
48
- // Regenerate all files
37
+ // Custom mode: Regenerate all files
49
38
50
39
// This file is explicitly included in unit tests. Needs regex dependency.
51
40
#[ cfg( test) ]
@@ -82,12 +71,13 @@ mod custom {
82
71
pub use custom:: * ;
83
72
84
73
// ----------------------------------------------------------------------------------------------------------------------------------------------
85
- // Reuse existing files
74
+ // Prebuilt mode: Reuse existing files
86
75
87
76
#[ cfg( not( feature = "api-custom" ) ) ]
88
77
#[ path = "" ]
89
78
mod prebuilt {
90
79
use super :: * ;
80
+ use crate :: import:: godot4_prebuilt;
91
81
92
82
pub fn load_gdextension_json ( _watch : & mut StopWatch ) -> & ' static str {
93
83
godot4_prebuilt:: load_gdextension_json ( )
@@ -130,14 +120,6 @@ pub use prebuilt::*;
130
120
// ----------------------------------------------------------------------------------------------------------------------------------------------
131
121
// Common
132
122
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 ) ] ;
140
-
141
123
pub fn clear_dir ( dir : & Path , watch : & mut StopWatch ) {
142
124
if dir. exists ( ) {
143
125
remove_dir_all_reliable ( dir) ;
@@ -146,54 +128,43 @@ pub fn clear_dir(dir: &Path, watch: &mut StopWatch) {
146
128
std:: fs:: create_dir_all ( dir) . unwrap_or_else ( |e| panic ! ( "failed to create dir: {e}" ) ) ;
147
129
}
148
130
131
+ /// Emit the `cfg` flags for the current Godot version. Allows rustc to know about valid `cfg` values.
149
132
pub fn emit_godot_version_cfg ( ) {
133
+ // This could also be done as `KNOWN_API_VERSIONS.len() - 1`, but this is more explicit.
134
+ let all_versions = import:: ALL_VERSIONS ;
135
+
136
+ // Emit `rustc-check-cfg` for all minor versions (patch .0), so Cargo doesn't complain when we use the #[cfg]s.
137
+ for ( _, minor, patch) in all_versions. iter ( ) . copied ( ) {
138
+ if minor > 0 && patch == 0 {
139
+ println ! ( r#"cargo:rustc-check-cfg=cfg(since_api, values("4.{minor}"))"# ) ;
140
+ println ! ( r#"cargo:rustc-check-cfg=cfg(before_api, values("4.{minor}"))"# ) ;
141
+ }
142
+ }
143
+
150
144
let GodotVersion {
151
- major,
145
+ major : _ ,
152
146
minor,
153
147
patch,
154
148
..
155
149
} = get_godot_version ( ) ;
156
150
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
+ // Emit `rustc-cfg` dependent on current API version.
160
152
// Start at 1; checking for "since/before 4.0" makes no sense
153
+ let upcoming_minor = all_versions. last ( ) . unwrap ( ) . 1 ;
161
154
for m in 1 ..=minor {
162
- println ! ( r#"cargo:rustc-cfg=since_api="{major} .{m}""# ) ;
155
+ println ! ( r#"cargo:rustc-cfg=since_api="4 .{m}""# ) ;
163
156
}
164
- for m in minor + 1 ..=max {
165
- println ! ( r#"cargo:rustc-cfg=before_api="{major} .{m}""# ) ;
157
+ for m in minor + 1 ..=upcoming_minor {
158
+ println ! ( r#"cargo:rustc-cfg=before_api="4 .{m}""# ) ;
166
159
}
167
160
168
161
// The below configuration keys are very rarely needed and should generally not be used.
169
- println ! ( r#"cargo:rustc-cfg=gdextension_minor_api="{major}.{minor}""# ) ;
170
-
171
- // Godot drops the patch version if it is 0.
172
- if patch != 0 {
173
- println ! ( r#"cargo:rustc-cfg=gdextension_exact_api="{major}.{minor}.{patch}""# ) ;
174
- } else {
175
- println ! ( r#"cargo:rustc-cfg=gdextension_exact_api="{major}.{minor}""# ) ;
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
- }
162
+ // Emit #[cfg]s since/before for patch level.
163
+ for ( _, m, p) in all_versions. iter ( ) . copied ( ) {
164
+ if ( m, p) >= ( minor, patch) {
165
+ println ! ( r#"cargo:rustc-cfg=since_patch_api="4.{m}.{p}""# ) ;
166
+ } else {
167
+ println ! ( r#"cargo:rustc-cfg=before_patch_api="4.{m}.{p}""# ) ;
197
168
}
198
169
}
199
170
}
@@ -241,19 +212,3 @@ pub fn before_api(major_minor: &str) -> bool {
241
212
pub fn since_api ( major_minor : & str ) -> bool {
242
213
!before_api ( major_minor)
243
214
}
244
-
245
- //
246
- // pub fn write_module_file(path: &Path) {
247
- // let code = quote! {
248
- // pub mod table_builtins;
249
- // pub mod table_builtins_lifecycle;
250
- // pub mod table_servers_classes;
251
- // pub mod table_scene_classes;
252
- // pub mod table_editor_classes;
253
- // pub mod table_utilities;
254
- //
255
- // pub mod central;
256
- // pub mod gdextension_interface;
257
- // pub mod interface;
258
- // };
259
- // }
0 commit comments