Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
53 changes: 53 additions & 0 deletions google3/third_party/upb/bazel/private/copts.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2009-2021, Google LLC
# All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

"""Common copts for building upb."""

_DEFAULT_CPPOPTS = []
_DEFAULT_COPTS = [
# this is a compile error in C++ clang and GNU C, but not clang C by default
"-Werror=incompatible-pointer-types",
# GCC does not seem to support the no_sanitize attribute in some places
# where we use it.
"-Wno-error=attributes",
]

_DEFAULT_CPPOPTS.extend([
"-Wextra",
# "-Wshorten-64-to-32", # not in GCC (and my Kokoro images doesn't have Clang)
"-Wno-unused-parameter",
"-Wno-long-long",
])
_DEFAULT_COPTS.extend([
"-std=c99",
"-Wall",
"-Wstrict-prototypes",
# GCC (at least) emits spurious warnings for this that cannot be fixed
# without introducing redundant initialization (with runtime cost):
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
#"-Wno-maybe-uninitialized",
])

UPB_DEFAULT_CPPOPTS = select({
"//upb:windows": [],
"//conditions:default": _DEFAULT_CPPOPTS,
}) + select({
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [],
}) + select({
"//conditions:default": [],
})

UPB_DEFAULT_COPTS = select({
"//upb:windows": [],
"//conditions:default": _DEFAULT_COPTS,
}) + select({
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [],
}) + select({
"//conditions:default": [],
})
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import sys
import re
import os
import re
import sys

INCLUDE_RE = re.compile('^#include "([^"]*)"')


def parse_include(line):
match = INCLUDE_RE.match(line)
return match.groups()[0] if match else None


class Amalgamator:

def __init__(self, h_out, c_out):
self.include_paths = ["."]
self.included = set()
Expand All @@ -53,7 +56,9 @@ def amalgamate(self, h_files, c_files):
self.output_c.write("/* Amalgamated source file */\n")
self.output_c.write('#include "%s"\n' % (self.h_out))
if self.h_out == "ruby-upb.h":
self.output_h.write("// Ruby is still using proto3 enum semantics for proto2\n")
self.output_h.write(
"// Ruby is still using proto3 enum semantics for proto2\n"
)
self.output_h.write("#define UPB_DISABLE_CLOSED_ENUM_CHECKING\n")

self.output_h.write("/* Amalgamated source file */\n")
Expand Down Expand Up @@ -103,7 +108,9 @@ def _process_include(self, line):
or include.startswith("google")
):
return False
if include and (include.endswith("port/def.inc") or include.endswith("port/undef.inc")):
if include and (
include.endswith("port/def.inc") or include.endswith("port/undef.inc")
):
# Skip, we handle this separately
return True
if include.endswith("hpp"):
Expand All @@ -124,7 +131,13 @@ def _process_include(self, line):
self.included.add(include)
self._process_file(h_file, self.output_h)
return True
raise RuntimeError("Couldn't find include: " + include + ", h_files=" + repr(self.h_files))
raise RuntimeError(
"Couldn't find include: "
+ include
+ ", h_files="
+ repr(self.h_files)
)


