Skip to content

Commit 90db359

Browse files
committed
Update to the newest schema
1 parent 9460dfb commit 90db359

File tree

11 files changed

+127
-403
lines changed

11 files changed

+127
-403
lines changed

Cargo.lock

Lines changed: 29 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.16.1"
3+
version = "0.17.0"
44
edition = "2024"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
@@ -18,7 +18,7 @@ all = "warn"
1818
crate-type = ["cdylib"]
1919

2020
[dependencies]
21-
pyo3 = { version = "0.24.0", features = [] }
21+
pyo3 = { version = "0.25.0", features = [] }
2222
serde = "1.0.217"
2323
flatbuffers = "=25.2.10"
2424
# get-size appears to be unmaintained but it's too useful here
@@ -27,7 +27,7 @@ get-size = { git = "https://github.com/VirxEC/get-size", branch = "update", feat
2727

2828
[build-dependencies]
2929
reqwest = { version = "0.12.15", features = ["blocking", "rustls-tls"], default-features = false }
30-
zip = { version = "2.6.1", features = ["deflate"], default-features = false }
30+
zip = { version = "4.0.0", features = ["deflate"], default-features = false }
3131

3232
[profile.dev]
3333
opt-level = 2

codegen/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl EnumBindGenerator {
6464
Cow::Borrowed("use crate::{flat_err_to_py, generated::rlbot::flat};"),
6565
Cow::Borrowed("use flatbuffers::root;"),
6666
Cow::Borrowed(
67-
"use pyo3::{exceptions::PyValueError, pyclass, pymethods, types::PyBytes, Bound, PyResult, Python};",
67+
"use pyo3::{Bound, PyResult, Python, exceptions::PyValueError, pyclass, pymethods, types::PyBytes};",
6868
),
6969
Cow::Borrowed(""),
7070
];

codegen/main.rs

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ use std::{borrow::Cow, env::set_current_dir, fs, io, path::Path, process::Comman
1212
use structs::StructBindGenerator;
1313
use zip::ZipArchive;
1414

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+
1717
const SCHEMA_FOLDER: &str = "./flatbuffers-schema";
1818
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+
};
1925

20-
const FLATC_DOWNLOAD_URL: &str = "https://github.com/google/flatbuffers/releases/download/v25.2.10/";
21-
26+
const OUT_FOLDER: &str = "./src/generated";
2227
pub const PYTHON_OUT_FOLDER: &str = "./src/python";
2328

2429
pub enum PythonBindType {
@@ -29,15 +34,14 @@ pub enum PythonBindType {
2934

3035
impl PythonBindType {
3136
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",
3342
"GoalInfo",
3443
"BoostPad",
3544
"FieldInfo",
36-
"ControllableInfo",
37-
"ControllableTeamInfo",
38-
"PlayerClass",
39-
];
40-
pub const NO_SET_TYPES: [&'static str; 16] = [
4145
"Physics",
4246
"GamePacket",
4347
"PlayerInfo",
@@ -52,10 +56,21 @@ impl PythonBindType {
5256
"MatchInfo",
5357
"TeamInfo",
5458
"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",
5773
];
58-
pub const UNIONS: [&'static str; 4] = ["PlayerClass", "CollisionShape", "RelativeAnchor", "RenderType"];
5974

6075
pub const OPTIONAL_UNIONS: [&'static str; 1] = ["RelativeAnchor"];
6176
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<()> {
176191
Ok(())
177192
}
178193

179-
fn run_flatc() -> io::Result<()> {
194+
fn run_flatc() {
180195
println!("cargo:rerun-if-changed=flatbuffers-schema/comms.fbs");
181196
println!("cargo:rerun-if-changed=flatbuffers-schema/gamedata.fbs");
182197
println!("cargo:rerun-if-changed=flatbuffers-schema/gamestatemanip.fbs");
183198
println!("cargo:rerun-if-changed=flatbuffers-schema/matchconfig.fbs");
184199
println!("cargo:rerun-if-changed=flatbuffers-schema/rendering.fbs");
185200
println!("cargo:rerun-if-changed=flatbuffers-schema/rlbot.fbs");
186201

187-
set_current_dir(env!("CARGO_MANIFEST_DIR"))?;
202+
set_current_dir(env!("CARGO_MANIFEST_DIR")).unwrap();
188203

189204
let mut schema_folder = Path::new(SCHEMA_FOLDER);
190205
if !schema_folder.exists() {
@@ -197,51 +212,58 @@ fn run_flatc() -> io::Result<()> {
197212
let flatc_path = Path::new(&flatc_str);
198213

199214
if !flatc_path.exists() {
215+
fs::create_dir_all(flatc_path).unwrap();
216+
200217
// if the flatc binary isn't found, download it
201218
let file_name = if cfg!(windows) {
202219
"Windows.flatc.binary.zip"
203220
} else {
204221
"Linux.flatc.binary.g++-13.zip"
205222
};
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();
214236

215237
// 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();
218240

219241
assert!(flatc_path.exists(), "Failed to download flatc binary");
220242
}
221243

222244
let mut proc = Command::new(flatc_str);
223245

224246
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(),
234256
])
235-
.spawn()?
236-
.wait()?;
237-
238-
assert!(proc.status()?.success(), "flatc failed to run");
257+
.spawn()
258+
.unwrap()
259+
.wait()
260+
.unwrap();
239261

240-
Ok(())
262+
assert!(proc.status().unwrap().success(), "flatc failed to run");
241263
}
242264

243-
fn main() -> io::Result<()> {
244-
run_flatc()?;
265+
fn main() {
266+
run_flatc();
245267

246268
let out_folder = Path::new(OUT_FOLDER).join("rlbot").join("flat");
247269

@@ -252,9 +274,11 @@ fn main() -> io::Result<()> {
252274
);
253275

254276
// 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()
256279
.map(|res| res.map(|e| e.path()))
257-
.collect::<Result<Vec<_>, io::Error>>()?;
280+
.collect::<Result<Vec<_>, io::Error>>()
281+
.unwrap();
258282

259283
let mut type_data = Vec::new();
260284

@@ -263,13 +287,11 @@ fn main() -> io::Result<()> {
263287
continue;
264288
};
265289

266-
bind_generator.generate(&path)?;
290+
bind_generator.generate(&path).unwrap();
267291
type_data.push(bind_generator);
268292
}
269293

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();
275297
}

codegen/pyi.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,6 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
309309
write_str!(file, " Serializes this instance into a byte array");
310310
write_str!(file, " \"\"\"");
311311

312-
if !bind.is_frozen {
313-
write_str!(file, " def unpack_with(self, data: bytes) -> None:");
314-
write_str!(file, " \"\"\"");
315-
write_str!(file, " Deserializes the data into this instance\n");
316-
write_str!(
317-
file,
318-
" :raises InvalidFlatbuffer: If the `data` is invalid for this type"
319-
);
320-
write_str!(file, " \"\"\"");
321-
}
322-
323312
write_str!(file, " @staticmethod");
324313
write_fmt!(file, " def unpack(data: bytes) -> {type_name}:");
325314
write_str!(file, " \"\"\"");

0 commit comments

Comments
 (0)