Change Rust generated file defaults (#7101)
authorCasper <casperneo@uchicago.edu>
Tue, 15 Feb 2022 16:48:42 +0000 (11:48 -0500)
committerGitHub <noreply@github.com>
Tue, 15 Feb 2022 16:48:42 +0000 (11:48 -0500)
* Change Rust generated file defaults

After #6731, flatc changed its default behavior
for generating rust code to fix some importing issues.
This was a breaking change which invlidated the patch release,
`flatc 2.0.5` (#7081). This PR reverses the default so we can
release a patch update. However, does break Rust users who work at
HEAD.

* Bump flatc patch version (2.0.6)

Co-authored-by: Casper Neo <cneo@google.com>
26 files changed:
CMake/Version.cmake
include/flatbuffers/base.h
include/flatbuffers/idl.h
scripts/generate_code.py
src/flatc.cpp
src/idl_gen_rust.cpp
tests/MyGame/Example/Ability.lua
tests/MyGame/Example/Any.lua
tests/MyGame/Example/AnyAmbiguousAliases.lua
tests/MyGame/Example/AnyUniqueAliases.lua
tests/MyGame/Example/Color.lua
tests/MyGame/Example/Monster.lua
tests/MyGame/Example/Race.lua
tests/MyGame/Example/Referrable.lua
tests/MyGame/Example/Stat.lua
tests/MyGame/Example/StructOfStructs.lua
tests/MyGame/Example/Test.lua
tests/MyGame/Example/TestSimpleTableWithEnum.lua
tests/MyGame/Example/TypeAliases.lua
tests/MyGame/Example/Vec3.lua
tests/MyGame/Example2/Monster.lua
tests/MyGame/InParentNamespace.lua
tests/MyGame/OtherNameSpace/FromInclude.lua
tests/MyGame/OtherNameSpace/TableB.lua
tests/MyGame/OtherNameSpace/Unused.lua
tests/TableA.lua

index 147de5e..4825d18 100644 (file)
@@ -1,6 +1,6 @@
 set(VERSION_MAJOR 2)
 set(VERSION_MINOR 0)
-set(VERSION_PATCH 5)
+set(VERSION_PATCH 6)
 set(VERSION_COMMIT 0)
 
 find_program(GIT git)
index a5ac10d..458ac3f 100644 (file)
 
 #define FLATBUFFERS_VERSION_MAJOR 2
 #define FLATBUFFERS_VERSION_MINOR 0
-#define FLATBUFFERS_VERSION_REVISION 5
+#define FLATBUFFERS_VERSION_REVISION 6
 #define FLATBUFFERS_STRING_EXPAND(X) #X
 #define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
 namespace flatbuffers {
index 0b11ba4..7b04d0b 100644 (file)
@@ -633,6 +633,9 @@ struct IDLOptions {
   // If set, implement serde::Serialize for generated Rust types
   bool rust_serialize;
 
+  // If set, generate rust types in individual files with a root module file.
+  bool rust_module_root_file;
+
   // The corresponding language bit will be set if a language is included
   // for code generation.
   unsigned long lang_to_generate;
@@ -698,6 +701,7 @@ struct IDLOptions {
         mini_reflect(IDLOptions::kNone),
         require_explicit_ids(false),
         rust_serialize(false),
+        rust_module_root_file(false),
         lang_to_generate(0),
         set_empty_strings_to_null(true),
         set_empty_vectors_to_null(true) {}
index 48d317e..9871c0d 100755 (executable)
@@ -125,12 +125,13 @@ CPP_17_OPTS = NO_INCL_OPTS + [
     "--cpp-static-reflection",
     "--gen-object-api",
 ]
-RUST_OPTS = BASE_OPTS + ["--rust", "--gen-all", "--gen-name-strings"]
+RUST_OPTS = BASE_OPTS + ["--rust", "--gen-all", "--gen-name-strings", "--rust-module-root-file"]
 RUST_SERIALIZE_OPTS = BASE_OPTS + [
     "--rust",
     "--gen-all",
     "--gen-name-strings",
     "--rust-serialize",
+    "--rust-module-root-file",
 ]
 TS_OPTS = ["--ts", "--gen-name-strings"]
 LOBSTER_OPTS = ["--lobster"]
@@ -449,4 +450,4 @@ if not args.skip_gen_reflection:
                    "reflection_generated.h")
 
 # Python Reflection
-flatc_reflection(["-p"], "python/flatbuffers", "reflection")
\ No newline at end of file
+flatc_reflection(["-p"], "python/flatbuffers", "reflection")
index 8d6ba96..d6924f7 100644 (file)
@@ -185,6 +185,8 @@ const static FlatCOption options[] = {
   { "", "reflect-names", "", "Add minimal type/name reflection." },
   { "", "rust-serialize", "",
     "Implement serde::Serialize on generated Rust types." },
+  {"", "rust-module-root-file", "",
+   "Generate rust code in individual files with a module root file."},
   { "", "root-type", "T", "Select or override the default root_type." },
   { "", "require-explicit-ids", "",
     "When parsing schemas, require explicit ids (id: x)." },
@@ -503,6 +505,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
         opts.mini_reflect = IDLOptions::kTypesAndNames;
       } else if (arg == "--rust-serialize") {
         opts.rust_serialize = true;
+      } else if (arg == "--rust-module-root-file") {
+        opts.rust_module_root_file = true;
       } else if (arg == "--require-explicit-ids") {
         opts.require_explicit_ids = true;
       } else if (arg == "--root-type") {
index 75adaca..a00a07d 100644 (file)
@@ -194,7 +194,7 @@ bool IsOptionalToBuilder(const FieldDef &field) {
 
 bool GenerateRustModuleRootFile(const Parser &parser,
                                 const std::string &output_dir) {
-  if (parser.opts.one_file) {
+  if (!parser.opts.rust_module_root_file) {
     // Don't generate a root file when generating one file. This isn't an error
     // so return true.
     return true;
@@ -371,7 +371,7 @@ class RustGenerator : public BaseGenerator {
   }
 
   bool generate() {
-    if (parser_.opts.one_file) {
+    if (!parser_.opts.rust_module_root_file) {
       return GenerateOneFile();
     } else {
       return GenerateIndividualFiles();
index 0555a6a..870ff81 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 58c8450..769a224 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 4dbd30b..c0d3407 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 7ca7ed7..0042b93 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 6289568..1909a1b 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index b8a040d..0f73dbc 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 00798b6..f241870 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 9f2d3bc..3bd6b0a 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 08ba1cd..f621fd0 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 4374412..7f56b34 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index a1041e5..63b566c 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 061b4f4..000e6e1 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 0511923..111ae3e 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index d4bb112..ef51051 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index a30cbbf..9c33904 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 1e39a01..8112c25 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //monster_test.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 95c378e..2c2bf0a 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //include_test/sub/include_test2.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index 3bb6a7e..bfa8b03 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //include_test/sub/include_test2.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index ea04cdb..2769625 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //include_test/sub/include_test2.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)
index e3114db..90b9c95 100644 (file)
@@ -3,7 +3,7 @@
   Automatically generated by the FlatBuffers compiler, do not modify.
   Or modify. I'm a message, not a cop.
 
-  flatc version: 2.0.5
+  flatc version: 2.0.6
 
   Declared by  : //include_test/include_test1.fbs
   Rooting type : MyGame.Example.Monster (//monster_test.fbs)