mirror of
https://github.com/google/flatbuffers.git
synced 2025-04-08 01:02:04 +08:00
When flatbuffers is being used from a project that has no use for JavaScript, users encounter an error similar to the following: ERROR: Skipping '@com_github_google_flatbuffers//:flatbuffers': error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined. WARNING: Target pattern parsing failed. ERROR: error loading package '@com_github_google_flatbuffers//': Unable to find package for @npm//:defs.bzl: The repository '@npm' could not be resolved: Repository '@npm' is not defined. INFO: Elapsed time: 0.023s INFO: 0 processes. FAILED: Build did NOT complete successfully (0 packages loaded) currently loading: @com_github_google_flatbuffers// That's not ideal. Users that only care about C++ for example shouldn't be forced to deal with rules_js and friends. This patch attempts to fix that by moving the rules_js-specific things into the `ts` and `tests/ts` directories. This should allow non-JavaScript projects to ignore rules_js and friends completely. Here I basically followed the `rules_foo` example from rules_js: https://github.com/aspect-build/rules_js/tree/main/e2e/rules_foo The idea is that flatbuffers has its own npm dependencies regardless of what other projects may have. This means we should not force the user to import flatbuffers's npm dependencies. The new `ts/repositories.bzl` file is used by dependents to import flatbuffers's dependencies. They can still import their own dependencies. This cleanup allowed me to move all JavaScript-specific stuff from the top-level directory into subdirectories. There should be no changes in this patch in terms of functionality. It's just a refactor of the rules_js call sites. Users will have to add a call to the function in `ts/repositories.bzl` in their own `WORKSPACE` file. They can use `tests/ts/bazel_repository_test/WORKSPACE` as an example. Co-authored-by: Derek Bailey <derekbailey@google.com>
277 lines
7.6 KiB
Python
277 lines
7.6 KiB
Python
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
|
|
load("@rules_cc//cc:defs.bzl", "cc_test")
|
|
load("//:build_defs.bzl", "DEFAULT_FLATC_ARGS", "flatbuffer_cc_library")
|
|
load(":defs.bzl", "flatbuffers_as_external_repo_test")
|
|
|
|
package(default_visibility = ["//visibility:private"])
|
|
|
|
exports_files([
|
|
"bazel_repository_test_template.sh",
|
|
])
|
|
|
|
# rules_js works around various JS tooling limitations by copying everything
|
|
# into the output directory. Make the test data available to the tests this way.
|
|
copy_to_bin(
|
|
name = "test_data_copied_to_bin",
|
|
srcs = glob([
|
|
"*.mon",
|
|
"*.json",
|
|
]),
|
|
visibility = ["//tests/ts:__subpackages__"],
|
|
)
|
|
|
|
# Test binary.
|
|
cc_test(
|
|
name = "flatbuffers_test",
|
|
testonly = 1,
|
|
srcs = [
|
|
"64bit/evolution/v1_generated.h",
|
|
"64bit/evolution/v2_generated.h",
|
|
"64bit/offset64_test.cpp",
|
|
"64bit/offset64_test.h",
|
|
"64bit/test_64bit_bfbs_generated.h",
|
|
"64bit/test_64bit_generated.h",
|
|
"alignment_test.cpp",
|
|
"alignment_test.h",
|
|
"alignment_test_generated.h",
|
|
"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",
|
|
"key_field/key_field_sample_generated.h",
|
|
"key_field_test.cpp",
|
|
"key_field_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_underlying_type_test_generated.h",
|
|
"union_vector/union_vector_generated.h",
|
|
"util_test.cpp",
|
|
"util_test.h",
|
|
],
|
|
copts = [
|
|
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
|
|
],
|
|
data = [
|
|
":alignment_test.fbs",
|
|
":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",
|
|
":key_field/key_field_sample.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/non-positive-id.proto",
|
|
":prototest/test.golden.fbs",
|
|
":prototest/test.proto",
|
|
":prototest/test_id.golden.fbs",
|
|
":prototest/test_include.golden.fbs",
|
|
":prototest/test_include_id.golden.fbs",
|
|
":prototest/test_suffix.golden.fbs",
|
|
":prototest/test_suffix_id.golden.fbs",
|
|
":prototest/test_union.golden.fbs",
|
|
":prototest/test_union_id.golden.fbs",
|
|
":prototest/test_union_include.golden.fbs",
|
|
":prototest/test_union_include_id.golden.fbs",
|
|
":prototest/test_union_suffix.golden.fbs",
|
|
":prototest/test_union_suffix_id.golden.fbs",
|
|
":prototest/twice-id.proto",
|
|
":prototest/use-reserved-id.proto",
|
|
":unicode_test.json",
|
|
":union_vector/union_vector.fbs",
|
|
":union_vector/union_vector.json",
|
|
],
|
|
includes = [
|
|
"",
|
|
"include/",
|
|
],
|
|
deps = [
|
|
":alignment_test_cc_fbs",
|
|
":arrays_test_cc_fbs",
|
|
":monster_extra_cc_fbs",
|
|
":monster_test_cc_fbs",
|
|
":native_type_test_cc_fbs",
|
|
"//:flatbuffers",
|
|
"//src:generate_fbs",
|
|
],
|
|
)
|
|
|
|
# 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_bfbs_generated.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"],
|
|
outs = ["monster_test_bfbs_generated.h"],
|
|
flatc_args = DEFAULT_FLATC_ARGS + [
|
|
"--bfbs-comments",
|
|
"--bfbs-builtins",
|
|
"--bfbs-gen-embed",
|
|
"--bfbs-filenames tests",
|
|
],
|
|
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_cc_library(
|
|
name = "alignment_test_cc_fbs",
|
|
srcs = ["alignment_test.fbs"],
|
|
)
|
|
|
|
flatbuffers_as_external_repo_test(
|
|
name = "bazel_repository_test",
|
|
directory = "bazel_repository_test_dir",
|
|
)
|