diff --git a/build_defs.bzl b/build_defs.bzl index fff235448..f9d8597be 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -7,13 +7,19 @@ Rules for building C++ flatbuffers with Bazel. load("@rules_cc//cc:defs.bzl", "cc_library") -TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc" +def repo_name(label): + if hasattr(label, "repo_name"): # Added in Bazel 7.1 + return label.repo_name + else: + return "com_github_google_flatbuffers" + +TRUE_FLATC_PATH = Label("//:flatc") DEFAULT_INCLUDE_PATHS = [ "./", "$(GENDIR)", "$(BINDIR)", - "$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers", + "$(execpath %s).runfiles/%s" % (TRUE_FLATC_PATH, repo_name(TRUE_FLATC_PATH)), ] def default_include_paths(flatc_path): @@ -21,7 +27,7 @@ def default_include_paths(flatc_path): "./", "$(GENDIR)", "$(BINDIR)", - "$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path), + "$(execpath %s).runfiles/%s" % (flatc_path, repo_name(flatc_path)), ] DEFAULT_FLATC_ARGS = [ @@ -47,7 +53,7 @@ def flatbuffer_library_public( compatible_with = None, restricted_to = None, target_compatible_with = None, - flatc_path = "@com_github_google_flatbuffers//:flatc", + flatc_path = None, output_to_bindir = False, tools = None, extra_env = None, @@ -87,6 +93,11 @@ def flatbuffer_library_public( optionally a Fileset([reflection_name]) with all generated reflection binaries. """ + if flatc_path == None: + flatc_path = TRUE_FLATC_PATH + else: + flatc_path = native.package_relative_label(flatc_path) + reflection_include_paths = include_paths if include_paths == None: include_paths = default_include_paths(flatc_path) @@ -262,8 +273,8 @@ def flatbuffer_cc_library( "-parse_headers", ], deps = [ - "@com_github_google_flatbuffers//:runtime_cc", - "@com_github_google_flatbuffers//:flatbuffers", + Label("//:runtime_cc"), + Label("//:flatbuffers"), ] + deps, includes = cc_include_paths, compatible_with = compatible_with, diff --git a/ts/BUILD.bazel b/ts/BUILD.bazel index 804faea61..261baa087 100644 --- a/ts/BUILD.bazel +++ b/ts/BUILD.bazel @@ -68,7 +68,7 @@ sh_binary( name = "compile_flat_file", srcs = ["compile_flat_file.sh"], data = [ - "@com_github_google_flatbuffers//:flatc", + "//:flatc", "@nodejs_linux_amd64//:node_bin", ], # We just depend directly on the linux amd64 nodejs binary, so only support diff --git a/typescript.bzl b/typescript.bzl index 63c1218c6..994488bb9 100644 --- a/typescript.bzl +++ b/typescript.bzl @@ -69,7 +69,7 @@ def flatbuffer_ts_library( reflection_name = reflection_name, reflection_visibility = visibility, target_compatible_with = target_compatible_with, - flatc_path = "@com_github_google_flatbuffers//ts:compile_flat_file", + flatc_path = Label("//ts:compile_flat_file"), toolchains = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"], tools = ["@aspect_rules_esbuild//esbuild:resolved_toolchain"], )