From 615616cb5549a34bdf288c04bc1b94bd7a65c396 Mon Sep 17 00:00:00 2001 From: Casper Date: Tue, 15 Feb 2022 11:48:42 -0500 Subject: [PATCH] Change Rust generated file defaults (#7101) * 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 --- CMake/Version.cmake | 2 +- include/flatbuffers/base.h | 2 +- include/flatbuffers/idl.h | 4 ++++ scripts/generate_code.py | 5 +++-- src/flatc.cpp | 4 ++++ src/idl_gen_rust.cpp | 4 ++-- tests/MyGame/Example/Ability.lua | 2 +- tests/MyGame/Example/Any.lua | 2 +- tests/MyGame/Example/AnyAmbiguousAliases.lua | 2 +- tests/MyGame/Example/AnyUniqueAliases.lua | 2 +- tests/MyGame/Example/Color.lua | 2 +- tests/MyGame/Example/Monster.lua | 2 +- tests/MyGame/Example/Race.lua | 2 +- tests/MyGame/Example/Referrable.lua | 2 +- tests/MyGame/Example/Stat.lua | 2 +- tests/MyGame/Example/StructOfStructs.lua | 2 +- tests/MyGame/Example/Test.lua | 2 +- tests/MyGame/Example/TestSimpleTableWithEnum.lua | 2 +- tests/MyGame/Example/TypeAliases.lua | 2 +- tests/MyGame/Example/Vec3.lua | 2 +- tests/MyGame/Example2/Monster.lua | 2 +- tests/MyGame/InParentNamespace.lua | 2 +- tests/MyGame/OtherNameSpace/FromInclude.lua | 2 +- tests/MyGame/OtherNameSpace/TableB.lua | 2 +- tests/MyGame/OtherNameSpace/Unused.lua | 2 +- tests/TableA.lua | 2 +- 26 files changed, 35 insertions(+), 26 deletions(-) diff --git a/CMake/Version.cmake b/CMake/Version.cmake index 147de5e3c..4825d18ba 100644 --- a/CMake/Version.cmake +++ b/CMake/Version.cmake @@ -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) diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h index a5ac10d78..458ac3f79 100644 --- a/include/flatbuffers/base.h +++ b/include/flatbuffers/base.h @@ -140,7 +140,7 @@ #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 { diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 0b11ba451..7b04d0b50 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -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) {} diff --git a/scripts/generate_code.py b/scripts/generate_code.py index 48d317e6f..9871c0dff 100755 --- a/scripts/generate_code.py +++ b/scripts/generate_code.py @@ -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") diff --git a/src/flatc.cpp b/src/flatc.cpp index 8d6ba9688..d6924f789 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -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") { diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 75adacab9..a00a07d3e 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -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(); diff --git a/tests/MyGame/Example/Ability.lua b/tests/MyGame/Example/Ability.lua index 0555a6acd..870ff81cc 100644 --- a/tests/MyGame/Example/Ability.lua +++ b/tests/MyGame/Example/Ability.lua @@ -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) diff --git a/tests/MyGame/Example/Any.lua b/tests/MyGame/Example/Any.lua index 58c8450f7..769a224d8 100644 --- a/tests/MyGame/Example/Any.lua +++ b/tests/MyGame/Example/Any.lua @@ -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) diff --git a/tests/MyGame/Example/AnyAmbiguousAliases.lua b/tests/MyGame/Example/AnyAmbiguousAliases.lua index 4dbd30b31..c0d34072d 100644 --- a/tests/MyGame/Example/AnyAmbiguousAliases.lua +++ b/tests/MyGame/Example/AnyAmbiguousAliases.lua @@ -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) diff --git a/tests/MyGame/Example/AnyUniqueAliases.lua b/tests/MyGame/Example/AnyUniqueAliases.lua index 7ca7ed7ea..0042b9357 100644 --- a/tests/MyGame/Example/AnyUniqueAliases.lua +++ b/tests/MyGame/Example/AnyUniqueAliases.lua @@ -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) diff --git a/tests/MyGame/Example/Color.lua b/tests/MyGame/Example/Color.lua index 6289568b5..1909a1b9f 100644 --- a/tests/MyGame/Example/Color.lua +++ b/tests/MyGame/Example/Color.lua @@ -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) diff --git a/tests/MyGame/Example/Monster.lua b/tests/MyGame/Example/Monster.lua index b8a040dd7..0f73dbc65 100644 --- a/tests/MyGame/Example/Monster.lua +++ b/tests/MyGame/Example/Monster.lua @@ -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) diff --git a/tests/MyGame/Example/Race.lua b/tests/MyGame/Example/Race.lua index 00798b64e..f24187097 100644 --- a/tests/MyGame/Example/Race.lua +++ b/tests/MyGame/Example/Race.lua @@ -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) diff --git a/tests/MyGame/Example/Referrable.lua b/tests/MyGame/Example/Referrable.lua index 9f2d3bc9c..3bd6b0ac8 100644 --- a/tests/MyGame/Example/Referrable.lua +++ b/tests/MyGame/Example/Referrable.lua @@ -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) diff --git a/tests/MyGame/Example/Stat.lua b/tests/MyGame/Example/Stat.lua index 08ba1cdf9..f621fd0b1 100644 --- a/tests/MyGame/Example/Stat.lua +++ b/tests/MyGame/Example/Stat.lua @@ -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) diff --git a/tests/MyGame/Example/StructOfStructs.lua b/tests/MyGame/Example/StructOfStructs.lua index 437441270..7f56b3452 100644 --- a/tests/MyGame/Example/StructOfStructs.lua +++ b/tests/MyGame/Example/StructOfStructs.lua @@ -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) diff --git a/tests/MyGame/Example/Test.lua b/tests/MyGame/Example/Test.lua index a1041e50a..63b566cfb 100644 --- a/tests/MyGame/Example/Test.lua +++ b/tests/MyGame/Example/Test.lua @@ -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) diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.lua b/tests/MyGame/Example/TestSimpleTableWithEnum.lua index 061b4f4f6..000e6e1e9 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.lua +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.lua @@ -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) diff --git a/tests/MyGame/Example/TypeAliases.lua b/tests/MyGame/Example/TypeAliases.lua index 051192324..111ae3e69 100644 --- a/tests/MyGame/Example/TypeAliases.lua +++ b/tests/MyGame/Example/TypeAliases.lua @@ -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) diff --git a/tests/MyGame/Example/Vec3.lua b/tests/MyGame/Example/Vec3.lua index d4bb11241..ef510513f 100644 --- a/tests/MyGame/Example/Vec3.lua +++ b/tests/MyGame/Example/Vec3.lua @@ -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) diff --git a/tests/MyGame/Example2/Monster.lua b/tests/MyGame/Example2/Monster.lua index a30cbbfd0..9c3390489 100644 --- a/tests/MyGame/Example2/Monster.lua +++ b/tests/MyGame/Example2/Monster.lua @@ -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) diff --git a/tests/MyGame/InParentNamespace.lua b/tests/MyGame/InParentNamespace.lua index 1e39a014c..8112c257c 100644 --- a/tests/MyGame/InParentNamespace.lua +++ b/tests/MyGame/InParentNamespace.lua @@ -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) diff --git a/tests/MyGame/OtherNameSpace/FromInclude.lua b/tests/MyGame/OtherNameSpace/FromInclude.lua index 95c378ee1..2c2bf0af9 100644 --- a/tests/MyGame/OtherNameSpace/FromInclude.lua +++ b/tests/MyGame/OtherNameSpace/FromInclude.lua @@ -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) diff --git a/tests/MyGame/OtherNameSpace/TableB.lua b/tests/MyGame/OtherNameSpace/TableB.lua index 3bb6a7e00..bfa8b0335 100644 --- a/tests/MyGame/OtherNameSpace/TableB.lua +++ b/tests/MyGame/OtherNameSpace/TableB.lua @@ -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) diff --git a/tests/MyGame/OtherNameSpace/Unused.lua b/tests/MyGame/OtherNameSpace/Unused.lua index ea04cdb31..276962591 100644 --- a/tests/MyGame/OtherNameSpace/Unused.lua +++ b/tests/MyGame/OtherNameSpace/Unused.lua @@ -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) diff --git a/tests/TableA.lua b/tests/TableA.lua index e3114db7e..90b9c9570 100644 --- a/tests/TableA.lua +++ b/tests/TableA.lua @@ -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)