bazel: fix compile when precompiled headers are used
This CL fixes building the cpp proto targets when precompiled headers
are being used.
The build was failing because the generated headers are not standalone
when having a repeated field defined in another file.
Use textual_hdrs option to indicate to Bazel it should not try and
precompile these headers.
Also fix a small bug in the protogen rule where we returned all files
(including headers) as the default sourceset of the protogen rule.
Change-Id: I385b4bb8cb21565ef9ebd171aa0021d08821591a
diff --git a/bazel/proto_gen.bzl b/bazel/proto_gen.bzl
index 14e7e75..50f5747 100644
--- a/bazel/proto_gen.bzl
+++ b/bazel/proto_gen.bzl
@@ -82,14 +82,17 @@
executable = ctx.executable.protoc,
arguments = arguments,
)
+ cc_files = depset([f for f in out_files if f.path.endswith(".cc")])
+ h_files = depset([f for f in out_files if f.path.endswith(".h")])
return [
- DefaultInfo(files = depset(out_files)),
+ DefaultInfo(files = cc_files),
OutputGroupInfo(
- cc = depset([f for f in out_files if f.path.endswith(".cc")]),
- h = depset([f for f in out_files if f.path.endswith(".h")]),
+ cc = cc_files,
+ h = h_files,
),
]
+
proto_gen = rule(
attrs = {
"deps": attr.label_list(
diff --git a/bazel/rules.bzl b/bazel/rules.bzl
index 65ff4b0..af272f5 100644
--- a/bazel/rules.bzl
+++ b/bazel/rules.bzl
@@ -197,10 +197,13 @@
output_group = "h",
)
+ # The headers from the gen plugin have implicit dependencies
+ # on each other so will fail when compiled independently. Use
+ # textual_hdrs to indicate this to Bazel.
perfetto_cc_library(
name = name,
srcs = [":" + name + "_gen"],
- hdrs = [":" + name + "_gen_h"],
+ textual_hdrs = [":" + name + "_gen_h"],
deps = [
PERFETTO_CONFIG.root + ":libprotozero"
] + _cc_deps,