Ah, gotcha.
Apply this patch:
diff --git a/samples/sample_binary.cpp b/samples/sample_binary.cpp
index b8f4f1f6..e14e9e2b 100644
--- a/samples/sample_binary.cpp
+++ b/samples/sample_binary.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "monster_generated.h" // Already includes
"flatbuffers/flatbuffers.h".
+#include "samples/monster_generated.h" // Already includes
"flatbuffers/flatbuffers.h".
using namespace MyGame::Sample;
Add this as the BUILD file:
austin[30141] (master) ~/local/flatbuffers
$ cat samples/BUILD
load("//:build_defs.bzl", "flatbuffer_cc_library")
flatbuffer_cc_library(
name = "monster_fbs",
srcs = ["monster.fbs"],
)
cc_binary(
name = "sample_binary",
srcs = [
"sample_binary.cpp",
],
deps = [
":monster_fbs",
],
)
Then you should be able to run it!
austin[30143] (master) ~/local/flatbuffers
$ bazel run -c opt //samples:sample_binary
INFO: Analyzed target //samples:sample_binary (0 packages loaded, 0
targets configured).
INFO: Found 1 target...
Target //samples:sample_binary up-to-date:
bazel-bin/samples/sample_binary
INFO: Elapsed time: 0.174s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
The FlatBuffer was successfully created and verified!
Make sure your bazel is decently modern. And to reproduce what I did,
you want to be on the latest master.
austin[30145] (master) ~/local/flatbuffers
$ bazel version
Build label: 2.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 19 12:30:18 2019 (1576758618)
Build timestamp: 1576758618
Build timestamp as int: 1576758618
The background here is that bazel really really wants to use absolute
paths in your repo, which is sometimes at odds with flatbuffers. I've
been running with the following arguments (build_defs.bzl), which is
different than the defaults.
DEFAULT_FLATC_ARGS = [
"--gen-object-api",
"--gen-compare",
"--keep-prefix",
"--gen-mutable",
"--reflect-names",
"--cpp-ptr-type flatbuffers::unique_ptr",
"--force-empty",
"--scoped-enums",
"--gen-name-strings",
]
Somewhere on my long TODO list is to rewrite the bazel rules for
flatbuffers to not be genrules.
load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
will load it from an external repo when you are ready. And then the
rest of the build file should work.
Austin