Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bazel ts support #8499

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def flatbuffer_library_public(
reflection_genrule_cmd = " ".join([
"SRCS=($(SRCS));",
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
# Move the .fbs file into the current package if it is not there already
'if [[ $$(dirname $$f) != "{0}" ]]; then s="$$f"; f="{0}/$$(basename "$$f")"; mkdir -p "{0}"; mv "$$s" "$$f"; fi;'.format(native.package_relative_label(":invalid").package),
dbaileychess marked this conversation as resolved.
Show resolved Hide resolved
"$(location %s)" % (TRUE_FLATC_PATH),
"-b --schema",
" ".join(flatc_args),
Expand All @@ -152,9 +154,10 @@ def flatbuffer_library_public(
"done",
])
reflection_outs = [
(out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1])
(out_prefix + "%s.bfbs") % (native.package_relative_label(s).name.removesuffix(".fbs"))
for s in srcs
]

native.genrule(
name = "%s_srcs" % reflection_name,
srcs = srcs + includes,
Expand Down
6 changes: 6 additions & 0 deletions reflection/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ filegroup(
visibility = ["//visibility:public"],
)

# flatbuffer_ts_library() only supports .fbs file but not filegroups
exports_files(
srcs = ["reflection.fbs"],
visibility = ["//visibility:public"],
)

filegroup(
name = "reflection_fbs_schema",
srcs = ["reflection.fbs"],
Expand Down
9 changes: 1 addition & 8 deletions reflection/ts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
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",
srcs = [":reflection.fbs"],
srcs = ["//reflection:reflection.fbs"],
gen_reflections = True,
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions tests/ts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flatbuffer_ts_library(
name = "typescript_ts_fbs",
srcs = ["typescript_keywords.fbs"],
deps = [
"//reflection/ts:reflection_ts_fbs",
"//tests/ts/test_dir:include_ts_fbs",
"//tests/ts/test_dir:typescript_transitive_ts_fbs",
],
Expand Down
2 changes: 1 addition & 1 deletion typescript.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def flatbuffer_ts_library(
reflection binaries for the schemas.
"""
srcs_lib = "%s_srcs" % (name)
out_base = [s.replace(".fbs", "").split("/")[-1].split(":")[-1] for s in srcs]
out_base = [native.package_relative_label(s).name.removesuffix(".fbs") for s in srcs]

if len(srcs) != 1:
fail("flatbuffer_ts_library only supports one .fbs file per target currently.")
Expand Down
Loading