blob: af05903a6a5413453e2a438c66b32e14f7249004 [file] [log] [blame]
################################################################################
# Protocol Buffers Compiler
################################################################################
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
"pkg_files",
"strip_prefix",
)
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
proto_library(
name = "plugin_proto",
srcs = ["plugin.proto"],
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = ["//:descriptor_proto"],
)
cc_library(
name = "importer",
srcs = [
"importer.cc",
"parser.cc",
],
hdrs = [
"importer.h",
"parser.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "code_generator",
srcs = [
"code_generator.cc",
"plugin.cc",
"plugin.pb.cc",
],
hdrs = [
"code_generator.h",
"plugin.h",
"plugin.pb.h",
"scc.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"],
deps = [
"//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "command_line_interface",
srcs = [
"command_line_interface.cc",
"subprocess.cc",
"zip_writer.cc",
],
hdrs = [
"command_line_interface.h",
"subprocess.h",
"zip_writer.h",
],
copts = COPTS,
include_prefix = "google/protobuf/compiler",
visibility = ["//visibility:public"],
deps = [
":code_generator",
":importer",
"//src/google/protobuf:protobuf_nowkt",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
)
cc_library(
name = "protoc_lib_nowkt",
srcs = [
"main.cc",
],
copts = COPTS,
deps = [
":code_generator",
":command_line_interface",
":importer",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/python",
"//src/google/protobuf/compiler/ruby",
],
)
cc_binary(
name = "protoc_nowkt",
copts = COPTS,
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
visibility = [
"//src/google/protobuf:__pkg__",
],
deps = [":protoc_lib_nowkt"],
)
cc_library(
name = "protoc_lib",
copts = COPTS,
visibility = [
"//:__pkg__",
"//pkg:__pkg__",
],
deps = [
":protoc_lib_nowkt",
"//:protobuf",
],
)
# 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(
name = "protoc",
actual = "//:protoc",
visibility = ["//visibility:public"],
)
# Test that the protoc binary is built for the correct architecture.
aarch64_test(
name = "protoc_aarch64_test",
bazel_binaries = ["//:protoc"],
)
x86_64_test(
name = "protoc_x86_64_test",
bazel_binaries = ["//:protoc"],
)
################################################################################
# Tests and support libraries
################################################################################
cc_library(
name = "annotation_test_util",
testonly = 1,
srcs = ["annotation_test_util.cc"],
hdrs = ["annotation_test_util.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
":code_generator",
":command_line_interface",
"//:protobuf",
"//src/google/protobuf/io",
"//src/google/protobuf/testing",
],
)
################################################################################
# Tests
################################################################################
filegroup(
name = "plugin_proto_srcs",
testonly = 1,
srcs = [
"plugin.pb.cc",
"plugin.pb.h",
"plugin.proto",
],
visibility = [
"//src/google/protobuf/compiler/cpp:__pkg__",
],
)
exports_files(
srcs = ["plugin.proto"],
visibility = ["//:__pkg__"],
)
cc_library(
name = "mock_code_generator",
testonly = 1,
srcs = ["mock_code_generator.cc"],
hdrs = ["mock_code_generator.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//pkg:__pkg__"],
deps = [
":code_generator",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs",
"//src/google/protobuf/testing",
],
)
cc_binary(
name = "test_plugin",
testonly = 1,
srcs = ["test_plugin.cc"],
copts = COPTS,
deps = [
":code_generator",
":mock_code_generator",
],
)
cc_test(
name = "command_line_interface_unittest",
srcs = ["command_line_interface_unittest.cc"],
copts = COPTS + select({
"//build_defs:config_msvc": [],
"//conditions:default": [
"-Wno-deprecated",
"-Wno-deprecated-declarations",
],
}) + [
# Note: This only works on Windows with symlinks and runfiles enabled.
"-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH=\\\"$(rootpath :test_plugin)\\\"",
],
data = [
":test_plugin",
"//:test_proto_srcs",
"//src/google/protobuf:testdata",
],
deps = [
":code_generator",
":command_line_interface",
":mock_code_generator",
"//:protobuf",
"//src/google/protobuf/compiler/cpp:names",
"//src/google/protobuf:cc_test_protos",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs",
"//src/google/protobuf/testing",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "importer_unittest",
srcs = ["importer_unittest.cc"],
copts = COPTS,
deps = [
":importer",
"//:protobuf",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs",
"//src/google/protobuf/testing",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "parser_unittest",
srcs = ["parser_unittest.cc"],
copts = COPTS + select({
"//build_defs:config_msvc": [],
"//conditions:default": [
"-Wno-deprecated",
"-Wno-deprecated-declarations",
],
}),
deps = [
":importer",
"//:protobuf",
"//src/google/protobuf:cc_test_protos",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/io",
"//src/google/protobuf/stubs",
"//src/google/protobuf/testing",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
################################################################################
# Generates protoc release artifacts.
################################################################################
genrule(
name = "protoc_readme",
outs = ["readme.txt"],
cmd = """
echo "Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/
This package contains a precompiled binary version of the protocol buffer
compiler (protoc). This binary is intended for users who want to use Protocol
Buffers in languages other than C++ but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH.
If you intend to use the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.
Please refer to our official github site for more installation instructions:
https://github.com/protocolbuffers/protobuf" > $@
""",
visibility = ["//:__pkg__"],
)
pkg_files(
name = "compiler_plugin_protos_files",
srcs = ["plugin.proto"],
prefix = "include/google/protobuf/compiler",
visibility = ["//pkg:__pkg__"],
)
pkg_files(
name = "protoc_files",
srcs = [":protoc"],
attributes = pkg_attributes(mode = "0555"),
prefix = "bin/",
visibility = ["//:__pkg__"],
)
################################################################################
# Distribution packaging
################################################################################
pkg_files(
name = "dist_files",
srcs = glob(["**/*"]),
strip_prefix = strip_prefix.from_root(""),
visibility = ["//src:__pkg__"],
)
filegroup(
name = "test_srcs",
srcs = glob([
"*_test.cc",
"*unittest.cc",
]) + [
"//src/google/protobuf/compiler/cpp:test_srcs",
"//src/google/protobuf/compiler/csharp:test_srcs",
"//src/google/protobuf/compiler/java:test_srcs",
"//src/google/protobuf/compiler/objectivec:test_srcs",
"//src/google/protobuf/compiler/php:test_srcs",
"//src/google/protobuf/compiler/python:test_srcs",
"//src/google/protobuf/compiler/ruby:test_srcs",
],
visibility = ["//pkg:__pkg__"],
)
filegroup(
name = "test_plugin_srcs",
srcs = ["test_plugin.cc"],
visibility = ["//pkg:__pkg__"],
)
filegroup(
name = "test_proto_srcs",
srcs = [
"//src/google/protobuf/compiler/cpp:test_proto_srcs",
],
visibility = ["//pkg:__pkg__"],
)