[Bazel] Move C++ build-related logic into //build_defs (#9921)
These are all "toolchain-y" things, like copts, link_opts, and config_settings. These are very different from what is in //toolchain, though, so I chose the somewhat common name build_defs for the package. For now, I am only using this package for purely internal things. (Most public "defs"-type things should come from rules_proto/rules_cc, anyhow.)pull/9928/head
parent
e305932431
commit
52655b1f5e
9 changed files with 239 additions and 264 deletions
@ -0,0 +1,159 @@ |
||||
# 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", |
||||
) |
||||
|
||||
# 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", |
||||
}, |
||||
) |
||||
|
||||
# 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__"], |
||||
) |
@ -0,0 +1,40 @@ |
||||
# C++ compile/link options for Protobuf. |
||||
|
||||
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", |
||||
], |
||||
}) |
||||
|
||||
# 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", |
||||
], |
||||
}) |
Loading…
Reference in new issue