diff -urN a/BUILD.bazel b/BUILD.bazel --- a/BUILD.bazel 2023-05-17 17:37:21.521745059 +0000 +++ b/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,112 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") - -licenses(["notice"]) - -package( - default_visibility = ["//visibility:public"], -) - -exports_files([ - "LICENSE", - "tsconfig.json", -]) - -config_setting( - name = "platform_freebsd", - constraint_values = [ - "@platforms//os:freebsd", - ], -) - -config_setting( - name = "platform_openbsd", - constraint_values = [ - "@platforms//os:openbsd", - ], -) - -# Public flatc library to compile flatbuffer files at runtime. -cc_library( - name = "flatbuffers", - hdrs = ["//:public_headers"], - linkstatic = 1, - strip_include_prefix = "/include", - deps = ["//src:flatbuffers"], -) - -# Public C++ headers for the Flatbuffers library. -filegroup( - name = "public_headers", - srcs = [ - "include/flatbuffers/allocator.h", - "include/flatbuffers/array.h", - "include/flatbuffers/base.h", - "include/flatbuffers/bfbs_generator.h", - "include/flatbuffers/buffer.h", - "include/flatbuffers/buffer_ref.h", - "include/flatbuffers/code_generators.h", - "include/flatbuffers/default_allocator.h", - "include/flatbuffers/detached_buffer.h", - "include/flatbuffers/flatbuffer_builder.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/flex_flat_util.h", - "include/flatbuffers/flexbuffers.h", - "include/flatbuffers/grpc.h", - "include/flatbuffers/hash.h", - "include/flatbuffers/idl.h", - "include/flatbuffers/minireflect.h", - "include/flatbuffers/reflection.h", - "include/flatbuffers/reflection_generated.h", - "include/flatbuffers/registry.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/string.h", - "include/flatbuffers/struct.h", - "include/flatbuffers/table.h", - "include/flatbuffers/util.h", - "include/flatbuffers/vector.h", - "include/flatbuffers/vector_downward.h", - "include/flatbuffers/verifier.h", - ], -) - -# Public flatc compiler library. -cc_library( - name = "flatc_library", - linkstatic = 1, - deps = [ - "//src:flatc_library", - ], -) - -# Public flatc compiler. -cc_binary( - name = "flatc", - data = ["//reflection:reflection_fbs_schema"], - deps = [ - "//src:flatc", - ], -) - -filegroup( - name = "flatc_headers", - srcs = [ - "include/flatbuffers/flatc.h", - ], - visibility = ["//:__subpackages__"], -) - -# Library used by flatbuffer_cc_library rules. -cc_library( - name = "runtime_cc", - hdrs = [ - "include/flatbuffers/base.h", - "include/flatbuffers/flatbuffers.h", - "include/flatbuffers/flexbuffers.h", - "include/flatbuffers/stl_emulation.h", - "include/flatbuffers/util.h", - "include/flatbuffers/vector.h", - "include/flatbuffers/verifier.h", - ], - linkstatic = 1, - strip_include_prefix = "/include", -) diff -urN a/build_defs.bzl b/build_defs.bzl --- a/build_defs.bzl 2023-05-17 17:37:21.521745059 +0000 +++ b/build_defs.bzl 1970-01-01 00:00:00.000000000 +0000 @@ -1,255 +0,0 @@ -# Description: -# BUILD rules for generating flatbuffer files in various languages. - -""" -Rules for building C++ flatbuffers with Bazel. -""" - -load("@rules_cc//cc:defs.bzl", "cc_library") - -flatc_path = "@com_github_google_flatbuffers//:flatc" - -DEFAULT_INCLUDE_PATHS = [ - "./", - "$(GENDIR)", - "$(BINDIR)", - "$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers", -] - -DEFAULT_FLATC_ARGS = [ - "--gen-object-api", - "--gen-compare", - "--no-includes", - "--gen-mutable", - "--reflect-names", - "--cpp-ptr-type flatbuffers::unique_ptr", -] - -def flatbuffer_library_public( - name, - srcs, - outs, - language_flag, - out_prefix = "", - includes = [], - include_paths = DEFAULT_INCLUDE_PATHS, - flatc_args = DEFAULT_FLATC_ARGS, - reflection_name = "", - reflection_visibility = None, - compatible_with = None, - restricted_to = None, - target_compatible_with = None, - output_to_bindir = False): - """Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler. - - Args: - name: Rule name. - srcs: Source .fbs files. Sent in order to the compiler. - outs: Output files from flatc. - language_flag: Target language flag. One of [-c, -j, -js]. - out_prefix: Prepend this path to the front of all generated files except on - single source targets. Usually is a directory name. - includes: Optional, list of filegroups of schemas that the srcs depend on. - include_paths: Optional, list of paths the includes files can be found in. - flatc_args: Optional, list of additional arguments to pass to flatc. - reflection_name: Optional, if set this will generate the flatbuffer - reflection binaries for the schemas. - reflection_visibility: The visibility of the generated reflection Fileset. - output_to_bindir: Passed to genrule for output to bin directory. - compatible_with: Optional, The list of environments this rule can be - built for, in addition to default-supported environments. - restricted_to: Optional, The list of environments this rule can be built - for, instead of default-supported environments. - target_compatible_with: Optional, The list of target platform constraints - to use. - output_to_bindir: Passed to genrule for output to bin directory. - - - This rule creates a filegroup(name) with all generated source files, and - optionally a Fileset([reflection_name]) with all generated reflection - binaries. - """ - include_paths_cmd = ["-I %s" % (s) for s in include_paths] - - # '$(@D)' when given a single source target will give the appropriate - # directory. Appending 'out_prefix' is only necessary when given a build - # target with multiple sources. - output_directory = ( - ("-o $(@D)/%s" % (out_prefix)) if len(srcs) > 1 else ("-o $(@D)") - ) - genrule_cmd = " ".join([ - "SRCS=($(SRCS));", - "for f in $${SRCS[@]:0:%s}; do" % len(srcs), - "$(location %s)" % (flatc_path), - " ".join(include_paths_cmd), - " ".join(flatc_args), - language_flag, - output_directory, - "$$f;", - "done", - ]) - native.genrule( - name = name, - srcs = srcs + includes, - outs = outs, - output_to_bindir = output_to_bindir, - tools = [flatc_path], - cmd = genrule_cmd, - compatible_with = compatible_with, - target_compatible_with = target_compatible_with, - restricted_to = restricted_to, - message = "Generating flatbuffer files for %s:" % (name), - ) - if reflection_name: - reflection_genrule_cmd = " ".join([ - "SRCS=($(SRCS));", - "for f in $${SRCS[@]:0:%s}; do" % len(srcs), - "$(location %s)" % (flatc_path), - "-b --schema", - " ".join(flatc_args), - " ".join(include_paths_cmd), - language_flag, - output_directory, - "$$f;", - "done", - ]) - reflection_outs = [ - (out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1]) - for s in srcs - ] - native.genrule( - name = "%s_srcs" % reflection_name, - srcs = srcs + includes, - outs = reflection_outs, - output_to_bindir = output_to_bindir, - tools = [flatc_path], - compatible_with = compatible_with, - restricted_to = restricted_to, - target_compatible_with = target_compatible_with, - cmd = reflection_genrule_cmd, - message = "Generating flatbuffer reflection binary for %s:" % (name), - visibility = reflection_visibility, - ) - native.filegroup( - name = "%s_out" % reflection_name, - srcs = reflection_outs, - visibility = reflection_visibility, - compatible_with = compatible_with, - restricted_to = restricted_to, - ) - -def flatbuffer_cc_library( - name, - srcs, - srcs_filegroup_name = "", - out_prefix = "", - deps = [], - includes = [], - include_paths = DEFAULT_INCLUDE_PATHS, - cc_include_paths = [], - flatc_args = DEFAULT_FLATC_ARGS, - visibility = None, - compatible_with = None, - restricted_to = None, - target_compatible_with = None, - srcs_filegroup_visibility = None, - gen_reflections = False): - """A cc_library with the generated reader/writers for the given flatbuffer definitions. - - Args: - name: Rule name. - srcs: Source .fbs files. Sent in order to the compiler. - srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this - filegroup into the `includes` parameter of any other - flatbuffer_cc_library that depends on this one's schemas. - out_prefix: Prepend this path to the front of all generated files. Usually - is a directory name. - deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified - alongside includes. - includes: Optional, list of filegroups of schemas that the srcs depend on. - Use of this is discouraged, and may be deprecated. - include_paths: Optional, list of paths the includes files can be found in. - cc_include_paths: Optional, list of paths to add to the cc_library includes attribute. - flatc_args: Optional list of additional arguments to pass to flatc - (e.g. --gen-mutable). - visibility: The visibility of the generated cc_library. By default, use the - default visibility of the project. - srcs_filegroup_visibility: The visibility of the generated srcs filegroup. - By default, use the value of the visibility parameter above. - gen_reflections: Optional, if true this will generate the flatbuffer - reflection binaries for the schemas. - compatible_with: Optional, The list of environments this rule can be built - for, in addition to default-supported environments. - restricted_to: Optional, The list of environments this rule can be built - for, instead of default-supported environments. - target_compatible_with: Optional, The list of target platform constraints - to use. - - This produces: - filegroup([name]_srcs): all generated .h files. - filegroup(srcs_filegroup_name if specified, or [name]_includes if not): - Other flatbuffer_cc_library's can pass this in for their `includes` - parameter, if they depend on the schemas in this library. - Fileset([name]_reflection): (Optional) all generated reflection binaries. - cc_library([name]): library with sources and flatbuffers deps. - """ - output_headers = [ - (out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1]) - for s in srcs - ] - if deps and includes: - # There is no inherent reason we couldn't support both, but this discourages - # use of includes without good reason. - fail("Cannot specify both deps and include in flatbuffer_cc_library.") - if deps: - includes = [d + "_includes" for d in deps] - reflection_name = "%s_reflection" % name if gen_reflections else "" - - srcs_lib = "%s_srcs" % (name) - flatbuffer_library_public( - name = srcs_lib, - srcs = srcs, - outs = output_headers, - language_flag = "-c", - out_prefix = out_prefix, - includes = includes, - include_paths = include_paths, - flatc_args = flatc_args, - compatible_with = compatible_with, - restricted_to = restricted_to, - target_compatible_with = target_compatible_with, - reflection_name = reflection_name, - reflection_visibility = visibility, - ) - cc_library( - name = name, - hdrs = [ - ":" + srcs_lib, - ], - srcs = [ - ":" + srcs_lib, - ], - features = [ - "-parse_headers", - ], - deps = [ - "@com_github_google_flatbuffers//:runtime_cc", - "@com_github_google_flatbuffers//:flatbuffers", - ] + deps, - includes = cc_include_paths, - compatible_with = compatible_with, - restricted_to = restricted_to, - target_compatible_with = target_compatible_with, - linkstatic = 1, - visibility = visibility, - ) - - # A filegroup for the `srcs`. That is, all the schema files for this - # Flatbuffer set. - native.filegroup( - name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name), - srcs = srcs + includes, - compatible_with = compatible_with, - restricted_to = restricted_to, - visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility, - ) diff -urN a/grpc/src/compiler/BUILD.bazel b/grpc/src/compiler/BUILD.bazel --- a/grpc/src/compiler/BUILD.bazel 2023-05-17 17:37:21.529744923 +0000 +++ b/grpc/src/compiler/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,121 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -package( - default_visibility = ["//visibility:public"], -) - -filegroup( - name = "common_headers", - srcs = [ - "schema_interface.h", - ], -) - -cc_library( - name = "cpp_generator", - srcs = [ - "cpp_generator.cc", - ], - hdrs = [ - "cpp_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - "//:flatbuffers", - ], -) - -cc_library( - name = "go_generator", - srcs = [ - "go_generator.cc", - ], - hdrs = [ - "go_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - "//:flatbuffers", - ], -) - -cc_library( - name = "java_generator", - srcs = [ - "java_generator.cc", - ], - hdrs = [ - "java_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - "//:flatbuffers", - ], -) - -cc_library( - name = "python_generator", - hdrs = [ - "python_generator.h", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - ":python_generator_private", - ], -) - -cc_library( - name = "python_generator_private", - srcs = [ - "python_generator.cc", - ], - hdrs = [ - "python_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - visibility = ["//visibility:private"], - deps = [ - "//:flatbuffers", - ], -) - -cc_library( - name = "swift_generator", - srcs = [ - "swift_generator.cc", - ], - hdrs = [ - "swift_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - "//:flatbuffers", - ], -) - -cc_library( - name = "ts_generator", - srcs = [ - "ts_generator.cc", - ], - hdrs = [ - "ts_generator.h", - ":common_headers", - ], - include_prefix = "src/compiler", - strip_include_prefix = "/grpc/src/compiler", - deps = [ - "//:flatbuffers", - ], -) diff -urN a/grpc/tests/BUILD b/grpc/tests/BUILD --- a/grpc/tests/BUILD 2023-05-17 17:37:21.529744923 +0000 +++ b/grpc/tests/BUILD 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -cc_test( - name = "grpc_test", - srcs = [ - "grpctest.cpp", - "message_builder_test.cpp", - ], - copts = ["-Itests"], - # This is required. - linkstatic = 1, - deps = [ - "//tests:monster_test_cc_fbs", - "//tests:monster_test_grpc", - "//tests:test_assert", - "//tests:test_builder", - "@com_github_grpc_grpc//:grpc++", - ], -) diff -urN a/reflection/BUILD.bazel b/reflection/BUILD.bazel --- a/reflection/BUILD.bazel 2023-05-17 17:37:21.521745059 +0000 +++ b/reflection/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ -filegroup( - name = "reflection_fbs_schema", - srcs = ["reflection.fbs"], - visibility = ["//visibility:public"], -) diff -urN a/reflection/ts/BUILD.bazel b/reflection/ts/BUILD.bazel --- a/reflection/ts/BUILD.bazel 2023-05-17 17:37:21.521745059 +0000 +++ b/reflection/ts/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,16 +0,0 @@ -load("//:typescript.bzl", "flatbuffer_ts_library") - -genrule( - name = "copy_schema_to_folder", - srcs = ["//reflection:reflection_fbs_schema"], - outs = ["reflection.fbs"], - cmd = "cp $< $@", -) - -flatbuffer_ts_library( - name = "reflection_ts_fbs", - package_name = "flatbuffers_reflection", - srcs = [":reflection.fbs"], - include_reflection = False, - visibility = ["//visibility:public"], -) diff -urN a/src/BUILD.bazel b/src/BUILD.bazel --- a/src/BUILD.bazel 2023-05-17 17:37:21.549744583 +0000 +++ b/src/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,101 +0,0 @@ -# @unused -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") - -package( - default_visibility = ["//visibility:private"], -) - -# Public flatc library to compile flatbuffer files at runtime. -cc_library( - name = "flatbuffers", - srcs = [ - "code_generators.cpp", - "idl_gen_fbs.cpp", - "idl_gen_text.cpp", - "idl_parser.cpp", - "reflection.cpp", - "util.cpp", - ], - hdrs = ["//:public_headers"], - linkopts = select({ - # TODO: Bazel uses `clang` instead of `clang++` to link - # C++ code on BSD. Temporarily adding these linker flags while - # we wait for Bazel to resolve - # https://github.com/bazelbuild/bazel/issues/12023. - "//:platform_freebsd": ["-lm"], - "//:platform_openbsd": ["-lm"], - "//conditions:default": [], - }), - strip_include_prefix = "/include", - visibility = ["//:__pkg__"], -) - -# Public flatc compiler library. -cc_library( - name = "flatc_library", - srcs = [ - "annotated_binary_text_gen.cpp", - "annotated_binary_text_gen.h", - "bfbs_gen.h", - "bfbs_gen_lua.cpp", - "bfbs_gen_lua.h", - "bfbs_namer.h", - "binary_annotator.cpp", - "binary_annotator.h", - "flatc.cpp", - "namer.h", - ], - hdrs = [ - "//:flatc_headers", - ], - strip_include_prefix = "/include", - visibility = ["//:__pkg__"], - deps = [ - ":flatbuffers", - ], -) - -# Public flatc compiler. -cc_library( - name = "flatc", - srcs = [ - "bfbs_gen.h", - "bfbs_gen_lua.cpp", - "bfbs_gen_lua.h", - "bfbs_namer.h", - "flatc_main.cpp", - "idl_gen_cpp.cpp", - "idl_gen_csharp.cpp", - "idl_gen_dart.cpp", - "idl_gen_go.cpp", - "idl_gen_grpc.cpp", - "idl_gen_java.cpp", - "idl_gen_json_schema.cpp", - "idl_gen_kotlin.cpp", - "idl_gen_lobster.cpp", - "idl_gen_lua.cpp", - "idl_gen_php.cpp", - "idl_gen_python.cpp", - "idl_gen_rust.cpp", - "idl_gen_swift.cpp", - "idl_gen_text.cpp", - "idl_gen_ts.cpp", - "idl_namer.h", - "namer.h", - "util.cpp", - ], - hdrs = [ - "//:flatc_headers", - ], - strip_include_prefix = "/include", - visibility = ["//:__pkg__"], - deps = [ - ":flatc_library", - "//grpc/src/compiler:cpp_generator", - "//grpc/src/compiler:go_generator", - "//grpc/src/compiler:java_generator", - "//grpc/src/compiler:python_generator", - "//grpc/src/compiler:swift_generator", - "//grpc/src/compiler:ts_generator", - ], -) diff -urN a/swift/BUILD.bazel b/swift/BUILD.bazel --- a/swift/BUILD.bazel 2023-05-17 17:37:21.549744583 +0000 +++ b/swift/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") - -swift_library( - name = "swift", - srcs = glob(["Sources/FlatBuffers/*.swift"]), - module_name = "FlatBuffers", - visibility = ["//visibility:public"], -) diff -urN a/tests/BUILD.bazel b/tests/BUILD.bazel --- a/tests/BUILD.bazel 2023-05-17 17:37:21.553744516 +0000 +++ b/tests/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,233 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_test") -load("@rules_cc//cc:defs.bzl", "cc_test") -load("//:build_defs.bzl", "flatbuffer_cc_library") -load("//:typescript.bzl", "flatbuffer_ts_library") - -package(default_visibility = ["//visibility:private"]) - -# Test binary. -cc_test( - name = "flatbuffers_test", - testonly = 1, - srcs = [ - "evolution_test.cpp", - "evolution_test.h", - "evolution_test/evolution_v1_generated.h", - "evolution_test/evolution_v2_generated.h", - "flexbuffers_test.cpp", - "flexbuffers_test.h", - "fuzz_test.cpp", - "fuzz_test.h", - "is_quiet_nan.h", - "json_test.cpp", - "json_test.h", - "monster_test.cpp", - "monster_test.h", - "monster_test_bfbs_generated.h", - "namespace_test/namespace_test1_generated.h", - "namespace_test/namespace_test2_generated.h", - "native_inline_table_test_generated.h", - "native_type_test_impl.cpp", - "native_type_test_impl.h", - "optional_scalars_generated.h", - "optional_scalars_test.cpp", - "optional_scalars_test.h", - "parser_test.cpp", - "parser_test.h", - "proto_test.cpp", - "proto_test.h", - "reflection_test.cpp", - "reflection_test.h", - "test.cpp", - "test_assert.cpp", - "test_assert.h", - "test_builder.cpp", - "test_builder.h", - "union_vector/union_vector_generated.h", - "util_test.cpp", - "util_test.h", - ], - copts = [ - "-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE", - "-DBAZEL_TEST_DATA_PATH", - ], - data = [ - ":arrays_test.bfbs", - ":arrays_test.fbs", - ":arrays_test.golden", - ":evolution_test/evolution_v1.fbs", - ":evolution_test/evolution_v1.json", - ":evolution_test/evolution_v2.fbs", - ":evolution_test/evolution_v2.json", - ":include_test/include_test1.fbs", - ":include_test/sub/include_test2.fbs", - ":monster_extra.fbs", - ":monster_test.bfbs", - ":monster_test.fbs", - ":monsterdata_extra.json", - ":monsterdata_test.golden", - ":monsterdata_test.json", - ":name_clash_test/invalid_test1.fbs", - ":name_clash_test/invalid_test2.fbs", - ":name_clash_test/valid_test1.fbs", - ":name_clash_test/valid_test2.fbs", - ":native_type_test.fbs", - ":optional_scalars.fbs", - ":optional_scalars.json", - ":optional_scalars_defaults.json", - ":prototest/imported.proto", - ":prototest/test.golden", - ":prototest/test.proto", - ":prototest/test_include.golden", - ":prototest/test_suffix.golden", - ":prototest/test_union.golden", - ":prototest/test_union_include.golden", - ":prototest/test_union_suffix.golden", - ":unicode_test.json", - ":union_vector/union_vector.fbs", - ":union_vector/union_vector.json", - ], - includes = [ - "", - "include/", - ], - deps = [ - ":arrays_test_cc_fbs", - ":monster_extra_cc_fbs", - ":monster_test_cc_fbs", - ":native_type_test_cc_fbs", - "//:flatbuffers", - ], -) - -# Test bzl rules - -cc_library( - name = "test_assert", - srcs = ["test_assert.cpp"], - hdrs = ["test_assert.h"], - visibility = ["//grpc/tests:__subpackages__"], - deps = ["//:flatbuffers"], -) - -cc_library( - name = "test_builder", - srcs = ["test_builder.cpp"], - hdrs = ["test_builder.h"], - visibility = ["//grpc/tests:__subpackages__"], - deps = [ - ":monster_test_grpc", - ":test_assert", - "//:flatbuffers", - ], -) - -cc_library( - name = "monster_test_grpc", - srcs = [ - "monster_test.grpc.fb.cc", - "monster_test.grpc.fb.h", - "monster_test_generated.h", - ], - hdrs = [ - "monster_test.grpc.fb.h", - "monster_test_generated.h", - ], - includes = ["."], - visibility = ["//grpc/tests:__subpackages__"], - deps = [ - "//:flatbuffers", - "@com_github_grpc_grpc//:grpc++", - ], -) - -flatbuffer_cc_library( - name = "include_test_fbs", - srcs = [ - "include_test/include_test1.fbs", - "include_test/sub/include_test2.fbs", - ], - include_paths = ["tests/include_test"], -) - -flatbuffer_cc_library( - name = "monster_test_cc_fbs", - srcs = ["monster_test.fbs"], - include_paths = ["tests/include_test"], - visibility = ["//grpc/tests:__subpackages__"], - deps = [":include_test_fbs"], -) - -# Test that running without --no-includes works properly (monster_test doesn't -# work cleanly due to the circular dependency in the include_tests/ files). -include_test_args = [ - "--gen-object-api", - "--gen-compare", - "--gen-mutable", - "--reflect-names", - "--cpp-ptr-type flatbuffers::unique_ptr", - "--force-empty", -] - -flatbuffer_cc_library( - name = "included_test_fbs", - srcs = ["included_test.fbs"], - flatc_args = include_test_args, -) - -flatbuffer_cc_library( - name = "includer_test_fbs", - srcs = ["includer_test.fbs"], - flatc_args = include_test_args, - deps = [":included_test_fbs"], -) - -cc_library( - name = "include_build_test", - srcs = ["include_build_test.cc"], - deps = [":includer_test_fbs"], -) - -flatbuffer_cc_library( - name = "monster_extra_cc_fbs", - srcs = ["monster_extra.fbs"], -) - -flatbuffer_cc_library( - name = "arrays_test_cc_fbs", - srcs = ["arrays_test.fbs"], - flatc_args = [ - "--gen-object-api", - "--gen-compare", - "--no-includes", - "--gen-mutable", - "--reflect-names", - "--cpp-ptr-type flatbuffers::unique_ptr", - "--scoped-enums", - ], -) - -flatbuffer_cc_library( - name = "native_type_test_cc_fbs", - srcs = ["native_type_test.fbs"], - flatc_args = [ - "--gen-object-api", - "--gen-mutable", - "--cpp-ptr-type flatbuffers::unique_ptr", - ], -) - -flatbuffer_ts_library( - name = "typescript_ts_fbs", - srcs = ["typescript_keywords.fbs"], - deps = [ - "//tests/test_dir:include_ts_fbs", - "//tests/test_dir:typescript_transitive_ts_fbs", - ], -) - -go_test( - name = "tests_test", - srcs = ["go_test.go"], - deps = ["//go"], -) diff -urN a/tests/MyGame/BUILD.bazel b/tests/MyGame/BUILD.bazel --- a/tests/MyGame/BUILD.bazel 2023-05-17 17:37:21.557744447 +0000 +++ b/tests/MyGame/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "MyGame", - srcs = ["InParentNamespace.go"], - importpath = "github.com/google/flatbuffers/tests/MyGame", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":MyGame", - visibility = ["//visibility:public"], -) diff -urN a/tests/MyGame/Example/BUILD.bazel b/tests/MyGame/Example/BUILD.bazel --- a/tests/MyGame/Example/BUILD.bazel 2023-05-17 17:37:21.557744447 +0000 +++ b/tests/MyGame/Example/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "Example", - srcs = [ - "Ability.go", - "Any.go", - "AnyAmbiguousAliases.go", - "AnyUniqueAliases.go", - "Color.go", - "LongEnum.go", - "Monster.go", - "MonsterStorage_grpc.go", - "Race.go", - "Referrable.go", - "Stat.go", - "StructOfStructs.go", - "StructOfStructsOfStructs.go", - "Test.go", - "TestSimpleTableWithEnum.go", - "TypeAliases.go", - "Vec3.go", - ], - importpath = "github.com/google/flatbuffers/tests/MyGame/Example", - visibility = ["//visibility:public"], - deps = [ - "//go", - "@org_golang_google_grpc//:grpc", - "@org_golang_google_grpc//codes", - "@org_golang_google_grpc//status", - ], -) - -alias( - name = "go_default_library", - actual = ":Example", - visibility = ["//visibility:public"], -) diff -urN a/tests/MyGame/Example2/BUILD.bazel b/tests/MyGame/Example2/BUILD.bazel --- a/tests/MyGame/Example2/BUILD.bazel 2023-05-17 17:37:21.557744447 +0000 +++ b/tests/MyGame/Example2/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "Example2", - srcs = ["Monster.go"], - importpath = "github.com/google/flatbuffers/tests/MyGame/Example2", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":Example2", - visibility = ["//visibility:public"], -) diff -urN a/tests/namespace_test/NamespaceA/BUILD.bazel b/tests/namespace_test/NamespaceA/BUILD.bazel --- a/tests/namespace_test/NamespaceA/BUILD.bazel 2023-05-17 17:37:21.565744312 +0000 +++ b/tests/namespace_test/NamespaceA/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,19 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "NamespaceA", - srcs = [ - "SecondTableInA.go", - "TableInC.go", - "TableInFirstNS.go", - ], - importpath = "github.com/google/flatbuffers/tests/namespace_test/NamespaceA", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":NamespaceA", - visibility = ["//visibility:public"], -) diff -urN a/tests/namespace_test/NamespaceA/NamespaceB/BUILD.bazel b/tests/namespace_test/NamespaceA/NamespaceB/BUILD.bazel --- a/tests/namespace_test/NamespaceA/NamespaceB/BUILD.bazel 2023-05-17 17:37:21.565744312 +0000 +++ b/tests/namespace_test/NamespaceA/NamespaceB/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "NamespaceB", - srcs = [ - "EnumInNestedNS.go", - "StructInNestedNS.go", - "TableInNestedNS.go", - "UnionInNestedNS.go", - ], - importpath = "github.com/google/flatbuffers/tests/namespace_test/NamespaceA/NamespaceB", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":NamespaceB", - visibility = ["//visibility:public"], -) diff -urN a/tests/namespace_test/NamespaceC/BUILD.bazel b/tests/namespace_test/NamespaceC/BUILD.bazel --- a/tests/namespace_test/NamespaceC/BUILD.bazel 2023-05-17 17:37:21.565744312 +0000 +++ b/tests/namespace_test/NamespaceC/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "NamespaceC", - srcs = ["TableInC.go"], - importpath = "github.com/google/flatbuffers/tests/namespace_test/NamespaceC", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":NamespaceC", - visibility = ["//visibility:public"], -) diff -urN a/tests/optional_scalars/BUILD.bazel b/tests/optional_scalars/BUILD.bazel --- a/tests/optional_scalars/BUILD.bazel 2023-05-17 17:37:21.569744244 +0000 +++ b/tests/optional_scalars/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "optional_scalars", - srcs = [ - "OptionalByte.go", - "ScalarStuff.go", - ], - importpath = "github.com/google/flatbuffers/tests/optional_scalars", - visibility = ["//visibility:public"], - deps = ["//go"], -) - -alias( - name = "go_default_library", - actual = ":optional_scalars", - visibility = ["//visibility:public"], -) diff -urN a/tests/test_dir/BUILD.bazel b/tests/test_dir/BUILD.bazel --- a/tests/test_dir/BUILD.bazel 2023-05-17 17:37:21.569744244 +0000 +++ b/tests/test_dir/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -load("//:typescript.bzl", "flatbuffer_ts_library") - -flatbuffer_ts_library( - name = "typescript_transitive_ts_fbs", - srcs = ["typescript_transitive_include.fbs"], - visibility = ["//visibility:public"], -) - -flatbuffer_ts_library( - name = "include_ts_fbs", - srcs = ["typescript_include.fbs"], - visibility = ["//visibility:public"], - deps = [":typescript_transitive_ts_fbs"], -) diff -urN a/ts/BUILD.bazel b/ts/BUILD.bazel --- a/ts/BUILD.bazel 2023-05-17 17:37:21.573744176 +0000 +++ b/ts/BUILD.bazel 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -load("@npm//@bazel/typescript:index.bzl", "ts_project") -load("@build_bazel_rules_nodejs//:index.bzl", "js_library") - -ts_project( - name = "flatbuffers_ts", - srcs = [ - "builder.ts", - "byte-buffer.ts", - "constants.ts", - "encoding.ts", - "index.ts", - "types.ts", - "utils.ts", - ], - declaration = True, - tsconfig = { - "compilerOptions": { - "module": "commonjs", - "declaration": True, - "moduleResolution": "node", - "lib": [ - "ES2015", - "ES2020.BigInt", - "DOM", - ], - "types": ["node"], - "strict": True, - }, - }, - visibility = ["//visibility:public"], - deps = ["@npm//@types/node"], -) - -js_library( - name = "flatbuffers", - package_name = "flatbuffers", - visibility = ["//visibility:public"], - deps = [":flatbuffers_ts"], -) diff -urN a/typescript.bzl b/typescript.bzl --- a/typescript.bzl 2023-05-17 17:37:21.521745059 +0000 +++ b/typescript.bzl 1970-01-01 00:00:00.000000000 +0000 @@ -1,134 +0,0 @@ -""" -Rules for building typescript flatbuffers with Bazel. -""" - -load("@build_bazel_rules_nodejs//:index.bzl", "js_library") -load("@npm//@bazel/typescript:index.bzl", "ts_project") -load(":build_defs.bzl", "DEFAULT_INCLUDE_PATHS", "flatbuffer_library_public") - -DEFAULT_FLATC_TS_ARGS = [ - "--gen-object-api", - "--gen-mutable", - "--reflect-names", - "--gen-name-strings", - "--ts-flat-files", - "--keep-prefix", -] - -def flatbuffer_ts_library( - name, - srcs, - compatible_with = None, - target_compatible_with = None, - deps = [], - include_paths = DEFAULT_INCLUDE_PATHS, - flatc_args = DEFAULT_FLATC_TS_ARGS, - visibility = None, - restricted_to = None, - include_reflection = True, - gen_reflections = False, - package_name = None): - """Generates a ts_library rule for a given flatbuffer definition. - - Args: - name: Name of the generated ts_library rule. - srcs: Source .fbs file(s). - deps: Other flatbuffer_ts_library's to depend on. Note that currently - you must specify all your transitive dependencies manually. - include_paths: Optional, list of paths the includes files can be found in. - flatc_args: Optional list of additional arguments to pass to flatc - (e.g. --gen-mutable). - visibility: The visibility of the generated cc_library. By default, use the - default visibility of the project. - compatible_with: Optional, The list of environments this rule can be built - for, in addition to default-supported environments. - restricted_to: Optional, The list of environments this rule can be built - for, instead of default-supported environments. - target_compatible_with: Optional, The list of target platform constraints - to use. - include_reflection: Optional, Whether to depend on the flatbuffer - reflection library automatically. Only really relevant for the - target that builds the reflection library itself. - gen_reflections: Optional, if true this will generate the flatbuffer - reflection binaries for the schemas. - package_name: Optional, Package name to use for the generated code. - """ - srcs_lib = "%s_srcs" % (name) - out_base = [s.replace(".fbs", "").split("/")[-1].split(":")[-1] for s in srcs] - - # Because of how we have to manage the bazel rules for typescript, - # reflection has to get special-cased to get imported when - # run within bazel. As such, generate the code using the _pregenerate - # suffix; then do a find/replace to fix-up all the reflection imports. - pre_outs = ["%s_pregenerated.ts" % s for s in out_base] - outs = ["%s_generated.ts" % s for s in out_base] - includes = [d + "_includes" for d in deps] - reflection_name = "%s_reflection" % name if gen_reflections else "" - flatbuffer_library_public( - name = srcs_lib, - srcs = srcs, - outs = pre_outs, - language_flag = "--ts", - includes = includes, - include_paths = include_paths, - flatc_args = flatc_args + ["--filename-suffix _pregenerated"], - compatible_with = compatible_with, - restricted_to = restricted_to, - reflection_name = reflection_name, - reflection_visibility = visibility, - target_compatible_with = target_compatible_with, - ) - fix_import_cmd = " ".join([ - "SRCS=($(SRCS));", - "OUTS=($(OUTS));", - "for i in $${!SRCS[@]}; do", - "sed \"s/'.*reflection\\/reflection_pregenerated/'flatbuffers_reflection\\/reflection_generated/; s/_pregenerated/_generated/\" $${SRCS[i]} > $${OUTS[i]};", - "done", - ]) - native.genrule( - name = name + "_reimporter", - srcs = pre_outs, - outs = outs, - cmd = fix_import_cmd, - ) - ts_project( - name = name + "_ts", - srcs = outs, - declaration = True, - visibility = visibility, - compatible_with = compatible_with, - restricted_to = restricted_to, - target_compatible_with = target_compatible_with, - tsconfig = { - "compilerOptions": { - "declaration": True, - "lib": [ - "ES2015", - "ES2020.BigInt", - "DOM", - ], - "module": "commonjs", - "moduleResolution": "node", - "noUnusedLocals": True, - "strict": True, - "types": ["node"], - }, - }, - deps = deps + ["@com_github_google_flatbuffers//ts:flatbuffers"] + (["@com_github_google_flatbuffers//reflection/ts:reflection_ts_fbs"] if include_reflection else []), - ) - js_library( - name = name, - visibility = visibility, - compatible_with = compatible_with, - restricted_to = restricted_to, - target_compatible_with = target_compatible_with, - deps = [name + "_ts"], - package_name = package_name, - ) - native.filegroup( - name = "%s_includes" % (name), - srcs = srcs + includes, - compatible_with = compatible_with, - restricted_to = restricted_to, - visibility = visibility, - ) diff -urN a/WORKSPACE b/WORKSPACE --- a/WORKSPACE 2023-05-17 17:37:21.521745059 +0000 +++ b/WORKSPACE 1970-01-01 00:00:00.000000000 +0000 @@ -1,98 +0,0 @@ -workspace(name = "com_github_google_flatbuffers") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "platforms", - sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz", - ], -) - -http_archive( - name = "build_bazel_rules_swift", - sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97", - url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz", -) - -load( - "@build_bazel_rules_swift//swift:repositories.bzl", - "swift_rules_dependencies", -) - -swift_rules_dependencies() - -load( - "@build_bazel_rules_swift//swift:extras.bzl", - "swift_rules_extra_dependencies", -) - -swift_rules_extra_dependencies() - -http_archive( - name = "io_bazel_rules_go", - sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") - -go_rules_dependencies() - -##### Protobuf -_PROTOBUF_VERSION = "3.15.2" - -http_archive( - name = "com_google_protobuf", - strip_prefix = "protobuf-" + _PROTOBUF_VERSION, - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v" + _PROTOBUF_VERSION + ".tar.gz", - ], -) - -##### GRPC -_GRPC_VERSION = "1.48.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0 - -http_archive( - name = "com_github_grpc_grpc", - strip_prefix = "grpc-" + _GRPC_VERSION, - urls = ["https://github.com/grpc/grpc/archive/refs/tags/v" + _GRPC_VERSION + ".tar.gz"], -) - -load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") - -grpc_deps() - -load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") - -grpc_extra_deps() - -# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0 -http_archive( - name = "build_bazel_rules_nodejs", - sha256 = "965ee2492a2b087cf9e0f2ca472aeaf1be2eb650e0cfbddf514b9a7d3ea4b02a", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.2.0/rules_nodejs-5.2.0.tar.gz"], -) - -load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies") - -build_bazel_rules_nodejs_dependencies() - -load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install") - -node_repositories() - -yarn_install( - name = "npm", - exports_directories_only = False, - # Unfreeze to add/remove packages. - frozen_lockfile = True, - package_json = "//:package.json", - symlink_node_modules = False, - yarn_lock = "//:yarn.lock", -)