Commit 62ec7d52 authored by Austin Schuh's avatar Austin Schuh Committed by Wouter van Oortmerssen

[Bazel] Add support for compatible_with and restricted_to (#5681)

* Add support for compatible_with and restricted_to

These attributes have been available in Bazel for years.  Pass them
through so the flatbuffer rules can be used with them.  They let you
constrain which target platform is used.

While we are here, fix gen_reflections to work with bazel.

* Add docs
parent 7de66805
...@@ -35,6 +35,8 @@ def flatbuffer_library_public( ...@@ -35,6 +35,8 @@ def flatbuffer_library_public(
flatc_args = DEFAULT_FLATC_ARGS, flatc_args = DEFAULT_FLATC_ARGS,
reflection_name = "", reflection_name = "",
reflection_visibility = None, reflection_visibility = None,
compatible_with = None,
restricted_to = None,
output_to_bindir = False): output_to_bindir = False):
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler. """Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
...@@ -52,6 +54,11 @@ def flatbuffer_library_public( ...@@ -52,6 +54,11 @@ def flatbuffer_library_public(
reflection binaries for the schemas. reflection binaries for the schemas.
reflection_visibility: The visibility of the generated reflection Fileset. reflection_visibility: The visibility of the generated reflection Fileset.
output_to_bindir: Passed to genrule for output to bin directory. 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.
output_to_bindir: Passed to genrule for output to bin directory.
This rule creates a filegroup(name) with all generated source files, and This rule creates a filegroup(name) with all generated source files, and
...@@ -84,6 +91,8 @@ def flatbuffer_library_public( ...@@ -84,6 +91,8 @@ def flatbuffer_library_public(
output_to_bindir = output_to_bindir, output_to_bindir = output_to_bindir,
tools = [flatc_path], tools = [flatc_path],
cmd = genrule_cmd, cmd = genrule_cmd,
compatible_with = compatible_with,
restricted_to = restricted_to,
message = "Generating flatbuffer files for %s:" % (name), message = "Generating flatbuffer files for %s:" % (name),
) )
if reflection_name: if reflection_name:
...@@ -109,16 +118,17 @@ def flatbuffer_library_public( ...@@ -109,16 +118,17 @@ def flatbuffer_library_public(
outs = reflection_outs, outs = reflection_outs,
output_to_bindir = output_to_bindir, output_to_bindir = output_to_bindir,
tools = [flatc_path], tools = [flatc_path],
compatible_with = compatible_with,
restricted_to = restricted_to,
cmd = reflection_genrule_cmd, cmd = reflection_genrule_cmd,
message = "Generating flatbuffer reflection binary for %s:" % (name), message = "Generating flatbuffer reflection binary for %s:" % (name),
) )
native.Fileset( native.filegroup(
name = reflection_name, name = "%s_out" % reflection_name,
out = "%s_out" % reflection_name, srcs = reflection_outs,
entries = [
native.FilesetEntry(files = reflection_outs),
],
visibility = reflection_visibility, visibility = reflection_visibility,
compatible_with = compatible_with,
restricted_to = restricted_to,
) )
def flatbuffer_cc_library( def flatbuffer_cc_library(
...@@ -130,6 +140,8 @@ def flatbuffer_cc_library( ...@@ -130,6 +140,8 @@ def flatbuffer_cc_library(
include_paths = DEFAULT_INCLUDE_PATHS, include_paths = DEFAULT_INCLUDE_PATHS,
flatc_args = DEFAULT_FLATC_ARGS, flatc_args = DEFAULT_FLATC_ARGS,
visibility = None, visibility = None,
compatible_with = None,
restricted_to = None,
srcs_filegroup_visibility = None, srcs_filegroup_visibility = None,
gen_reflections = False): gen_reflections = False):
'''A cc_library with the generated reader/writers for the given flatbuffer definitions. '''A cc_library with the generated reader/writers for the given flatbuffer definitions.
...@@ -153,6 +165,10 @@ def flatbuffer_cc_library( ...@@ -153,6 +165,10 @@ def flatbuffer_cc_library(
By default, use the value of the visibility parameter above. By default, use the value of the visibility parameter above.
gen_reflections: Optional, if true this will generate the flatbuffer gen_reflections: Optional, if true this will generate the flatbuffer
reflection binaries for the schemas. 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.
This produces: This produces:
filegroup([name]_srcs): all generated .h files. filegroup([name]_srcs): all generated .h files.
...@@ -208,6 +224,8 @@ def flatbuffer_cc_library( ...@@ -208,6 +224,8 @@ def flatbuffer_cc_library(
includes = includes, includes = includes,
include_paths = include_paths, include_paths = include_paths,
flatc_args = flatc_args, flatc_args = flatc_args,
compatible_with = compatible_with,
restricted_to = restricted_to,
reflection_name = reflection_name, reflection_name = reflection_name,
reflection_visibility = visibility, reflection_visibility = visibility,
) )
...@@ -226,6 +244,8 @@ def flatbuffer_cc_library( ...@@ -226,6 +244,8 @@ def flatbuffer_cc_library(
"@com_github_google_flatbuffers//:runtime_cc", "@com_github_google_flatbuffers//:runtime_cc",
], ],
includes = [], includes = [],
compatible_with = compatible_with,
restricted_to = restricted_to,
linkstatic = 1, linkstatic = 1,
visibility = visibility, visibility = visibility,
) )
...@@ -235,5 +255,7 @@ def flatbuffer_cc_library( ...@@ -235,5 +255,7 @@ def flatbuffer_cc_library(
native.filegroup( native.filegroup(
name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name), name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
srcs = srcs, srcs = srcs,
compatible_with = compatible_with,
restricted_to = restricted_to,
visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility, visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment