Skip to content

Commit 9afa98d

Browse files
authored
Merge pull request #687 from godot-rust/feature/output-dir
Migrate crate-local `/gen` directories to `OUT_DIR`
2 parents 688ac92 + 977f925 commit 9afa98d

File tree

15 files changed

+89
-183
lines changed

15 files changed

+89
-183
lines changed

.github/composite/godot-itest/action.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,34 +162,6 @@ runs:
162162
fi
163163
shell: bash
164164

165-
# This step no longer fails if there's a diff, as we expect header to be forward-compatible; instead issues a warning
166-
# However, still fails if patch cannot be applied (conflict).
167-
# Step is only run in latest, not for compat 4.0.1 etc. -> no need to take into account different header versions.
168-
- name: "Copy and compare GDExtension header"
169-
if: inputs.godot-check-header == 'true'
170-
run: |
171-
mv godot-ffi/src/gen/gdextension_interface.h godot-ffi/src/gen/gdextension_interface_prebuilt.h
172-
mv $RUNNER_DIR/godot_bin/gdextension_interface.h godot-ffi/src/gen/gdextension_interface.h
173-
git apply godot-bindings/res/tweak.patch
174-
cd godot-ffi/src/gen
175-
git diff --no-index --exit-code --quiet gdextension_interface_prebuilt.h gdextension_interface.h || {
176-
echo "OUTCOME=header-diff" >> $GITHUB_ENV
177-
echo "::warning::gdextension_interface.h is not up-to-date."
178-
echo ""
179-
180-
echo "### :warning: Outdated GDExtension API header" >> $GITHUB_STEP_SUMMARY
181-
echo "gdextension_interface.h contains the following differences:" >> $GITHUB_STEP_SUMMARY
182-
echo "\`\`\`diff" >> $GITHUB_STEP_SUMMARY
183-
git diff --no-index gdextension_interface_prebuilt.h gdextension_interface.h >> $GITHUB_STEP_SUMMARY || true
184-
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
185-
echo "After manually updating file, run: \`git diff -R > tweak2.patch && mv tweak2.patch tweak.patch\`." >> $GITHUB_STEP_SUMMARY
186-
187-
# Undo modifications
188-
mv gdextension_interface_prebuilt.h gdextension_interface.h
189-
#exit 1
190-
}
191-
shell: bash
192-
193165
- name: "Run Godot integration tests"
194166
# Aborts immediately if Godot outputs certain keywords (would otherwise stall until CI runner times out).
195167
# Explanation:

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/res/tweak.patch

Lines changed: 0 additions & 108 deletions
This file was deleted.

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
(

0 commit comments

Comments
 (0)