diff options
author | James Kuszmaul <jkuszmaul@users.noreply.github.com> | 2022-02-21 20:33:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 22:33:47 -0600 |
commit | 9c52ec37449a76af089f6010cb3cda6399e57b37 (patch) | |
tree | 3f06d91c52267ad0c8c6c19a25720302552182d8 /build_defs.bzl | |
parent | 70e2f49bff2061d54d06df594c451a7c3fa6fbed (diff) | |
download | flatbuffers-9c52ec37449a76af089f6010cb3cda6399e57b37.tar.gz flatbuffers-9c52ec37449a76af089f6010cb3cda6399e57b37.tar.bz2 flatbuffers-9c52ec37449a76af089f6010cb3cda6399e57b37.zip |
Add deps attribute to flatbuffer_cc_library (#7107)
I'm not seeing the reason why we didn't attempt to support transitive
dependencies for flatbuffer_cc_library, and the current setup makes
having to propagate new dependencies to all of their recursive
dependents obnoxious.
Diffstat (limited to 'build_defs.bzl')
-rw-r--r-- | build_defs.bzl | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/build_defs.bzl b/build_defs.bzl index 231804bf..14188aa5 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -37,6 +37,7 @@ def flatbuffer_library_public( 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. @@ -58,6 +59,8 @@ def flatbuffer_library_public( 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. @@ -92,6 +95,7 @@ def flatbuffer_library_public( 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), ) @@ -120,8 +124,10 @@ def flatbuffer_library_public( 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, @@ -136,15 +142,18 @@ def flatbuffer_cc_library( 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. + """A cc_library with the generated reader/writers for the given flatbuffer definitions. Args: name: Rule name. @@ -154,9 +163,12 @@ def flatbuffer_cc_library( 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. - ** SEE REMARKS BELOW ** + 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 @@ -169,6 +181,8 @@ def flatbuffer_cc_library( 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. @@ -177,41 +191,17 @@ def flatbuffer_cc_library( 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. - - Remarks: - ** Because the genrule used to call flatc does not have any trivial way of - computing the output list of files transitively generated by includes and - --gen-includes (the default) being defined for flatc, the --gen-includes - flag will not work as expected. The way around this is to add a dependency - to the flatbuffer_cc_library defined alongside the flatc included Fileset. - For example you might define: - - flatbuffer_cc_library( - name = "my_fbs", - srcs = [ "schemas/foo.fbs" ], - includes = [ "//third_party/bazz:bazz_fbs_includes" ], - ) - - In which foo.fbs includes a few files from the Fileset defined at - //third_party/bazz:bazz_fbs_includes. When compiling the library that - includes foo_generated.h, and therefore has my_fbs as a dependency, it - will fail to find any of the bazz *_generated.h files unless you also - add bazz's flatbuffer_cc_library to your own dependency list, e.g.: - - cc_library( - name = "my_lib", - deps = [ - ":my_fbs", - "//third_party/bazz:bazz_fbs" - ], - ) - - Happy dependent Flatbuffering! - ''' + """ 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) @@ -226,6 +216,7 @@ def flatbuffer_cc_library( 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, ) @@ -242,10 +233,12 @@ def flatbuffer_cc_library( ], deps = [ "@com_github_google_flatbuffers//:runtime_cc", - ], - includes = [], + "@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, ) @@ -254,7 +247,7 @@ def flatbuffer_cc_library( # Flatbuffer set. native.filegroup( name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name), - srcs = srcs, + srcs = srcs + includes, compatible_with = compatible_with, restricted_to = restricted_to, visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility, |