Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ build --enable_platform_specific_config
# warning set used for our own code (see phaser/copts.bzl) does not flood the
# build with diagnostics from abseil/protobuf/googletest/toolbelt.
build --features=external_include_paths
# Dependency sources are outside Phaser's control. Keep clean builds focused on
# diagnostics actionable in this repository for both target and tool builds.
build --per_file_copt=^external/.*@-w
build --host_per_file_copt=^external/.*@-w

# For all builds, use C++17
build --cxxopt="-std=c++17"
Expand Down
17 changes: 11 additions & 6 deletions phaser/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//phaser:copts.bzl", "PHASER_COPTS")
load(
"//phaser:copts.bzl",
"PHASER_COPTS",
"PHASER_PROTOBUF_GENERATED_COPTS",
)

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -38,7 +42,7 @@ cc_test(
srcs = [
"phaser_test.cc",
],
copts = PHASER_COPTS,
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
":test_helpers",
Expand Down Expand Up @@ -66,12 +70,13 @@ cc_test(
cc_test(
name = "ros_compile_test",
srcs = ["ros_compile_test.cc"],
copts = PHASER_COPTS,
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
"//phaser/runtime:phaser_runtime",
"//phaser/testdata:ros_compile_cc_proto",
"//phaser/testdata:ros_compile_phaser",
"//phaser/testdata:service_only_phaser",
"@com_google_absl//absl/types:span",
"@com_google_googletest//:gtest_main",
],
Expand Down Expand Up @@ -192,7 +197,7 @@ cc_test(
cc_test(
name = "ros_wire_conversion_test",
srcs = ["ros_wire_conversion_test.cc"],
copts = PHASER_COPTS,
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
"//phaser/runtime:phaser_runtime",
Expand All @@ -208,7 +213,7 @@ cc_test(
cc_test(
name = "all_types_test",
srcs = ["all_types_test.cc"],
copts = PHASER_COPTS,
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
data = ["valgrind.supp"],
deps = [
":test_helpers",
Expand Down Expand Up @@ -246,7 +251,7 @@ cc_test(
# Performance benchmark; excluded from wildcard test runs (e.g. //...).
# Run explicitly with `bazel test //phaser:perf_test`.
tags = ["manual"],
copts = PHASER_COPTS,
copts = PHASER_COPTS + PHASER_PROTOBUF_GENERATED_COPTS,
deps = [
"//phaser/runtime:phaser_runtime",
"//phaser/testdata:test_message_phaser",
Expand Down
6 changes: 3 additions & 3 deletions phaser/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//phaser:copts.bzl", "PHASER_COPTS")
load("//phaser:copts.bzl", "PHASER_PROTOC_COPTS")

package(default_visibility = ["//visibility:public"])

Expand All @@ -10,7 +10,7 @@ cc_library(
"gen.cc",
"message_gen.cc",
],
copts = PHASER_COPTS,
copts = PHASER_PROTOC_COPTS,
hdrs = [
"enum_gen.h",
"gen.h",
Expand All @@ -33,7 +33,7 @@ cc_binary(
srcs = [
"main.cc",
],
copts = PHASER_COPTS,
copts = PHASER_PROTOC_COPTS,
deps = [
":phaser_lib",
"@com_google_absl//absl/flags:flag",
Expand Down
31 changes: 24 additions & 7 deletions phaser/compiler/gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,31 @@ bool CodeGenerator::Generate(
generate_ros_metadata_ &&
file->package().rfind("google.protobuf", 0) != 0;

// Custom option schemas and other message-free protos need no C++ output.
// descriptor.proto is imported for extensions but must not be emitted as a
// Phaser message graph (it is huge and not a runtime payload type here).
if (file->message_type_count() == 0 && file->enum_type_count() == 0) {
return true;
}
if (file->name() == std::string("google/protobuf/descriptor.proto") ||
// Custom option schemas, service-only files, and descriptor.proto need no
// generated declarations. Still create their declared outputs so build rules
// can safely include them in larger transitive proto graphs.
if ((file->message_type_count() == 0 && file->enum_type_count() == 0) ||
file->name() == std::string("google/protobuf/descriptor.proto") ||
file->name() == std::string("phaser/options.proto")) {
std::string filename = GeneratedFilename(
package_name_, target_name_, std::string(file->name()));
std::filesystem::path hp(filename);
hp.replace_extension(".phaser.h");
std::filesystem::path cp(filename);
cp.replace_extension(".phaser.cc");
auto header_output = std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream>(
generator_context->Open(hp.string()));
auto source_output = std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream>(
generator_context->Open(cp.string()));
if (header_output == nullptr || source_output == nullptr) {
*error = absl::StrFormat("Failed to create empty outputs for %s",
file->name());
return false;
}
WriteToZeroCopyStream("// No Phaser declarations in this schema.\n",
header_output.get());
WriteToZeroCopyStream("// No Phaser definitions in this schema.\n",
source_output.get());
return true;
}

Expand Down
Loading
Loading