Squashed 'libs/protobuf/' content from commit fcd3b9a85
git-subtree-dir: libs/protobuf git-subtree-split: fcd3b9a85ef36e46643dc30176cea1a7ad62e02b
This commit is contained in:
183
build_defs/BUILD.bazel
Normal file
183
build_defs/BUILD.bazel
Normal file
@@ -0,0 +1,183 @@
|
||||
# Internal Starlark definitions for Protobuf.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", starlark_cc_proto_library = "cc_proto_library")
|
||||
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
|
||||
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
|
||||
load(":compiler_config_setting.bzl", "create_compiler_config_setting")
|
||||
|
||||
package(
|
||||
default_visibility = [
|
||||
# Public, but Protobuf only visibility.
|
||||
"//:__subpackages__",
|
||||
],
|
||||
)
|
||||
|
||||
create_compiler_config_setting(
|
||||
name = "config_msvc",
|
||||
value = "msvc-cl",
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "aarch64",
|
||||
values = {"cpu": "linux-aarch_64"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "x86_64",
|
||||
values = {"cpu": "linux-x86_64"},
|
||||
)
|
||||
|
||||
# Android NDK builds can specify different crosstool_top flags to choose which
|
||||
# STL they use for C++. We need these multiple variants to catch all of those
|
||||
# versions of crosstool_top and reliably detect Android.
|
||||
#
|
||||
# For more info on the various crosstool_tops used by NDK Bazel builds, see:
|
||||
# https://docs.bazel.build/versions/master/android-ndk.html#configuring-the-stl
|
||||
|
||||
config_setting(
|
||||
name = "config_android",
|
||||
values = {
|
||||
"crosstool_top": "//external:android/crosstool",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_android-stlport",
|
||||
values = {
|
||||
"crosstool_top": "@androidndk//:toolchain-stlport",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_android-libcpp",
|
||||
values = {
|
||||
"crosstool_top": "@androidndk//:toolchain-libcpp",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_android-gnu-libstdcpp",
|
||||
values = {
|
||||
"crosstool_top": "@androidndk//:toolchain-gnu-libstdcpp",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_android-default",
|
||||
values = {
|
||||
"crosstool_top": "@androidndk//:default_crosstool",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_win32",
|
||||
values = {
|
||||
"cpu": "win32",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "config_win64",
|
||||
values = {
|
||||
"cpu": "win64",
|
||||
},
|
||||
)
|
||||
|
||||
# Internal testing:
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "any_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:any_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "api_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:api_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "compiler_plugin_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:compiler_plugin_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "descriptor_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:descriptor_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "duration_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:duration_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "empty_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:empty_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "field_mask_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:field_mask_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "source_context_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:source_context_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "struct_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:struct_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "timestamp_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:timestamp_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "type_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:type_proto"],
|
||||
)
|
||||
|
||||
starlark_cc_proto_library(
|
||||
name = "wrappers_cc_proto",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = ["//:wrappers_proto"],
|
||||
)
|
||||
|
||||
cc_proto_blacklist_test(
|
||||
name = "cc_proto_blacklist_test",
|
||||
deps = [
|
||||
":any_cc_proto",
|
||||
":api_cc_proto",
|
||||
":compiler_plugin_cc_proto",
|
||||
":descriptor_cc_proto",
|
||||
":duration_cc_proto",
|
||||
":empty_cc_proto",
|
||||
":field_mask_cc_proto",
|
||||
":source_context_cc_proto",
|
||||
":struct_cc_proto",
|
||||
":timestamp_cc_proto",
|
||||
":type_cc_proto",
|
||||
":wrappers_cc_proto",
|
||||
],
|
||||
)
|
||||
|
||||
pkg_files(
|
||||
name = "dist_files",
|
||||
srcs = glob(["*"]),
|
||||
strip_prefix = strip_prefix.from_root(""),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
)
|
||||
56
build_defs/arch_tests.bzl
Normal file
56
build_defs/arch_tests.bzl
Normal file
@@ -0,0 +1,56 @@
|
||||
"""Generated unittests to verify that a binary is built for the expected architecture."""
|
||||
|
||||
load("//build_defs:internal_shell.bzl", "inline_sh_test")
|
||||
|
||||
def _arch_test_impl(
|
||||
name,
|
||||
platform,
|
||||
file_platform,
|
||||
bazel_binaries = [],
|
||||
system_binaries = [],
|
||||
**kwargs):
|
||||
"""Bazel rule to verify that a Bazel or system binary is built for the aarch64 architecture.
|
||||
|
||||
Args:
|
||||
name: the name of the test.
|
||||
platform: a diagnostic name for this architecture.
|
||||
file_platform: the expected output of `file`.
|
||||
bazel_binaries: a set of binary targets to inspect.
|
||||
system_binaries: a set of paths to system executables to inspect.
|
||||
**kwargs: other keyword arguments that are passed to the test.
|
||||
"""
|
||||
|
||||
inline_sh_test(
|
||||
name = name,
|
||||
tools = bazel_binaries,
|
||||
cmd = """
|
||||
for binary in "$(rootpaths %s) %s"; do
|
||||
(file -L $$binary | grep -q "%s") \
|
||||
|| (echo "Test binary is not an %s binary: "; file -L $$binary; exit 1)
|
||||
done
|
||||
""" % (
|
||||
" ".join(bazel_binaries),
|
||||
" ".join(system_binaries),
|
||||
file_platform,
|
||||
platform,
|
||||
),
|
||||
target_compatible_with = select({
|
||||
"//build_defs:" + platform: [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def aarch64_test(**kwargs):
|
||||
_arch_test_impl(
|
||||
platform = "aarch64",
|
||||
file_platform = "ELF 64-bit LSB executable, ARM aarch64",
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def x86_64_test(**kwargs):
|
||||
_arch_test_impl(
|
||||
platform = "x86_64",
|
||||
file_platform = "ELF 64-bit LSB executable, ARM x86_64",
|
||||
**kwargs
|
||||
)
|
||||
38
build_defs/cc_proto_blacklist_test.bzl
Normal file
38
build_defs/cc_proto_blacklist_test.bzl
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Contains a unittest to verify that `cc_proto_library` does not generate code for blacklisted `.proto` sources (i.e. WKPs)."""
|
||||
|
||||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
|
||||
|
||||
def _cc_proto_blacklist_test_impl(ctx):
|
||||
"""Verifies that there are no C++ compile actions for Well-Known-Protos.
|
||||
|
||||
Args:
|
||||
ctx: The rule context.
|
||||
|
||||
Returns: A (not further specified) sequence of providers.
|
||||
"""
|
||||
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
for dep in ctx.attr.deps:
|
||||
files = dep.files.to_list()
|
||||
asserts.equals(
|
||||
env,
|
||||
[],
|
||||
files,
|
||||
"Expected that target '{}' does not provide files, got {}".format(
|
||||
dep.label,
|
||||
len(files),
|
||||
),
|
||||
)
|
||||
|
||||
return unittest.end(env)
|
||||
|
||||
cc_proto_blacklist_test = unittest.make(
|
||||
impl = _cc_proto_blacklist_test_impl,
|
||||
attrs = {
|
||||
"deps": attr.label_list(
|
||||
mandatory = True,
|
||||
providers = [CcInfo],
|
||||
),
|
||||
},
|
||||
)
|
||||
23
build_defs/compiler_config_setting.bzl
Normal file
23
build_defs/compiler_config_setting.bzl
Normal file
@@ -0,0 +1,23 @@
|
||||
"""Creates config_setting that allows selecting based on 'compiler' value."""
|
||||
|
||||
def create_compiler_config_setting(name, value, visibility = None):
|
||||
# The "do_not_use_tools_cpp_compiler_present" attribute exists to
|
||||
# distinguish between older versions of Bazel that do not support
|
||||
# "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
|
||||
# In the future, the only way to select on the compiler will be through
|
||||
# flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can
|
||||
# be removed.
|
||||
if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
|
||||
native.config_setting(
|
||||
name = name,
|
||||
flag_values = {
|
||||
"@bazel_tools//tools/cpp:compiler": value,
|
||||
},
|
||||
visibility = visibility,
|
||||
)
|
||||
else:
|
||||
native.config_setting(
|
||||
name = name,
|
||||
values = {"compiler": value},
|
||||
visibility = visibility,
|
||||
)
|
||||
47
build_defs/cpp_opts.bzl
Normal file
47
build_defs/cpp_opts.bzl
Normal file
@@ -0,0 +1,47 @@
|
||||
"""C++ compile/link options for Protobuf libraries."""
|
||||
|
||||
COPTS = select({
|
||||
"//build_defs:config_msvc": [
|
||||
"/wd4065", # switch statement contains 'default' but no 'case' labels
|
||||
"/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data
|
||||
"/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
|
||||
"/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data
|
||||
"/wd4305", # 'identifier' : truncation from 'type1' to 'type2'
|
||||
"/wd4307", # 'operator' : integral constant overflow
|
||||
"/wd4309", # 'conversion' : truncation of constant value
|
||||
"/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
|
||||
"/wd4355", # 'this' : used in base member initializer list
|
||||
"/wd4506", # no definition for inline function 'function'
|
||||
"/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning)
|
||||
"/wd4996", # The compiler encountered a deprecated declaration.
|
||||
],
|
||||
"//conditions:default": [
|
||||
"-DHAVE_ZLIB",
|
||||
"-Woverloaded-virtual",
|
||||
"-Wno-sign-compare",
|
||||
"-Werror",
|
||||
],
|
||||
})
|
||||
# Android and MSVC builds do not need to link in a separate pthread library.
|
||||
LINK_OPTS = select({
|
||||
"//build_defs:config_android": [],
|
||||
"//build_defs:config_android-stlport": [],
|
||||
"//build_defs:config_android-libcpp": [],
|
||||
"//build_defs:config_android-gnu-libstdcpp": [],
|
||||
"//build_defs:config_android-default": [],
|
||||
"//build_defs:config_msvc": [
|
||||
# Suppress linker warnings about files with no symbols defined.
|
||||
"-ignore:4221",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"-lpthread",
|
||||
"-lm",
|
||||
],
|
||||
})
|
||||
|
||||
# When cross-compiling for Windows we need to statically link pthread and the C++ library.
|
||||
PROTOC_LINK_OPTS = select({
|
||||
"//build_defs:config_win32": ["-static"],
|
||||
"//build_defs:config_win64": ["-static"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
93
build_defs/internal_shell.bzl
Normal file
93
build_defs/internal_shell.bzl
Normal file
@@ -0,0 +1,93 @@
|
||||
"""
|
||||
Internal tools to migrate shell commands to Bazel as an intermediate step
|
||||
to wider Bazelification.
|
||||
"""
|
||||
|
||||
def inline_sh_binary(
|
||||
name,
|
||||
srcs = [],
|
||||
tools = [],
|
||||
deps = [],
|
||||
cmd = "",
|
||||
testonly = None,
|
||||
**kwargs):
|
||||
"""Bazel rule to wrap up an inline bash script in a binary.
|
||||
|
||||
This is most useful as a stop-gap solution for migrating off Autotools.
|
||||
These binaries are likely to be non-hermetic, with implicit system
|
||||
dependencies.
|
||||
|
||||
NOTE: the rule is only an internal workaround. The interface may change and
|
||||
the rule may be removed when everything is properly "Bazelified".
|
||||
|
||||
Args:
|
||||
name: the name of the inline_sh_binary.
|
||||
srcs: the files used directly by the script.
|
||||
tools: the executable tools used directly by the script. Any target used
|
||||
with rootpath/execpath/location must be declared here or in `srcs`.
|
||||
deps: a list of dependency labels that are required to run this binary.
|
||||
cmd: the inline sh command to run.
|
||||
**kwargs: other keyword arguments that are passed to sh_binary.
|
||||
testonly: common rule attribute (see:
|
||||
https://bazel.build/reference/be/common-definitions#common-attributes)
|
||||
"""
|
||||
|
||||
native.genrule(
|
||||
name = name + "_genrule",
|
||||
srcs = srcs,
|
||||
exec_tools = tools,
|
||||
outs = [name + ".sh"],
|
||||
cmd = "cat <<'EOF' >$(OUTS)\n#!/bin/bash -exu\n%s\nEOF\n" % cmd,
|
||||
testonly = testonly,
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
native.sh_binary(
|
||||
name = name,
|
||||
srcs = [name + "_genrule"],
|
||||
data = srcs + tools + deps,
|
||||
testonly = testonly,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def inline_sh_test(
|
||||
name,
|
||||
srcs = [],
|
||||
tools = [],
|
||||
deps = [],
|
||||
cmd = "",
|
||||
**kwargs):
|
||||
"""Bazel rule to wrap up an inline bash script in a test.
|
||||
|
||||
This is most useful as a stop-gap solution for migrating off Autotools.
|
||||
These tests are likely to be non-hermetic, with implicit system dependencies.
|
||||
|
||||
NOTE: the rule is only an internal workaround. The interface may change and
|
||||
the rule may be removed when everything is properly "Bazelified".
|
||||
|
||||
Args:
|
||||
name: the name of the inline_sh_binary.
|
||||
srcs: the files used directly by the script.
|
||||
tools: the executable tools used directly by the script. Any target used
|
||||
with rootpath/execpath/location must be declared here or in `srcs`.
|
||||
deps: a list of dependency labels that are required to run this binary.
|
||||
cmd: the inline sh command to run.
|
||||
**kwargs: other keyword arguments that are passed to sh_binary.
|
||||
https://bazel.build/reference/be/common-definitions#common-attributes)
|
||||
"""
|
||||
|
||||
native.genrule(
|
||||
name = name + "_genrule",
|
||||
srcs = srcs,
|
||||
exec_tools = tools,
|
||||
outs = [name + ".sh"],
|
||||
cmd = "cat <<'EOF' >$(OUTS)\n#!/bin/bash -exu\n%s\nEOF\n" % cmd,
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
native.sh_test(
|
||||
name = name,
|
||||
srcs = [name + "_genrule"],
|
||||
data = srcs + tools + deps,
|
||||
**kwargs
|
||||
)
|
||||
Reference in New Issue
Block a user