@@ -12,10 +12,7 @@ use std::path::{Path, PathBuf};
1212use std:: process:: { Command , Output } ;
1313use std:: sync:: Once ;
1414
15- use regex:: Regex ;
16-
1715use crate :: godot_version:: { parse_godot_version, validate_godot_version} ;
18- use crate :: header_gen:: generate_rust_binding;
1916use crate :: watch:: StopWatch ;
2017use crate :: { GodotVersion , env_var_or_deprecated} ;
2118
@@ -51,41 +48,6 @@ pub fn load_gdextension_json(watch: &mut StopWatch) -> String {
5148 result
5249}
5350
54- pub fn write_gdextension_headers (
55- inout_h_path : & Path ,
56- out_rs_path : & Path ,
57- is_h_provided : bool ,
58- watch : & mut StopWatch ,
59- ) {
60- // Use Godot binary to dump GDExtension headers if they weren't provided by the user.
61- if !is_h_provided {
62- // No external C header file: Godot binary is present, we use it to dump C header
63- let godot_bin = locate_godot_binary ( ) ;
64- rerun_on_changed ( & godot_bin) ;
65- watch. record ( "locate_godot" ) ;
66-
67- // Regenerate API JSON if first time or Godot version is different.
68- // Note: read_godot_version() already panics if 4.0 is still in use; no need to check again.
69- // This also validates whether we run a Debug build.
70- let _version = read_godot_version ( & godot_bin) ;
71-
72- // if !c_header_path.exists() || has_version_changed(&version) {
73- dump_header_file ( & godot_bin, inout_h_path) ;
74- // update_version_file(&version);
75- watch. record ( "dump_header_h" ) ;
76- // }
77- } ;
78-
79- // Listening to changes on files that are generated by this build step cause an infinite loop with cargo watch of
80- // build -> detect change -> rebuild -> detect change -> ...
81- // rerun_on_changed(inout_h_path);
82- patch_c_header ( inout_h_path, inout_h_path) ;
83- watch. record ( "patch_header_h" ) ;
84-
85- generate_rust_binding ( inout_h_path, out_rs_path) ;
86- watch. record ( "generate_header_rs" ) ;
87- }
88-
8951/*
9052fn has_version_changed(current_version: &str) -> bool {
9153 let version_path = Path::new(GODOT_VERSION_PATH);
@@ -161,67 +123,6 @@ fn dump_extension_api(godot_bin: &Path, out_file: &Path) {
161123 println ! ( "Generated {}/extension_api.json." , cwd. display( ) ) ;
162124}
163125
164- fn dump_header_file ( godot_bin : & Path , out_file : & Path ) {
165- let cwd = out_file. parent ( ) . unwrap ( ) ;
166- fs:: create_dir_all ( cwd) . unwrap_or_else ( |_| panic ! ( "create directory '{}'" , cwd. display( ) ) ) ;
167- println ! ( "Dump GDExtension header file to dir '{}'..." , cwd. display( ) ) ;
168-
169- let mut cmd = Command :: new ( godot_bin) ;
170- cmd. current_dir ( cwd)
171- . arg ( "--headless" )
172- . arg ( "--dump-gdextension-interface" ) ;
173-
174- execute ( cmd, "dump Godot header file" ) ;
175- println ! ( "Generated {}/gdextension_interface.h." , cwd. display( ) ) ;
176- }
177-
178- pub ( crate ) fn patch_c_header ( in_h_path : & Path , out_h_path : & Path ) {
179- // The C header path *must* be passed in by the invoking crate, as the path cannot be relative to this crate.
180- // Otherwise, it can be something like `/home/runner/.cargo/git/checkouts/gdext-76630c89719e160c/efd3b94/godot-bindings`.
181-
182- println ! ( "Patch C header '{}'..." , in_h_path. display( ) ) ;
183-
184- let mut c = fs:: read_to_string ( in_h_path)
185- . unwrap_or_else ( |_| panic ! ( "failed to read C header file {}" , in_h_path. display( ) ) ) ;
186-
187- // Detect whether header is legacy (4.0) format. This should generally already be checked outside.
188- assert ! (
189- c. contains( "GDExtensionInterfaceGetProcAddress" ) ,
190- "C header file '{}' seems to be GDExtension version 4.0, which is no longer support by godot-rust." ,
191- in_h_path. display( )
192- ) ;
193-
194- // Patch for variant converters and type constructors.
195- c = c. replace (
196- "typedef void (*GDExtensionVariantFromTypeConstructorFunc)(GDExtensionVariantPtr, GDExtensionTypePtr);" ,
197- "typedef void (*GDExtensionVariantFromTypeConstructorFunc)(GDExtensionUninitializedVariantPtr, GDExtensionTypePtr);"
198- )
199- . replace (
200- "typedef void (*GDExtensionTypeFromVariantConstructorFunc)(GDExtensionTypePtr, GDExtensionVariantPtr);" ,
201- "typedef void (*GDExtensionTypeFromVariantConstructorFunc)(GDExtensionUninitializedTypePtr, GDExtensionVariantPtr);"
202- )
203- . replace (
204- "typedef void (*GDExtensionPtrConstructor)(GDExtensionTypePtr p_base, const GDExtensionConstTypePtr *p_args);" ,
205- "typedef void (*GDExtensionPtrConstructor)(GDExtensionUninitializedTypePtr p_base, const GDExtensionConstTypePtr *p_args);"
206- ) ;
207-
208- // Use single regex with independent "const"/"Const", as there are definitions like this:
209- // typedef const void *GDExtensionMethodBindPtr;
210- let c = Regex :: new ( r"typedef (const )?void \*GDExtension(Const)?([a-zA-Z0-9]+?)Ptr;" ) //
211- . expect ( "regex for mut typedef" )
212- . replace_all ( & c, "typedef ${1}struct __Gdext$3 *GDExtension${2}${3}Ptr;" ) ;
213-
214- // println!("Patched contents:\n\n{}\n\n", c.as_ref());
215-
216- // Write the modified contents back to the file
217- fs:: write ( out_h_path, c. as_ref ( ) ) . unwrap_or_else ( |_| {
218- panic ! (
219- "failed to write patched C header file {}" ,
220- out_h_path. display( )
221- )
222- } ) ;
223- }
224-
225126pub ( crate ) fn locate_godot_binary ( ) -> PathBuf {
226127 static WARN_ONCE : Once = Once :: new ( ) ;
227128 let env_var = env_var_or_deprecated ( & WARN_ONCE , "GDRUST_GODOT_BIN" , "GODOT4_BIN" ) ;
0 commit comments