@@ -12,13 +12,18 @@ use std::{borrow::Cow, env::set_current_dir, fs, io, path::Path, process::Comman
12
12
use structs:: StructBindGenerator ;
13
13
use zip:: ZipArchive ;
14
14
15
- const FLATC_BINARY : & str = if cfg ! ( windows ) { "flatc.exe" } else { "flatc" } ;
16
- const OUT_FOLDER : & str = "./src/generated" ;
15
+ const FLATC_DOWNLOAD_URL : & str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/" ;
16
+
17
17
const SCHEMA_FOLDER : & str = "./flatbuffers-schema" ;
18
18
const SCHEMA_FOLDER_BACKUP : & str = "../flatbuffers-schema" ;
19
+ const RLBOT_FBS : & str = "schema/rlbot.fbs" ;
20
+ const FLATC_BINARY : & str = if cfg ! ( windows) {
21
+ "binaries\\ flatc.exe"
22
+ } else {
23
+ "binaries/flatc"
24
+ } ;
19
25
20
- const FLATC_DOWNLOAD_URL : & str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/" ;
21
-
26
+ const OUT_FOLDER : & str = "./src/generated" ;
22
27
pub const PYTHON_OUT_FOLDER : & str = "./src/python" ;
23
28
24
29
pub enum PythonBindType {
@@ -29,15 +34,14 @@ pub enum PythonBindType {
29
34
30
35
impl PythonBindType {
31
36
pub const BASE_TYPES : [ & ' static str ; 6 ] = [ "bool" , "i32" , "u32" , "f32" , "String" , "u8" ] ;
32
- pub const FROZEN_TYPES : [ & ' static str ; 6 ] = [
37
+ pub const FROZEN_TYPES : [ & ' static str ; 26 ] = [
38
+ "ControllableInfo" ,
39
+ "ControllableTeamInfo" ,
40
+ "PredictionSlice" ,
41
+ "BallPrediction" ,
33
42
"GoalInfo" ,
34
43
"BoostPad" ,
35
44
"FieldInfo" ,
36
- "ControllableInfo" ,
37
- "ControllableTeamInfo" ,
38
- "PlayerClass" ,
39
- ] ;
40
- pub const NO_SET_TYPES : [ & ' static str ; 16 ] = [
41
45
"Physics" ,
42
46
"GamePacket" ,
43
47
"PlayerInfo" ,
@@ -52,10 +56,21 @@ impl PythonBindType {
52
56
"MatchInfo" ,
53
57
"TeamInfo" ,
54
58
"Vector2" ,
55
- "PredictionSlice" ,
56
- "BallPrediction" ,
59
+ "CoreMessage" ,
60
+ "InterfaceMessage" ,
61
+ "CorePacket" ,
62
+ "InterfacePacket" ,
63
+ "PlayerInput" ,
64
+ ] ;
65
+ pub const NO_SET_TYPES : [ & ' static str ; 1 ] = [ "PlayerClass" ] ;
66
+ pub const UNIONS : [ & ' static str ; 6 ] = [
67
+ "PlayerClass" ,
68
+ "CollisionShape" ,
69
+ "RelativeAnchor" ,
70
+ "RenderType" ,
71
+ "CoreMessage" ,
72
+ "InterfaceMessage" ,
57
73
] ;
58
- pub const UNIONS : [ & ' static str ; 4 ] = [ "PlayerClass" , "CollisionShape" , "RelativeAnchor" , "RenderType" ] ;
59
74
60
75
pub const OPTIONAL_UNIONS : [ & ' static str ; 1 ] = [ "RelativeAnchor" ] ;
61
76
pub const DEFAULT_OVERRIDES : [ ( & ' static str , & ' static str , & ' static str ) ; 1 ] = [ ( "Color" , "a" , "255" ) ] ;
@@ -176,15 +191,15 @@ fn mod_rs_generator(type_data: &[PythonBindType]) -> io::Result<()> {
176
191
Ok ( ( ) )
177
192
}
178
193
179
- fn run_flatc ( ) -> io :: Result < ( ) > {
194
+ fn run_flatc ( ) {
180
195
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/comms.fbs" ) ;
181
196
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/gamedata.fbs" ) ;
182
197
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/gamestatemanip.fbs" ) ;
183
198
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/matchconfig.fbs" ) ;
184
199
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/rendering.fbs" ) ;
185
200
println ! ( "cargo:rerun-if-changed=flatbuffers-schema/rlbot.fbs" ) ;
186
201
187
- set_current_dir ( env ! ( "CARGO_MANIFEST_DIR" ) ) ? ;
202
+ set_current_dir ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
188
203
189
204
let mut schema_folder = Path :: new ( SCHEMA_FOLDER ) ;
190
205
if !schema_folder. exists ( ) {
@@ -197,51 +212,58 @@ fn run_flatc() -> io::Result<()> {
197
212
let flatc_path = Path :: new ( & flatc_str) ;
198
213
199
214
if !flatc_path. exists ( ) {
215
+ fs:: create_dir_all ( flatc_path) . unwrap ( ) ;
216
+
200
217
// if the flatc binary isn't found, download it
201
218
let file_name = if cfg ! ( windows) {
202
219
"Windows.flatc.binary.zip"
203
220
} else {
204
221
"Linux.flatc.binary.g++-13.zip"
205
222
} ;
206
- let response = reqwest:: blocking:: get ( format ! ( "{FLATC_DOWNLOAD_URL}/{file_name}" ) ) . map_err ( |e| {
207
- eprintln ! ( "Failed to download flatc binary: {e}" ) ;
208
- io:: Error :: other ( "Failed to download flatc binary" )
209
- } ) ?;
210
- let bytes = response. bytes ( ) . map_err ( |e| {
211
- eprintln ! ( "Failed to read response stream when downloading flatc binary: {e}" ) ;
212
- io:: Error :: other ( "Failed to read response stream when downloading flatc binary" )
213
- } ) ?;
223
+ let response = reqwest:: blocking:: get ( format ! ( "{FLATC_DOWNLOAD_URL}/{file_name}" ) )
224
+ . map_err ( |e| {
225
+ eprintln ! ( "Failed to download flatc binary: {e}" ) ;
226
+ io:: Error :: other ( "Failed to download flatc binary" )
227
+ } )
228
+ . unwrap ( ) ;
229
+ let bytes = response
230
+ . bytes ( )
231
+ . map_err ( |e| {
232
+ eprintln ! ( "Failed to read response stream when downloading flatc binary: {e}" ) ;
233
+ io:: Error :: other ( "Failed to read response stream when downloading flatc binary" )
234
+ } )
235
+ . unwrap ( ) ;
214
236
215
237
// extract zip
216
- let mut zip = ZipArchive :: new ( io:: Cursor :: new ( bytes) ) ? ;
217
- zip. extract ( schema_folder) ? ;
238
+ let mut zip = ZipArchive :: new ( io:: Cursor :: new ( bytes) ) . unwrap ( ) ;
239
+ zip. extract ( schema_folder) . unwrap ( ) ;
218
240
219
241
assert ! ( flatc_path. exists( ) , "Failed to download flatc binary" ) ;
220
242
}
221
243
222
244
let mut proc = Command :: new ( flatc_str) ;
223
245
224
246
proc. args ( [
225
- "--rust" ,
226
- "--gen-object-api" ,
227
- "--gen-all" ,
228
- "--filename-suffix" ,
229
- "" ,
230
- "--rust-module-root-file" ,
231
- "-o" ,
232
- OUT_FOLDER ,
233
- & format ! ( "{schema_folder_str}/rlbot.fbs" ) ,
247
+ "--rust" . as_ref ( ) ,
248
+ "--gen-object-api" . as_ref ( ) ,
249
+ "--gen-all" . as_ref ( ) ,
250
+ "--filename-suffix" . as_ref ( ) ,
251
+ "" . as_ref ( ) ,
252
+ "--rust-module-root-file" . as_ref ( ) ,
253
+ "-o" . as_ref ( ) ,
254
+ OUT_FOLDER . as_ref ( ) ,
255
+ schema_folder . join ( RLBOT_FBS ) . as_os_str ( ) ,
234
256
] )
235
- . spawn ( ) ?
236
- . wait ( ) ? ;
237
-
238
- assert ! ( proc . status ( ) ? . success ( ) , "flatc failed to run" ) ;
257
+ . spawn ( )
258
+ . unwrap ( )
259
+ . wait ( )
260
+ . unwrap ( ) ;
239
261
240
- Ok ( ( ) )
262
+ assert ! ( proc . status ( ) . unwrap ( ) . success ( ) , "flatc failed to run" ) ;
241
263
}
242
264
243
- fn main ( ) -> io :: Result < ( ) > {
244
- run_flatc ( ) ? ;
265
+ fn main ( ) {
266
+ run_flatc ( ) ;
245
267
246
268
let out_folder = Path :: new ( OUT_FOLDER ) . join ( "rlbot" ) . join ( "flat" ) ;
247
269
@@ -252,9 +274,11 @@ fn main() -> io::Result<()> {
252
274
) ;
253
275
254
276
// read the current contents of the generated folder
255
- let generated_files = fs:: read_dir ( out_folder) ?
277
+ let generated_files = fs:: read_dir ( out_folder)
278
+ . unwrap ( )
256
279
. map ( |res| res. map ( |e| e. path ( ) ) )
257
- . collect :: < Result < Vec < _ > , io:: Error > > ( ) ?;
280
+ . collect :: < Result < Vec < _ > , io:: Error > > ( )
281
+ . unwrap ( ) ;
258
282
259
283
let mut type_data = Vec :: new ( ) ;
260
284
@@ -263,13 +287,11 @@ fn main() -> io::Result<()> {
263
287
continue ;
264
288
} ;
265
289
266
- bind_generator. generate ( & path) ? ;
290
+ bind_generator. generate ( & path) . unwrap ( ) ;
267
291
type_data. push ( bind_generator) ;
268
292
}
269
293
270
- mod_rs_generator ( & type_data) ?;
271
- pyi:: generator ( & type_data) ?;
272
- class_inject:: classes_to_lib_rs ( & type_data) ?;
273
-
274
- Ok ( ( ) )
294
+ mod_rs_generator ( & type_data) . unwrap ( ) ;
295
+ pyi:: generator ( & type_data) . unwrap ( ) ;
296
+ class_inject:: classes_to_lib_rs ( & type_data) . unwrap ( ) ;
275
297
}
0 commit comments