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:
Casper
2021-07-22 19:02:28 -04:00
committed by GitHub
parent c36672d803
commit 12e341e4f8
83 changed files with 8894 additions and 8034 deletions

View File

@@ -1,6 +1,6 @@
extern crate array_init;
#[allow(dead_code, unused_imports)]
#[path = "../../arrays_test_generated.rs"]
#[path = "../../arrays_test/mod.rs"]
mod arrays_test_generated;
use std::fmt::Debug;

View File

@@ -33,32 +33,28 @@ mod more_defaults_test;
mod optional_scalars_test;
#[allow(dead_code, unused_imports)]
#[path = "../../include_test/include_test1_generated.rs"]
#[path = "../../include_test1/mod.rs"]
pub mod include_test1_generated;
#[allow(dead_code, unused_imports)]
#[path = "../../include_test/sub/include_test2_generated.rs"]
#[path = "../../include_test2/mod.rs"]
pub mod include_test2_generated;
#[allow(dead_code, unused_imports)]
#[path = "../../namespace_test/namespace_test1_generated.rs"]
pub mod namespace_test1_generated;
#[path = "../../namespace_test/mod.rs"]
pub mod namespace_test_generated;
#[allow(dead_code, unused_imports)]
#[path = "../../namespace_test/namespace_test2_generated.rs"]
pub mod namespace_test2_generated;
#[allow(dead_code, unused_imports)]
#[path = "../../monster_test_generated.rs"]
#[path = "../../monster_test/mod.rs"]
mod monster_test_generated;
pub use monster_test_generated::my_game;
#[allow(dead_code, unused_imports)]
#[path = "../../optional_scalars_generated.rs"]
#[path = "../../optional_scalars/mod.rs"]
mod optional_scalars_generated;
#[allow(dead_code, unused_imports)]
#[path = "../../arrays_test_generated.rs"]
#[path = "../../arrays_test/mod.rs"]
mod arrays_test_generated;
#[rustfmt::skip] // TODO: Use standard rust formatting and remove dead code.
@@ -2026,23 +2022,17 @@ mod generated_key_comparisons {
#[cfg(test)]
mod included_schema_generated_code {
extern crate flatbuffers;
//extern crate rust_usage_test;
#[test]
#[allow(unused_imports)]
fn namespace_test_mod_is_importable() {
use super::namespace_test_generated::{
namespace_a,
namespace_a::namespace_b,
namespace_c,
};
// TODO(rw): make generated sub-namespace files importable
//#[test]
//fn namespace_test_mod_is_importable() {
// use rust_usage_test::namespace_test;
//}
//#[test]
//fn namespace_test1_mod_is_importable() {
// use rust_usage_test::namespace_test::namespace_test1_generated;
//}
//#[test]
//fn namespace_test2_mod_is_importable() {
// use rust_usage_test::namespace_test::namespace_test2_generated;
//}
}
}
#[cfg(test)]
@@ -2113,7 +2103,7 @@ mod follow_impls {
// Define a test struct to use in a few tests. This replicates the work that the code generator
// would normally do when defining a FlatBuffer struct. For reference, compare the following
// `FooStruct` code with the code generated for the `Vec3` struct in
// `../../monster_test_generated.rs`.
// `../../monster_test/mod.rs`.
use flatbuffers::EndianScalar;
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(C, packed)]

View File

@@ -1,5 +1,5 @@
#[allow(dead_code, unused_imports)]
#[path = "../../more_defaults_generated.rs"]
#[path = "../../more_defaults/mod.rs"]
mod more_defaults_generated;
use self::more_defaults_generated::*;

View File

@@ -1,5 +1,5 @@
#[allow(dead_code, unused_imports)]
#[path = "../../optional_scalars_generated.rs"]
#[path = "../../optional_scalars/mod.rs"]
mod optional_scalars_generated;
use crate::optional_scalars_generated::optional_scalars::*;