Skip to content

Fix cc_library protoc_lib defines main() #12887 #20016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
22 changes: 5 additions & 17 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ load("//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
load("//bazel:java_proto_library.bzl", "java_proto_library")
load("//bazel:proto_library.bzl", "proto_library")
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")

licenses(["notice"])
Expand Down Expand Up @@ -234,27 +233,16 @@ alias(
visibility = ["//visibility:public"],
)

cc_binary(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's still a bunch of test failures related to the alias/cc_binary switch. There are a pretty large number of places where we assume protoc and protoc_static get dumped directly into bazel-bin, and this change moves the binaries somewhere else.

I agree with the direction, and it would be nice to keep as much as possible in //src/google/protobuf/compiler, but I think the cc_binary targets need to live here for now (to avoid a major refactor)

alias(
name = "protoc",
copts = COPTS,
linkopts = LINK_OPTS,
actual = "//src/google/protobuf/compiler:protoc",
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
)

cc_binary(
alias(
name = "protoc_static",
copts = COPTS,
features = select({
# This isn't possible on mac because there is no static library for lcrt0.o
"@platforms//os:osx": [],
"//build_defs:config_osx": [],
# When cross-compiling we need to statically link all C++ libraries.
"//conditions:default": ["fully_static_link"],
}),
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
actual = "//src/google/protobuf/compiler:protoc_static",
visibility = ["//visibility:public"],
)

################################################################################
Expand Down
30 changes: 22 additions & 8 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load("//bazel:proto_library.bzl", "proto_library")
load("//bazel:upb_c_proto_library.bzl", "upb_c_proto_library")
load("//bazel:upb_proto_reflection_library.bzl", "upb_proto_reflection_library")
load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
load("//build_defs:cpp_opts.bzl", "COPTS")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
load("test_plugin_injection.bzl", "inject_plugin_paths")

proto_library(
Expand Down Expand Up @@ -205,9 +205,6 @@ cc_library(

cc_library(
name = "protoc_lib",
srcs = [
"main.cc",
],
copts = COPTS,
strip_include_prefix = "/src",
visibility = [
Expand Down Expand Up @@ -250,12 +247,29 @@ cc_binary(
],
)

# Note: this is an alias for now. In the future, this rule will become the
# cc_binary for protoc, and //:protoc will become an alias.
alias(
cc_binary(
name = "protoc",
actual = "//:protoc",
srcs = ["main.cc"],
copts = COPTS,
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [":protoc_lib"],
)

cc_binary(
name = "protoc_static",
srcs = ["main.cc"],
copts = COPTS,
features = select({
# This isn't possible on mac because there is no static library for lcrt0.o
"@platforms//os:osx": [],
"//build_defs:config_osx": [],
# When cross-compiling we need to statically link all C++ libraries.
"//conditions:default": ["fully_static_link"],
}),
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
)

# Test that the protoc binary is built for the correct architecture.
Expand Down
Loading