# ---- main ----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ upb_amalgamation = rule(
"_amalgamator": attr.label(
executable = True,
cfg = "exec",
default = "//upb/bazel:amalgamate",
default = "//bazel/private/oss:amalgamate",
),
"prefix": attr.string(
default = "",
Expand Down
2 changes: 1 addition & 1 deletion lua/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load(
"lua_proto_library",
)
load(
"//upb/bazel:build_defs.bzl",
"//upb/bazel/private:copts.bzl",
"UPB_DEFAULT_COPTS",
"UPB_DEFAULT_CPPOPTS",
)
Expand Down
2 changes: 1 addition & 1 deletion python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")
load("//python:build_targets.bzl", "build_targets")
load("//python:py_extension.bzl", "py_extension")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")

build_targets(name = "python")

Expand Down
4 changes: 2 additions & 2 deletions upb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:upb_proto_library_internal/copts.bzl", "upb_proto_library_copts")
load("//upb/bazel:amalgamation.bzl", "upb_amalgamation")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private/oss:amalgamation.bzl", "upb_amalgamation")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
7 changes: 2 additions & 5 deletions upb/conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ load(
"upb_c_proto_library",
"upb_proto_reflection_library",
)
load(
"//upb/bazel:build_defs.bzl",
"UPB_DEFAULT_COPTS",
"make_shell_script",
)
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")
load(":build_defs.bzl", "make_shell_script")

package(default_applicable_licenses = ["//:license"])

Expand Down
45 changes: 0 additions & 45 deletions upb/bazel/build_defs.bzl → upb/conformance/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,6 @@

"""Internal rules for building upb."""

_DEFAULT_CPPOPTS = []
_DEFAULT_COPTS = [
# this is a compile error in C++ clang and GNU C, but not clang C by default
"-Werror=incompatible-pointer-types",
# GCC does not seem to support the no_sanitize attribute in some places
# where we use it.
"-Wno-error=attributes",
]

_DEFAULT_CPPOPTS.extend([
"-Wextra",
# "-Wshorten-64-to-32", # not in GCC (and my Kokoro images doesn't have Clang)
"-Wno-unused-parameter",
"-Wno-long-long",
])
_DEFAULT_COPTS.extend([
"-std=c99",
"-Wall",
"-Wstrict-prototypes",
# GCC (at least) emits spurious warnings for this that cannot be fixed
# without introducing redundant initialization (with runtime cost):
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
#"-Wno-maybe-uninitialized",
])

UPB_DEFAULT_CPPOPTS = select({
"//upb:windows": [],
"//conditions:default": _DEFAULT_CPPOPTS,
}) + select({
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [],
}) + select({
"//conditions:default": [],
})

UPB_DEFAULT_COPTS = select({
"//upb:windows": [],
"//conditions:default": _DEFAULT_COPTS,
}) + select({
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [],
}) + select({
"//conditions:default": [],
})

runfiles_init = """\
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
Expand Down
2 changes: 1 addition & 1 deletion upb/hash/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/json/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load(
"upb_c_proto_library",
"upb_proto_reflection_library",
)
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/lex/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/mem/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/message/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load(
"upb_c_proto_library",
"upb_proto_reflection_library",
)
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/mini_descriptor/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load(
"//upb/bazel:build_defs.bzl",
"//bazel/private:copts.bzl",
"UPB_DEFAULT_COPTS",
"UPB_DEFAULT_CPPOPTS",
)
Expand Down
2 changes: 1 addition & 1 deletion upb/mini_table/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load(
"upb_minitable_proto_library",
)
load(
"//upb/bazel:build_defs.bzl",
"//bazel/private:copts.bzl",
"UPB_DEFAULT_COPTS",
)
load(
Expand Down
2 changes: 1 addition & 1 deletion upb/port/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://developers.google.com/open-source/licenses/bsd

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/reflection/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")
load(
"//editions:defaults.bzl",
"compile_edition_defaults",
"embed_edition_defaults",
)
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load(
"//upb/cmake:build_defs.bzl",
"staleness_test",
Expand Down
2 changes: 1 addition & 1 deletion upb/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load(
"upb_proto_reflection_library",
)
load(
"//upb/bazel:build_defs.bzl",
"//bazel/private:copts.bzl",
"UPB_DEFAULT_CPPOPTS",
)

Expand Down
2 changes: 1 addition & 1 deletion upb/text/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/wire/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_CPPOPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/wire/decode_fast/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_COPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb/wire/test_util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://developers.google.com/open-source/licenses/bsd

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_CPPOPTS")

package(default_applicable_licenses = ["//:license"])

Expand Down
2 changes: 1 addition & 1 deletion upb_generator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://developers.google.com/open-source/licenses/bsd

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_CPPOPTS")
load(
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_library",
Expand Down
4 changes: 2 additions & 2 deletions upb_generator/c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# https://developers.google.com/open-source/licenses/bsd

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
load(
"//upb/bazel:build_defs.bzl",
"//bazel/private:copts.bzl",
"UPB_DEFAULT_CPPOPTS",
)
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
load("//upb_generator:bootstrap_compiler.bzl", "bootstrap_cc_binary")

package(default_applicable_licenses = ["//:license"])
Expand Down
2 changes: 1 addition & 1 deletion upb_generator/minitable/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# https://developers.google.com/open-source/licenses/bsd

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel/private:copts.bzl", "UPB_DEFAULT_CPPOPTS")
load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_CPPOPTS")
load(
"//upb_generator:bootstrap_compiler.bzl",
"bootstrap_cc_binary",
Expand Down
Loading
Loading