Skip to content

feat(bazel): support filegroups as srcs in flatbuffer_cc_library (issue #8941) - #9246

Open
jlaportebot wants to merge 1 commit into
google:masterfrom
jlaportebot:fix/bazel-filegroup-sources-8941
Open

jlaportebot wants to merge 1 commit into
google:masterfrom
jlaportebot:fix/bazel-filegroup-sources-8941

Conversation

@jlaportebot

Copy link
Copy Markdown

Summary

This PR adds support for using filegroups as source arguments in the flatbuffer_cc_library Bazel rule, addressing issue #8941.

Changes

  1. Modified flatbuffer_library_public in build_defs.bzl:

    • Updated genrule commands to properly iterate over expanded filegroup sources using for f in "${SRCS[@]}"; do instead of the previous fixed-count loop
    • Applied the same fix to the reflection generation genrule
    • Updated documentation to reflect that srcs can now be filegroups
  2. Modified flatbuffer_cc_library in build_defs.bzl:

    • Updated documentation to reflect filegroup support
  3. Added test case in tests/BUILD.bazel:

    • Created a filegroup test_filegroup_sources containing multiple .fbs files
    • Added flatbuffer_cc_library target using the filegroup as srcs
    • Added cc_test to verify the generated code compiles and works correctly

Testing

The changes have been tested with:

  • CMake build: cmake && make -j - all existing tests pass (./flattests outputs "ALL TESTS PASSED")
  • Manual flatc compilation of the test schemas
  • Manual C++ compilation and execution of the test binary

The implementation allows users to do things like:
[bazel release 9.2.0]
Usage: bazel ...

Available commands:
aquery Analyzes the given targets and queries the action graph.
build Builds the specified targets.
canonicalize-flags Canonicalizes a list of bazel options.
clean Removes output files and optionally stops the server.
coverage Generates code coverage report for specified test targets.
cquery Loads, analyzes, and queries the specified targets w/ configurations.
dump Dumps the internal state of the bazel server process.
fetch Fetches external repositories that are prerequisites to the targets.
help Prints help for commands, or the index.
info Displays runtime info about the bazel server.
license Prints the license of this software.
mobile-install Installs targets to mobile devices.
mod Queries the Bzlmod external dependency graph
print_action Prints the command line args for compiling a file.
query Executes a dependency graph query.
run Runs the specified target.
shutdown Stops the bazel server.
test Builds and runs the specified test targets.
vendor Fetches external repositories into a folder specified by the flag --vendor_dir.
version Prints version information for bazel.

Getting more help:
bazel help
Prints help and options for .
bazel help startup_options
Options for the JVM hosting bazel.
bazel help target-syntax
Explains the syntax for specifying targets.
bazel help info-keys
Displays a list of keys used by the info command.

This is a common pattern requested in #8941 for more flexible Bazel rule usage.

AI Disclosure

This PR was authored with AI assistance.

google#8941)

- Modified flatbuffer_library_public to accept filegroups as srcs
- Updated genrule commands to properly iterate over expanded filegroup sources
- Added test case demonstrating filegroup sources functionality
- Fixes issue google#8941: Bazel rule rewrite - filegroup source arguments support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant