mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 01:00:01 +00:00
Rework how Rust generated files are laid out (#6731)
* Refactored Rust Generated code into a module directory. Each symbol will be generated into one file and then imported into a module. This breaks the "out_dir" pattern where some users would generate code in their target/ directory. Also, these objects are best used in their own module. It will be hard for users to share their own module structure with flatbuffers namespaces. There may be solutions to these drawbacks but that should be discussed. I don't want to overengineer here. * shadow error * try fix .bat file * fix .bat 2 * Restore accidentally deleted files * Fixed some DONOTSUBMITs and made Rust outdir pattern use symlinks. * fixed binary files * git clang format * make generated onefiles not public and fix .bat * reduced diff with master in generate_code.sh * fix shadowed variable * add object api flags to .bat * space * Removed extern crate and extra & * use statement * more clippy lints * format * Undo extern crate -> use change, it actually matters to our tests Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -2,11 +2,11 @@ fn main() {
|
||||
use std::process::Command;
|
||||
let project_root = std::env::current_dir()
|
||||
.unwrap()
|
||||
.parent() // flatbuffers/tests/rust_usage test
|
||||
.parent() // flatbuffers/tests/rust_usage test
|
||||
.unwrap()
|
||||
.parent() // flatbuffers/tests
|
||||
.parent() // flatbuffers/tests
|
||||
.unwrap()
|
||||
.parent() // flatbuffers/
|
||||
.parent() // flatbuffers/
|
||||
.unwrap()
|
||||
.to_path_buf();
|
||||
let sample_schema = {
|
||||
@@ -22,17 +22,35 @@ fn main() {
|
||||
f
|
||||
};
|
||||
|
||||
let out_dir = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf();
|
||||
let out_dir = {
|
||||
let mut d = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf();
|
||||
d.push("flatbuffers");
|
||||
d
|
||||
};
|
||||
|
||||
Command::new(&flatc)
|
||||
.arg("-o")
|
||||
.arg(&out_dir)
|
||||
.arg("--rust")
|
||||
.arg(&sample_schema)
|
||||
.arg("--filename-suffix")
|
||||
.arg("_gen")
|
||||
.output()
|
||||
.expect("Failed to generate file");
|
||||
|
||||
let genfile = "monster_gen.rs";
|
||||
std::fs::rename(&genfile, out_dir.join("monster_generated.rs"))
|
||||
.expect("Could not rename monster_ge.rs to monster_generated.rs");
|
||||
assert!(out_dir.exists());
|
||||
|
||||
let generated = std::path::Path::new("src/generated");
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
if generated.exists() {
|
||||
std::fs::remove_dir(generated).unwrap();
|
||||
}
|
||||
std::os::windows::fs::symlink_dir(out_dir, generated).unwrap();
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
if generated.exists() {
|
||||
std::fs::remove_file(generated).unwrap();
|
||||
}
|
||||
std::os::unix::fs::symlink(out_dir, generated).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user