-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile flatbuffers for Rust in build.rs #1202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use std::env; | ||
use std::process::Command; | ||
use std::{env, fs}; | ||
|
||
fn main() { | ||
if env::var("DOCS_RS").is_ok() { | ||
|
@@ -16,6 +16,35 @@ fn main() { | |
}; | ||
|
||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
|
||
// Compile Rust flatbuffers | ||
let flatbuffers_declarations = planus_translation::translate_files( | ||
&fs::read_dir("fbs") | ||
.expect("Failed to read `fbs` directory") | ||
.filter_map(|maybe_entry| { | ||
maybe_entry | ||
.map(|entry| { | ||
let path = entry.path(); | ||
if path.extension() == Some("fbs".as_ref()) { | ||
Some(path) | ||
} else { | ||
None | ||
} | ||
}) | ||
.transpose() | ||
}) | ||
jmillan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.collect::<Result<Vec<_>, _>>() | ||
.expect("Failed to collect flatbuffers files"), | ||
) | ||
.expect("Failed to translate flatbuffers files"); | ||
|
||
fs::write( | ||
format!("{out_dir}/fbs.rs"), | ||
planus_codegen::generate_rust(&flatbuffers_declarations) | ||
.expect("Failed to generate Rust code from flatbuffers"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's all? No need to tricks in generated fbs.ts file to make clippy happy and so on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also a bit surprised given the fact that we do literal I'm not sure why that happens and lazy to search, but it works out for well for us here 🙂 |
||
) | ||
.expect("Failed to write generated Rust flatbuffers into fbs.rs"); | ||
|
||
// Force forward slashes on Windows too so that is plays well with our dumb `Makefile`. | ||
let mediasoup_out_dir = format!("{}/out", out_dir.replace('\\', "/")); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this fbs.es file is being generated on compile time, is it gitignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it doesn't exist in source tree at all, we write it into
OUT_DIR
that is specifically designed for that purpose just like the rest of stuff, seebuild.rs
.Read notes on https://doc.rust-lang.org/cargo/reference/environment-variables.html that contain
OUT_DIR
for details, there are a few of them there.