@@ -17,12 +17,8 @@ use std::process::{Command, Output};
17
17
18
18
// Note: CARGO_BUILD_TARGET_DIR and CARGO_TARGET_DIR are not set.
19
19
// OUT_DIR would be standing to reason, but it's an unspecified path that cannot be referenced by CI.
20
- const GODOT_VERSION_PATH : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/src/gen/godot_version.txt" ) ;
20
+ // const GODOT_VERSION_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen/godot_version.txt");
21
21
const JSON_PATH : & str = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/src/gen/extension_api.json" ) ;
22
- const HEADER_PATH : & str = concat ! (
23
- env!( "CARGO_MANIFEST_DIR" ) ,
24
- "/src/gen/gdextension_interface.h"
25
- ) ;
26
22
27
23
pub fn load_gdextension_json ( watch : & mut StopWatch ) -> String {
28
24
let json_path = Path :: new ( JSON_PATH ) ;
@@ -33,57 +29,52 @@ pub fn load_gdextension_json(watch: &mut StopWatch) -> String {
33
29
watch. record ( "locate_godot" ) ;
34
30
35
31
// Regenerate API JSON if first time or Godot version is different
36
- let version = read_godot_version ( & godot_bin) ;
32
+ let _version = read_godot_version ( & godot_bin) ;
37
33
// if !json_path.exists() || has_version_changed(&version) {
38
34
dump_extension_api ( & godot_bin, json_path) ;
39
- update_version_file ( & version) ;
35
+ // update_version_file(&version);
40
36
41
- watch. record ( "dump_json " ) ;
37
+ watch. record ( "dump_api_json " ) ;
42
38
// }
43
39
44
40
let result = fs:: read_to_string ( json_path)
45
41
. unwrap_or_else ( |_| panic ! ( "failed to open file {}" , json_path. display( ) ) ) ;
46
42
47
- watch. record ( "read_json_file " ) ;
43
+ watch. record ( "read_api_json " ) ;
48
44
result
49
45
}
50
46
51
- pub fn load_gdextension_header_rs (
52
- c_in_path : Option < & Path > ,
53
- rust_out_path : & Path ,
47
+ pub fn write_gdextension_headers (
48
+ inout_h_path : & Path ,
49
+ out_rs_path : & Path ,
50
+ is_h_provided : bool ,
54
51
watch : & mut StopWatch ,
55
52
) {
56
- let c_header_path;
57
-
58
- if let Some ( c_in_path) = c_in_path {
59
- // External C header file provided; we don't invoke Godot
60
- c_header_path = c_in_path;
61
- } else {
53
+ if !is_h_provided {
62
54
// No external C header file: Godot binary is present, we use it to dump C header
63
55
let godot_bin = locate_godot_binary ( ) ;
64
56
rerun_on_changed ( & godot_bin) ;
65
57
watch. record ( "locate_godot" ) ;
66
58
67
59
// Regenerate API JSON if first time or Godot version is different
68
- let version = read_godot_version ( & godot_bin) ;
69
- c_header_path = Path :: new ( HEADER_PATH ) ;
60
+ let _version = read_godot_version ( & godot_bin) ;
70
61
71
62
// if !c_header_path.exists() || has_version_changed(&version) {
72
- dump_header_file ( & godot_bin, c_header_path) ;
73
- update_version_file ( & version) ;
63
+ dump_header_file ( & godot_bin, inout_h_path) ;
64
+ // update_version_file(&version);
65
+ watch. record ( "dump_header_h" ) ;
74
66
// }
75
67
} ;
76
- rerun_on_changed ( c_header_path) ;
77
68
78
- watch. record ( "dump_header_c" ) ;
79
-
80
- patch_c_header ( c_header_path) ;
81
- generate_rust_binding ( c_header_path, rust_out_path) ;
69
+ rerun_on_changed ( inout_h_path) ;
70
+ patch_c_header ( inout_h_path) ;
71
+ watch. record ( "patch_header_h" ) ;
82
72
73
+ generate_rust_binding ( inout_h_path, out_rs_path) ;
83
74
watch. record ( "generate_header_rs" ) ;
84
75
}
85
76
86
- # [ allow ( dead_code ) ]
77
+ /*
87
78
fn has_version_changed(current_version: &str) -> bool {
88
79
let version_path = Path::new(GODOT_VERSION_PATH);
89
80
@@ -97,9 +88,10 @@ fn update_version_file(version: &str) {
97
88
let version_path = Path::new(GODOT_VERSION_PATH);
98
89
rerun_on_changed(version_path);
99
90
100
- std :: fs:: write ( version_path, version)
91
+ fs::write(version_path, version)
101
92
.unwrap_or_else(|_| panic!("write Godot version to file {}", version_path.display()));
102
93
}
94
+ */
103
95
104
96
fn read_godot_version ( godot_bin : & Path ) -> String {
105
97
let output = Command :: new ( godot_bin)
@@ -135,41 +127,39 @@ fn read_godot_version(godot_bin: &Path) -> String {
135
127
136
128
fn dump_extension_api ( godot_bin : & Path , out_file : & Path ) {
137
129
let cwd = out_file. parent ( ) . unwrap ( ) ;
138
- std :: fs:: create_dir_all ( cwd) . unwrap_or_else ( |_| panic ! ( "create directory '{}'" , cwd. display( ) ) ) ;
130
+ fs:: create_dir_all ( cwd) . unwrap_or_else ( |_| panic ! ( "create directory '{}'" , cwd. display( ) ) ) ;
139
131
println ! ( "Dump GDExtension API JSON to dir '{}'..." , cwd. display( ) ) ;
140
132
141
133
let mut cmd = Command :: new ( godot_bin) ;
142
134
cmd. current_dir ( cwd)
143
135
. arg ( "--headless" )
144
136
. arg ( "--dump-extension-api" ) ;
145
137
146
- execute ( cmd, "dump Godot header file" ) ;
147
-
148
- println ! ( "Generated {}/gdextension_interface.h." , cwd. display( ) ) ;
138
+ execute ( cmd, "dump Godot JSON file" ) ;
139
+ println ! ( "Generated {}/extension_api.json." , cwd. display( ) ) ;
149
140
}
150
141
151
142
fn dump_header_file ( godot_bin : & Path , out_file : & Path ) {
152
143
let cwd = out_file. parent ( ) . unwrap ( ) ;
153
- std :: fs:: create_dir_all ( cwd) . unwrap_or_else ( |_| panic ! ( "create directory '{}'" , cwd. display( ) ) ) ;
144
+ fs:: create_dir_all ( cwd) . unwrap_or_else ( |_| panic ! ( "create directory '{}'" , cwd. display( ) ) ) ;
154
145
println ! ( "Dump GDExtension header file to dir '{}'..." , cwd. display( ) ) ;
155
146
156
147
let mut cmd = Command :: new ( godot_bin) ;
157
148
cmd. current_dir ( cwd)
158
149
. arg ( "--headless" )
159
150
. arg ( "--dump-gdextension-interface" ) ;
160
151
161
- execute ( cmd, "dump Godot JSON file" ) ;
162
-
163
- println ! ( "Generated {}/extension_api.json." , cwd. display( ) ) ;
152
+ execute ( cmd, "dump Godot header file" ) ;
153
+ println ! ( "Generated {}/gdextension_interface.h." , cwd. display( ) ) ;
164
154
}
165
155
166
- fn patch_c_header ( c_header_path : & Path ) {
156
+ fn patch_c_header ( inout_h_path : & Path ) {
167
157
// The C header path *must* be passed in by the invoking crate, as the path cannot be relative to this crate.
168
158
// Otherwise, it can be something like `/home/runner/.cargo/git/checkouts/gdext-76630c89719e160c/efd3b94/godot-bindings`.
169
159
170
160
// Read the contents of the file into a string
171
- let c = fs:: read_to_string ( c_header_path )
172
- . unwrap_or_else ( |_| panic ! ( "failed to read C header file {}" , c_header_path . display( ) ) ) ;
161
+ let c = fs:: read_to_string ( inout_h_path )
162
+ . unwrap_or_else ( |_| panic ! ( "failed to read C header file {}" , inout_h_path . display( ) ) ) ;
173
163
174
164
// Use single regex with independent "const"/"Const", as there are definitions like this:
175
165
// typedef const void *GDExtensionMethodBindPtr;
@@ -180,10 +170,10 @@ fn patch_c_header(c_header_path: &Path) {
180
170
println ! ( "Patched contents:\n \n {}\n \n " , c. as_ref( ) ) ;
181
171
182
172
// Write the modified contents back to the file
183
- fs:: write ( c_header_path , c. as_ref ( ) ) . unwrap_or_else ( |_| {
173
+ fs:: write ( inout_h_path , c. as_ref ( ) ) . unwrap_or_else ( |_| {
184
174
panic ! (
185
175
"failed to write patched C header file {}" ,
186
- c_header_path . display( )
176
+ inout_h_path . display( )
187
177
)
188
178
} ) ;
189
179
}
0 commit comments