Remove workaround for Bazel C/C++ issue https://github.com/bazelbuild/bazel/pull/23792 is available in Bazel 7.4.0 or later. [0] has long set a minimum Bazel version of Bazel 7 and, as of [1], Envoy has since caught up. We should be able to rely on this now, and remove the workaround. This doesn't enable parse_headers, but clears the Bazel blocker. Update-Note: BoringSSL now requires Bazel 7.4.0 or later. [0] https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md [1] https://github.com/envoyproxy/envoy/pull/41209 Bug: 399387924 Change-Id: Icf2278d9fe8f0f38f353ce87dd227bd4bf0ac95c Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76787 Commit-Queue: David Benjamin <davidben@google.com> Auto-Submit: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/BUILD.bazel b/BUILD.bazel index b7dc359..c8c4b16 100644 --- a/BUILD.bazel +++ b/BUILD.bazel
@@ -47,10 +47,8 @@ package( default_applicable_licenses = [":license"], - # Disable the parse_headers feature. It does not work well in C right now. - # See https://github.com/bazelbuild/bazel/issues/23460 for details. When - # that is fixed, if enabled, we likely also need to rename some headers to - # .inc per + # TODO(crbug.com/399387924): Enable parse_headers feature. Not all of our + # headers are self-contained. We may need to rename or fix some of them per # https://google.github.io/styleguide/cppguide.html#Self_contained_Headers features = ["-parse_headers"], )
diff --git a/util/util.bzl b/util/util.bzl index 35c14a2..6b5b750 100644 --- a/util/util.bzl +++ b/util/util.bzl
@@ -33,18 +33,18 @@ "-fno-strict-aliasing", ] -gcc_copts_cxx = [ +gcc_cxxopts = [ "-Wmissing-declarations", "-Wnon-virtual-dtor", ] -gcc_copts_c = [ +gcc_conlyopts = [ "-Wmissing-prototypes", "-Wold-style-definition", "-Wstrict-prototypes", ] -boringssl_copts_common = select({ +boringssl_copts = select({ # This condition and the asm_srcs_used one below must be kept in sync. "@platforms//os:windows": ["-DOPENSSL_NO_ASM"], "//conditions:default": [], @@ -72,18 +72,18 @@ # We do not specify the C++ version here because Bazel expects C++ version # to come from the top-level toolchain. The concern is that different C++ # versions may cause ABIs, notably Abseil's, to change. -boringssl_copts_cxx = boringssl_copts_common + select({ +boringssl_cxxopts = select({ "@platforms//os:windows": [], - "//conditions:default": gcc_copts_cxx, + "//conditions:default": gcc_cxxopts, }) # We specify the C version because Bazel projects often do not remember to # specify the C version. We do not expect ABIs to vary by C versions, at least # for our code or the headers we include, so configure the C version inside the # library. If Bazel's C/C++ version handling improves, we may reconsider this. -boringssl_copts_c = boringssl_copts_common + select({ +boringssl_conlyopts = select({ "@platforms//os:windows": ["/std:c11"], - "//conditions:default": ["-std=c11"] + gcc_copts_c, + "//conditions:default": ["-std=c11"] + gcc_conlyopts, }) def linkstatic_kwargs(linkstatic): @@ -96,59 +96,6 @@ kwargs["linkstatic"] = linkstatic return kwargs -def handle_mixed_c_cxx( - name, - copts, - deps, - internal_hdrs, - includes, - linkopts, - linkstatic, - srcs, - testonly, - alwayslink): - """ - Works around https://github.com/bazelbuild/bazel/issues/22041. Determines - whether a target contains C, C++, or both. If the target is multi-language, - the C sources are split into a separate library. Returns a tuple of updated - (copts, deps, srcs) to apply. - """ - has_c, has_cxx = False, False - for src in srcs: - if src.endswith(".c"): - has_c = True - elif src.endswith(".cc"): - has_cxx = True - - # If a target has both C and C++, we need to split it in two. - if has_c and has_cxx: - # Pull the C++ files out. - srcs_cxx = [src for src in srcs if src.endswith(".cc") or src.endswith(".h")] - name_cxx = name + "_cxx" - cc_library( - name = name_cxx, - srcs = srcs_cxx + internal_hdrs, - copts = copts + boringssl_copts_cxx, - includes = includes, - linkopts = linkopts, - deps = deps, - testonly = testonly, - alwayslink = alwayslink, - **linkstatic_kwargs(linkstatic) - ) - - # Build the remainder as a C-only target. - deps = deps + [":" + name_cxx] - srcs = [src for src in srcs if not src.endswith(".cc")] - has_cxx = False - - if has_c: - copts = copts + boringssl_copts_c - else: - copts = copts + boringssl_copts_cxx - - return copts, deps, srcs - def handle_asm_srcs(asm_srcs): if not asm_srcs: return [] @@ -194,26 +141,6 @@ testonly = False, alwayslink = False, visibility = []): - copts, deps, srcs = handle_mixed_c_cxx( - name = name, - copts = copts, - deps = deps, - internal_hdrs = hdrs + internal_hdrs, - includes = includes, - linkopts = linkopts, - # Ideally we would set linkstatic = True to statically link the helper - # library into main cc_library. But Bazel interprets linkstatic such - # that, if A(test, linkshared) -> B(library) -> C(library, linkstatic), - # C will be statically linked into A, not B. This is probably to avoid - # diamond dependency problems but means linkstatic does not help us make - # this function transparent. Instead, just pass along the linkstatic - # nature of the main library. - linkstatic = linkstatic, - srcs = srcs, - testonly = testonly, - alwayslink = alwayslink, - ) - # BoringSSL's notion of internal headers are slightly different from # Bazel's. libcrypto's internal headers may be used by libssl, but they # cannot be used outside the library. To express this, we make separate @@ -226,7 +153,9 @@ name = name_internal, srcs = srcs + handle_asm_srcs(asm_srcs), hdrs = hdrs + internal_hdrs, - copts = copts, + copts = copts + boringssl_copts, + conlyopts = boringssl_conlyopts, + cxxopts = boringssl_cxxopts, includes = includes, linkopts = linkopts, deps = deps, @@ -254,28 +183,12 @@ deps = [], testonly = False, visibility = []): - copts, deps, srcs = handle_mixed_c_cxx( - name = name, - copts = copts, - deps = deps, - internal_hdrs = [], - includes = includes, - # If it weren't for https://github.com/bazelbuild/bazel/issues/22041, - # the split library be part of `srcs` and linked statically. Set - # linkstatic to match. - linkstatic = True, - linkopts = linkopts, - srcs = srcs, - testonly = testonly, - # TODO(davidben): Should this be alwayslink = True? How does Bazel treat - # the real cc_binary.srcs? - alwayslink = False, - ) - cc_binary( name = name, srcs = srcs + handle_asm_srcs(asm_srcs), - copts = copts, + copts = copts + boringssl_copts, + conlyopts = boringssl_conlyopts, + cxxopts = boringssl_cxxopts, includes = includes, linkopts = linkopts, deps = deps, @@ -296,30 +209,14 @@ linkstatic = None, deps = [], shard_count = None): - copts, deps, srcs = handle_mixed_c_cxx( - name = name, - copts = copts, - deps = deps, - internal_hdrs = [], - includes = includes, - # If it weren't for https://github.com/bazelbuild/bazel/issues/22041, - # the split library be part of `srcs` and linked statically. Set - # linkstatic to match. - linkstatic = True, - linkopts = linkopts, - srcs = srcs, - testonly = True, - # If any sources get extracted, they must always be linked, otherwise - # tests will be dropped. - alwayslink = True, - ) - cc_test( name = name, data = data, deps = deps, srcs = srcs + handle_asm_srcs(asm_srcs), - copts = copts, + copts = copts + boringssl_copts, + conlyopts = boringssl_conlyopts, + cxxopts = boringssl_cxxopts, includes = includes, linkopts = linkopts, shard_count = shard_count,