Skip to content

Commit 977f925

Browse files
committed
Migrate crate-local /gen directories to OUT_DIR
1 parent 587a7ba commit 977f925

File tree

13 files changed

+88
-45
lines changed

13 files changed

+88
-45
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ members = [
1919
]
2020

2121
#[patch."https://github.com/godot-rust/godot4-prebuilt"]
22-
#godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "4.1"}
22+
#godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "4.1" }

godot-bindings/src/godot_exe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use std::process::{Command, Output};
2020
// Note: CARGO_BUILD_TARGET_DIR and CARGO_TARGET_DIR are not set.
2121
// OUT_DIR would be standing to reason, but it's an unspecified path that cannot be referenced by CI.
2222
// const GODOT_VERSION_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen/godot_version.txt");
23-
const JSON_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen/extension_api.json");
2423

2524
pub fn load_gdextension_json(watch: &mut StopWatch) -> String {
26-
let json_path = Path::new(JSON_PATH);
25+
let path = format!("{}/extension_api.json", std::env::var("OUT_DIR").unwrap());
26+
let json_path = Path::new(&path);
2727

2828
// Listening to changes on files that are generated by this build step cause an infinite loop with cargo watch of
2929
// build -> detect change -> rebuild -> detect change -> ...

godot-bindings/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn emit_godot_version_cfg() {
170170

171171
// Function for safely removal of build directory. Workaround for errors happening during CI builds:
172172
// https://github.com/godot-rust/gdext/issues/616
173-
pub fn remove_dir_all_reliable(path: &std::path::Path) {
173+
pub fn remove_dir_all_reliable(path: &Path) {
174174
let mut retry_count = 0;
175175

176176
while path.exists() {
@@ -189,3 +189,18 @@ pub fn remove_dir_all_reliable(path: &std::path::Path) {
189189
}
190190
}
191191
}
192+
//
193+
// pub fn write_module_file(path: &Path) {
194+
// let code = quote! {
195+
// pub mod table_builtins;
196+
// pub mod table_builtins_lifecycle;
197+
// pub mod table_servers_classes;
198+
// pub mod table_scene_classes;
199+
// pub mod table_editor_classes;
200+
// pub mod table_utilities;
201+
//
202+
// pub mod central;
203+
// pub mod gdextension_interface;
204+
// pub mod interface;
205+
// };
206+
// }

godot-codegen/src/generator/extension_interface.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ pub fn generate_sys_interface_file(
2222
let code = if is_godot_4_0 {
2323
// Compat for 4.0.x
2424
// Most polyfills are in godot_exe.rs, fn polyfill_legacy_header()
25-
quote! {
26-
#[path = "../compat/compat_4_0.rs"]
27-
mod compat_4_0;
28-
29-
pub use compat_4_0::*;
30-
}
25+
// Module `compat_4_0` is directly imported in Rust code, behind #[cfg].
26+
TokenStream::new()
3127
} else {
3228
generate_proc_address_funcs(h_path)
3329
};
@@ -80,10 +76,8 @@ fn generate_proc_address_funcs(h_path: &Path) -> TokenStream {
8076

8177
// Do not derive Copy -- even though the struct is bitwise-copyable, this is rarely needed and may point to an error.
8278
let code = quote! {
83-
#[path = "../compat/compat_4_1plus.rs"]
84-
mod compat_4_1plus;
85-
86-
pub use compat_4_1plus::InitCompat;
79+
pub use crate::compat::InitCompat;
80+
// pub use crate::compat::compat_4_1plus::InitCompat;
8781

8882
pub struct GDExtensionInterface {
8983
#( #fptr_decls )*
@@ -101,6 +95,7 @@ fn generate_proc_address_funcs(h_path: &Path) -> TokenStream {
10195
}
10296
}
10397
};
98+
10499
code
105100
}
106101

godot-codegen/src/generator/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ pub mod virtual_traits;
3636
// - utility_functions
3737
// - native_structures
3838

39+
pub fn generate_sys_module_file(sys_gen_path: &Path, submit_fn: &mut SubmitFn) {
40+
let code = quote! {
41+
pub mod table_builtins;
42+
pub mod table_builtins_lifecycle;
43+
pub mod table_servers_classes;
44+
pub mod table_scene_classes;
45+
pub mod table_editor_classes;
46+
pub mod table_utilities;
47+
48+
pub mod central;
49+
pub mod gdextension_interface;
50+
pub mod interface;
51+
};
52+
53+
submit_fn(sys_gen_path.join("mod.rs"), code);
54+
}
55+
3956
pub fn generate_sys_central_file(
4057
api: &ExtensionApi,
4158
ctx: &mut Context,

godot-codegen/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::generator::utility_functions::generate_utilities_file;
2727
use crate::generator::{
2828
generate_core_central_file, generate_core_mod_file, generate_sys_builtin_lifecycle_file,
2929
generate_sys_builtin_methods_file, generate_sys_central_file, generate_sys_classes_file,
30-
generate_sys_utilities_file,
30+
generate_sys_module_file, generate_sys_utilities_file,
3131
};
3232
use crate::models::domain::{ApiView, ExtensionApi};
3333
use crate::models::json::{load_extension_api, JsonExtensionApi};
@@ -90,6 +90,9 @@ pub fn generate_sys_files(
9090
let is_godot_4_0 = api.godot_version.major == 4 && api.godot_version.minor == 0;
9191
generate_sys_interface_file(h_path, sys_gen_path, is_godot_4_0, &mut submit_fn);
9292
watch.record("generate_interface_file");
93+
94+
generate_sys_module_file(sys_gen_path, &mut submit_fn);
95+
watch.record("generate_module_file");
9396
}
9497

9598
pub fn generate_core_files(core_gen_path: &Path) {

godot-core/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
use std::path::Path;
99

1010
fn main() {
11-
// It would be better to generate this in /.generated or /target/godot-gen, however IDEs currently
12-
// struggle with static analysis when symbols are outside the crate directory (April 2023).
13-
let gen_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen"));
11+
let out_dir = std::env::var("OUT_DIR").unwrap();
12+
let gen_path = Path::new(&out_dir);
1413

1514
godot_bindings::remove_dir_all_reliable(gen_path);
1615

godot-core/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ pub mod engine;
4848
#[allow(clippy::wrong_self_convention)] // to_string() is const
4949
#[allow(clippy::upper_case_acronyms)] // TODO remove this line once we transform names
5050
#[allow(unreachable_code, clippy::unimplemented)] // TODO remove once #153 is implemented
51-
mod gen;
52-
53-
51+
mod gen {
52+
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
53+
}
5454

5555
macro_rules! generate_gdextension_api_version {
5656
(

godot-ffi/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ use std::path::Path;
1212
fn main() {
1313
let mut watch = godot_bindings::StopWatch::start();
1414

15-
// It would be better to generate this in /.generated or /target/godot-gen, however IDEs currently
16-
// struggle with static analysis when symbols are outside the crate directory (April 2023).
17-
let gen_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen"));
15+
let out_dir = std::env::var("OUT_DIR").unwrap();
16+
let gen_path = Path::new(&out_dir);
1817

1918
// C header is not strictly required, however it is generated for debugging.
2019
let h_path = gen_path.join("gdextension_interface.h");

godot-ffi/src/compat/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
use crate as sys;
99

10+
#[cfg(since_api = "4.1")]
11+
mod compat_4_1plus;
12+
#[cfg(since_api = "4.1")]
13+
pub use compat_4_1plus::*;
14+
15+
#[cfg(before_api = "4.1")]
16+
mod compat_4_0;
17+
#[cfg(before_api = "4.1")]
18+
pub use compat_4_0::*;
19+
1020
/// Dispatch at runtime between Godot 4.0 legacy and 4.1+ APIs.
1121
///
1222
/// Provides a compatibility layer to be able to use 4.0.x extensions under Godot versions >= 4.1.

0 commit comments

Comments
 (0)