chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:29:29 +08:00
commit f52cf32e56
1718 changed files with 366293 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
refresh_compile_commands(
name = "brpc_compdb",
# Specify the targets of interest.
# For example, specify a dict of targets and their arguments:
targets = {
"//:brpc": "",
},
# For more details, feel free to look into refresh_compile_commands.bzl if you want.
)
+152
View File
@@ -0,0 +1,152 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@bazel_skylib//lib:selects.bzl", "selects")
licenses(["notice"]) # Apache v2
selects.config_setting_group(
name = "brpc_with_glog",
match_any = [
":brpc_with_glog_deprecated_flag",
":brpc_with_glog_new_flag",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_glog_deprecated_flag",
define_values = {"with_glog": "true"},
)
config_setting(
name = "brpc_with_glog_new_flag",
define_values = {"BRPC_WITH_GLOG": "true"},
)
selects.config_setting_group(
name = "brpc_with_mesalink",
match_any = [
":brpc_with_mesalink_deprecated_flag",
":brpc_with_mesalink_new_flag",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_mesalink_deprecated_flag",
define_values = {"with_mesalink": "true"},
)
config_setting(
name = "brpc_with_mesalink_new_flag",
define_values = {"BRPC_WITH_MESALINK": "true"},
)
selects.config_setting_group(
name = "brpc_with_thrift",
match_any = [
":brpc_with_thrift_deprecated_flag",
":brpc_with_thrift_new_flag",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_thrift_legacy_version",
define_values = {"BRPC_WITH_THRIFT_LEGACY_VERSION": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_thrift_deprecated_flag",
define_values = {"with_thrift": "true"},
)
config_setting(
name = "brpc_with_thrift_new_flag",
define_values = {"BRPC_WITH_THRIFT": "true"},
)
config_setting(
name = "brpc_build_for_unittest",
define_values = {"BRPC_BUILD_FOR_UNITTEST": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_sse42",
define_values = {"BRPC_WITH_SSE42": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "darwin",
values = {"cpu": "darwin"},
visibility = ["//:__subpkgs__"],
)
config_setting(
name = "brpc_with_rdma",
define_values = {"BRPC_WITH_RDMA": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_boringssl",
define_values = {"BRPC_WITH_BORINGSSL": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_debug_bthread_sche_safety",
define_values = {"with_debug_bthread_sche_safety": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_debug_lock",
define_values = {"with_debug_lock": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_asan",
define_values = {"with_asan": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_bthread_tracer",
constraint_values = [
"@platforms//cpu:x86_64",
],
define_values = {
"with_bthread_tracer": "true",
},
visibility = ["//visibility:public"],
)
config_setting(
name = "brpc_with_no_pthread_mutex_hook",
define_values = {"BRPC_WITH_NO_PTHREAD_MUTEX_HOOK": "true"},
visibility = ["//visibility:public"],
)
config_setting(
name = "with_babylon_counter",
define_values = {"with_babylon_counter": "true"},
visibility = ["//visibility:public"],
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+93
View File
@@ -0,0 +1,93 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
genrule(
name = "crc32c_config_h",
srcs = ["src/crc32c_config.h.in"],
outs = ["crc32c/crc32c_config.h"],
cmd = """
sed -e 's/#cmakedefine01/#define/' \
""" + select({
"@//bazel/config:brpc_with_sse42": """-e 's/ HAVE_SSE42/ HAVE_SSE42 1/' \
""",
"//conditions:default": """-e 's/ HAVE_SSE42/ HAVE_SSE42 0/' \
""",
}) + select({
"@//bazel/config:brpc_with_glog": """-e 's/ CRC32C_TESTS_BUILT_WITH_GLOG/ CRC32C_TESTS_BUILT_WITH_GLOG 1/' \
""",
"//conditions:default": """-e 's/ CRC32C_TESTS_BUILT_WITH_GLOG/ CRC32C_TESTS_BUILT_WITH_GLOG 0/' \
""",
}) + """-e 's/ BYTE_ORDER_BIG_ENDIAN/ BYTE_ORDER_BIG_ENDIAN 0/' \
-e 's/ HAVE_BUILTIN_PREFETCH/ HAVE_BUILTIN_PREFETCH 0/' \
-e 's/ HAVE_MM_PREFETCH/ HAVE_MM_PREFETCH 0/' \
-e 's/ HAVE_ARM64_CRC32C/ HAVE_ARM64_CRC32C 0/' \
-e 's/ HAVE_STRONG_GETAUXVAL/ HAVE_STRONG_GETAUXVAL 0/' \
-e 's/ HAVE_WEAK_GETAUXVAL/ HAVE_WEAK_GETAUXVAL 0/' \
< $< > $@
""",
)
cc_library(
name = "crc32c",
srcs = [
"src/crc32c.cc",
"src/crc32c_arm64.cc",
"src/crc32c_arm64.h",
"src/crc32c_arm64_check.h",
"src/crc32c_internal.h",
"src/crc32c_portable.cc",
"src/crc32c_prefetch.h",
"src/crc32c_read_le.h",
"src/crc32c_round_up.h",
"src/crc32c_sse42.cc",
"src/crc32c_sse42.h",
"src/crc32c_sse42_check.h",
":crc32c_config_h",
],
hdrs = [
"include/crc32c/crc32c.h",
],
copts = select({
"@//bazel/config:brpc_with_sse42": ["-msse4.2"],
"//conditions:default": [],
}),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
cc_test(
name = "crc32c_test",
srcs = [
"src/crc32c_arm64_unittest.cc",
"src/crc32c_extend_unittests.h",
"src/crc32c_portable_unittest.cc",
"src/crc32c_prefetch_unittest.cc",
"src/crc32c_read_le_unittest.cc",
"src/crc32c_round_up_unittest.cc",
"src/crc32c_sse42_unittest.cc",
"src/crc32c_test_main.cc",
"src/crc32c_unittest.cc",
],
deps = [
":crc32c",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
] + select({
"@//bazel/config:brpc_with_glog": ["@com_github_google_glog//:glog"],
"//conditions:default": [],
}),
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+59
View File
@@ -0,0 +1,59 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
cmake(
name = "event",
cache_entries = {
"EVENT__DISABLE_BENCHMARK": "ON",
"EVENT__DISABLE_TESTS": "ON",
"EVENT__DISABLE_SAMPLES": "ON",
"EVENT__LIBRARY_TYPE": "STATIC",
"OPENSSL_ROOT_DIR": "$$EXT_BUILD_DEPS$$/openssl",
},
generate_args = ["-GNinja"],
lib_source = ":all_srcs",
linkopts = [
"-pthread",
],
out_static_libs = select({
"@platforms//os:windows": [
"event.lib",
"event_core.lib",
"event_extra.lib",
"event_openssl.lib",
"event_pthreads.lib",
],
"//conditions:default": [
"libevent.a",
"libevent_core.a",
"libevent_extra.a",
"libevent_openssl.a",
"libevent_pthreads.a",
],
}),
visibility = ["//visibility:public"],
deps = [
# Zlib is only used for testing.
"@openssl//:crypto",
"@openssl//:ssl",
],
)
@@ -0,0 +1,36 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
index 421f1e0..a363141 100755
--- a/src/glog/logging.h.in
+++ b/src/glog/logging.h.in
@@ -1334,7 +1334,7 @@ class GOOGLE_GLOG_DLL_DECL LogStreamBuf : public std::streambuf {
}
// This effectively ignores overflow.
- int_type overflow(int_type ch) {
+ int_type overflow(int_type ch) override {
return ch;
}
@@ -1862,7 +1862,7 @@ class GOOGLE_GLOG_DLL_DECL NullStreamFatal : public NullStream {
NullStreamFatal() { }
NullStreamFatal(const char* file, int line, const CheckOpString& result) :
NullStream(file, line, result) { }
- @ac_cv___attribute___noreturn@ ~NullStreamFatal() throw () { _exit(1); }
+ @ac_cv___attribute___noreturn@ ~NullStreamFatal() throw () override { _exit(1); }
};
// Install a signal handler that will dump signal information and a stack
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+21
View File
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
exports_files(
[
"port_config.h",
"port.h",
],
)
+72
View File
@@ -0,0 +1,72 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
copy_file(
name = "port_config_h",
src = "@//bazel/third_party/leveldb:port_config.h",
out = "port/port_config.h",
allow_symlink = True,
)
copy_file(
name = "port_h",
src = "@//bazel/third_party/leveldb:port.h",
out = "port/port.h",
allow_symlink = True,
)
cc_library(
name = "leveldb",
srcs = glob(
[
"db/**/*.cc",
"db/**/*.h",
"helpers/**/*.cc",
"helpers/**/*.h",
"port/**/*.cc",
"port/**/*.h",
"table/**/*.cc",
"table/**/*.h",
"util/**/*.cc",
"util/**/*.h",
],
exclude = [
"**/*_test.cc",
"**/testutil.*",
"**/*_bench.cc",
"**/*_windows*",
"db/leveldbutil.cc",
],
),
hdrs = glob(
["include/**/*.h"],
exclude = ["doc/**"],
) + [
":port_h",
":port_config_h",
],
includes = [
".",
"include",
],
visibility = ["//visibility:public"],
deps = [
"@com_github_google_crc32c//:crc32c",
"@com_github_google_snappy//:snappy",
],
)
+34
View File
@@ -0,0 +1,34 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#ifndef STORAGE_LEVELDB_PORT_PORT_H_
#define STORAGE_LEVELDB_PORT_PORT_H_
#include <string.h>
#define LEVELDB_HAS_PORT_CONFIG_H 1
// Include the appropriate platform specific file below. If you are
// porting to a new platform, see "port_example.h" for documentation
// of what the new port_<platform>.h file must provide.
#include "port/port_stdcxx.h"
#endif // STORAGE_LEVELDB_PORT_PORT_H_
+38
View File
@@ -0,0 +1,38 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
// Copyright 2017 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#ifndef STORAGE_LEVELDB_PORT_PORT_CONFIG_H_
#define STORAGE_LEVELDB_PORT_PORT_CONFIG_H_
// Define to 1 if you have a definition for fdatasync() in <unistd.h>.
#define HAVE_FUNC_FDATASYNC 1
// Define to 1 if you have Google CRC32C.
#define HAVE_CRC32C 1
// Define to 1 if you have Google Snappy.
#define HAVE_SNAPPY 1
// Define to 1 if your processor stores words with the most significant byte
// first (like Motorola and SPARC, unlike Intel and VAX).
#define LEVELDB_IS_BIG_ENDIAN 0
#endif // STORAGE_LEVELDB_PORT_PORT_CONFIG_H_
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+165
View File
@@ -0,0 +1,165 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copied from https://github.com/bazelbuild/rules_foreign_cc/blob/0.7.0/examples/third_party/openssl/BUILD.openssl.bazel
#
# Modifications:
# 1. Create alias `ssl` & `crypto` to align with boringssl.
# 2. Build with `@com_github_madler_zlib//:zlib`.
# 3. Add more configure options coming from debian openssl package configurations.
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "configure_make_variant")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
CONFIGURE_OPTIONS = [
"no-idea",
"no-mdc2",
"no-rc5",
"no-ssl3",
"no-ssl3-method",
"enable-rfc3779",
"enable-cms",
"no-capieng",
"enable-ec_nistp_64_gcc_128",
"--with-zlib-include=$$EXT_BUILD_DEPS$$",
"--with-zlib-lib=$$EXT_BUILD_DEPS$$",
# https://stackoverflow.com/questions/36220341/struct-in6-addr-has-no-member-named-s6-addr32-with-ansi
"-D_DEFAULT_SOURCE=1",
"-DPEDANTIC",
]
LIB_NAME = "openssl"
MAKE_TARGETS = [
"build_libs",
"install_dev",
]
config_setting(
name = "msvc_compiler",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "msvc-cl",
},
visibility = ["//visibility:public"],
)
alias(
name = "ssl",
actual = "openssl",
visibility = ["//visibility:public"],
)
alias(
name = "crypto",
actual = "openssl",
visibility = ["//visibility:public"],
)
alias(
name = "openssl",
actual = select({
":msvc_compiler": "openssl_msvc",
"//conditions:default": "openssl_default",
}),
visibility = ["//visibility:public"],
)
configure_make_variant(
name = "openssl_msvc",
build_data = [
"@nasm//:nasm",
"@perl//:perl",
],
configure_command = "Configure",
configure_in_place = True,
configure_options = CONFIGURE_OPTIONS + [
"VC-WIN64A",
# Unset Microsoft Assembler (MASM) flags set by built-in MSVC toolchain,
# as NASM is unsed to build OpenSSL rather than MASM
"ASFLAGS=\" \"",
],
configure_prefix = "$PERL",
env = {
# The Zi flag must be set otherwise OpenSSL fails to build due to missing .pdb files
"CFLAGS": "-Zi",
"PATH": "$$(dirname $(execpath @nasm//:nasm)):$$PATH",
"PERL": "$(execpath @perl//:perl)",
},
lib_name = LIB_NAME,
lib_source = ":all_srcs",
out_static_libs = [
"libssl.lib",
"libcrypto.lib",
],
targets = MAKE_TARGETS,
toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain",
deps = [
"@com_github_madler_zlib//:zlib",
],
)
# https://wiki.openssl.org/index.php/Compilation_and_Installation
configure_make(
name = "openssl_default",
configure_command = "config",
configure_in_place = True,
configure_options = CONFIGURE_OPTIONS,
env = select({
"@platforms//os:macos": {
"AR": "",
"PERL": "$$EXT_BUILD_ROOT$$/$(PERL)",
},
"//conditions:default": {
"PERL": "$$EXT_BUILD_ROOT$$/$(PERL)",
},
}),
lib_name = LIB_NAME,
lib_source = ":all_srcs",
# Note that for Linux builds, libssl must come before libcrypto on the linker command-line.
# As such, libssl must be listed before libcrypto
out_static_libs = [
"libssl.a",
"libcrypto.a",
],
targets = MAKE_TARGETS,
toolchains = ["@rules_perl//:current_toolchain"],
deps = [
"@com_github_madler_zlib//:zlib",
],
)
filegroup(
name = "gen_dir",
srcs = [":openssl"],
output_group = "gen_dir",
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+498
View File
@@ -0,0 +1,498 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2008 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Copied from https://github.com/protocolbuffers/protobuf/blob/v3.19.1/BUILD
#
# Modifications:
# 1. Remove all non-cxx rules.
# 2. Remove android support.
# 3. zlib use @com_github_madler_zlib//:zlib
# Bazel (https://bazel.build/) BUILD file for Protobuf.
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load(":compiler_config_setting.bzl", "create_compiler_config_setting")
load(
":protobuf.bzl",
"adapt_proto_library",
)
licenses(["notice"])
exports_files(["LICENSE"])
################################################################################
# build configuration
################################################################################
################################################################################
# ZLIB configuration
################################################################################
ZLIB_DEPS = ["@com_github_madler_zlib//:zlib"]
################################################################################
# Protobuf Runtime Library
################################################################################
MSVC_COPTS = [
"/wd4018", # -Wno-sign-compare
"/wd4065", # switch statement contains 'default' but no 'case' labels
"/wd4146", # unary minus operator applied to unsigned type, result still unsigned
"/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.
]
COPTS = select({
":msvc": MSVC_COPTS,
"//conditions:default": [
"-DHAVE_ZLIB",
"-Wmissing-field-initializers",
"-Woverloaded-virtual",
"-Wno-sign-compare",
],
})
create_compiler_config_setting(
name = "msvc",
value = "msvc-cl",
visibility = [
# Public, but Protobuf only visibility.
"//:__subpackages__",
],
)
# Android and MSVC builds do not need to link in a separate pthread library.
LINK_OPTS = select({
":msvc": [
# Suppress linker warnings about files with no symbols defined.
"-ignore:4221",
],
"//conditions:default": [
"-lpthread",
"-lm",
],
})
cc_library(
name = "protobuf_lite",
srcs = [
# AUTOGEN(protobuf_lite_srcs)
"src/google/protobuf/any_lite.cc",
"src/google/protobuf/arena.cc",
"src/google/protobuf/arenastring.cc",
"src/google/protobuf/extension_set.cc",
"src/google/protobuf/generated_enum_util.cc",
"src/google/protobuf/generated_message_table_driven_lite.cc",
"src/google/protobuf/generated_message_tctable_lite.cc",
"src/google/protobuf/generated_message_util.cc",
"src/google/protobuf/implicit_weak_message.cc",
"src/google/protobuf/inlined_string_field.cc",
"src/google/protobuf/io/coded_stream.cc",
"src/google/protobuf/io/io_win32.cc",
"src/google/protobuf/io/strtod.cc",
"src/google/protobuf/io/zero_copy_stream.cc",
"src/google/protobuf/io/zero_copy_stream_impl.cc",
"src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
"src/google/protobuf/map.cc",
"src/google/protobuf/message_lite.cc",
"src/google/protobuf/parse_context.cc",
"src/google/protobuf/repeated_field.cc",
"src/google/protobuf/repeated_ptr_field.cc",
"src/google/protobuf/stubs/bytestream.cc",
"src/google/protobuf/stubs/common.cc",
"src/google/protobuf/stubs/int128.cc",
"src/google/protobuf/stubs/status.cc",
"src/google/protobuf/stubs/statusor.cc",
"src/google/protobuf/stubs/stringpiece.cc",
"src/google/protobuf/stubs/stringprintf.cc",
"src/google/protobuf/stubs/structurally_valid.cc",
"src/google/protobuf/stubs/strutil.cc",
"src/google/protobuf/stubs/time.cc",
"src/google/protobuf/wire_format_lite.cc",
],
hdrs = glob([
"src/google/protobuf/**/*.h",
"src/google/protobuf/**/*.inc",
]),
copts = COPTS,
includes = ["src/"],
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
)
PROTOBUF_DEPS = select({
":msvc": [],
"//conditions:default": ZLIB_DEPS,
})
cc_library(
name = "protobuf",
srcs = [
# AUTOGEN(protobuf_srcs)
"src/google/protobuf/any.cc",
"src/google/protobuf/any.pb.cc",
"src/google/protobuf/api.pb.cc",
"src/google/protobuf/compiler/importer.cc",
"src/google/protobuf/compiler/parser.cc",
"src/google/protobuf/descriptor.cc",
"src/google/protobuf/descriptor.pb.cc",
"src/google/protobuf/descriptor_database.cc",
"src/google/protobuf/duration.pb.cc",
"src/google/protobuf/dynamic_message.cc",
"src/google/protobuf/empty.pb.cc",
"src/google/protobuf/extension_set_heavy.cc",
"src/google/protobuf/field_mask.pb.cc",
"src/google/protobuf/generated_message_bases.cc",
"src/google/protobuf/generated_message_reflection.cc",
"src/google/protobuf/generated_message_table_driven.cc",
"src/google/protobuf/generated_message_tctable_full.cc",
"src/google/protobuf/io/gzip_stream.cc",
"src/google/protobuf/io/printer.cc",
"src/google/protobuf/io/tokenizer.cc",
"src/google/protobuf/map_field.cc",
"src/google/protobuf/message.cc",
"src/google/protobuf/reflection_ops.cc",
"src/google/protobuf/service.cc",
"src/google/protobuf/source_context.pb.cc",
"src/google/protobuf/struct.pb.cc",
"src/google/protobuf/stubs/substitute.cc",
"src/google/protobuf/text_format.cc",
"src/google/protobuf/timestamp.pb.cc",
"src/google/protobuf/type.pb.cc",
"src/google/protobuf/unknown_field_set.cc",
"src/google/protobuf/util/delimited_message_util.cc",
"src/google/protobuf/util/field_comparator.cc",
"src/google/protobuf/util/field_mask_util.cc",
"src/google/protobuf/util/internal/datapiece.cc",
"src/google/protobuf/util/internal/default_value_objectwriter.cc",
"src/google/protobuf/util/internal/error_listener.cc",
"src/google/protobuf/util/internal/field_mask_utility.cc",
"src/google/protobuf/util/internal/json_escaping.cc",
"src/google/protobuf/util/internal/json_objectwriter.cc",
"src/google/protobuf/util/internal/json_stream_parser.cc",
"src/google/protobuf/util/internal/object_writer.cc",
"src/google/protobuf/util/internal/proto_writer.cc",
"src/google/protobuf/util/internal/protostream_objectsource.cc",
"src/google/protobuf/util/internal/protostream_objectwriter.cc",
"src/google/protobuf/util/internal/type_info.cc",
"src/google/protobuf/util/internal/utility.cc",
"src/google/protobuf/util/json_util.cc",
"src/google/protobuf/util/message_differencer.cc",
"src/google/protobuf/util/time_util.cc",
"src/google/protobuf/util/type_resolver_util.cc",
"src/google/protobuf/wire_format.cc",
"src/google/protobuf/wrappers.pb.cc",
],
hdrs = glob([
"src/**/*.h",
"src/**/*.inc",
]),
copts = COPTS,
includes = ["src/"],
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [":protobuf_lite"] + PROTOBUF_DEPS,
)
# This provides just the header files for use in projects that need to build
# shared libraries for dynamic loading. This target is available until Bazel
# adds native support for such use cases.
# TODO(keveman): Remove this target once the support gets added to Bazel.
cc_library(
name = "protobuf_headers",
hdrs = glob([
"src/**/*.h",
"src/**/*.inc",
]),
includes = ["src/"],
visibility = ["//visibility:public"],
)
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
"any": ("src/google/protobuf/any.proto", []),
"api": (
"src/google/protobuf/api.proto",
[
"source_context",
"type",
],
),
"compiler_plugin": (
"src/google/protobuf/compiler/plugin.proto",
["descriptor"],
),
"descriptor": ("src/google/protobuf/descriptor.proto", []),
"duration": ("src/google/protobuf/duration.proto", []),
"empty": ("src/google/protobuf/empty.proto", []),
"field_mask": ("src/google/protobuf/field_mask.proto", []),
"source_context": ("src/google/protobuf/source_context.proto", []),
"struct": ("src/google/protobuf/struct.proto", []),
"timestamp": ("src/google/protobuf/timestamp.proto", []),
"type": (
"src/google/protobuf/type.proto",
[
"any",
"source_context",
],
),
"wrappers": ("src/google/protobuf/wrappers.proto", []),
}
WELL_KNOWN_PROTOS = [value[0] for value in WELL_KNOWN_PROTO_MAP.values()]
LITE_WELL_KNOWN_PROTO_MAP = {
"any": ("src/google/protobuf/any.proto", []),
"api": (
"src/google/protobuf/api.proto",
[
"source_context",
"type",
],
),
"duration": ("src/google/protobuf/duration.proto", []),
"empty": ("src/google/protobuf/empty.proto", []),
"field_mask": ("src/google/protobuf/field_mask.proto", []),
"source_context": ("src/google/protobuf/source_context.proto", []),
"struct": ("src/google/protobuf/struct.proto", []),
"timestamp": ("src/google/protobuf/timestamp.proto", []),
"type": (
"src/google/protobuf/type.proto",
[
"any",
"source_context",
],
),
"wrappers": ("src/google/protobuf/wrappers.proto", []),
}
LITE_WELL_KNOWN_PROTOS = [value[0] for value in LITE_WELL_KNOWN_PROTO_MAP.values()]
filegroup(
name = "well_known_protos",
srcs = WELL_KNOWN_PROTOS,
visibility = ["//visibility:public"],
)
filegroup(
name = "lite_well_known_protos",
srcs = LITE_WELL_KNOWN_PROTOS,
visibility = ["//visibility:public"],
)
adapt_proto_library(
name = "cc_wkt_protos_genproto",
visibility = ["//visibility:public"],
deps = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
)
cc_library(
name = "cc_wkt_protos",
deprecation = "Only for backward compatibility. Do not use.",
visibility = ["//visibility:public"],
)
################################################################################
# Well Known Types Proto Library Rules
#
# These proto_library rules can be used with one of the language specific proto
# library rules i.e. java_proto_library:
#
# java_proto_library(
# name = "any_java_proto",
# deps = ["@com_google_protobuf//:any_proto],
# )
################################################################################
[proto_library(
name = proto[0] + "_proto",
srcs = [proto[1][0]],
strip_import_prefix = "src",
visibility = ["//visibility:public"],
deps = [dep + "_proto" for dep in proto[1][1]],
) for proto in WELL_KNOWN_PROTO_MAP.items()]
[native_cc_proto_library(
name = proto + "_cc_proto",
visibility = ["//visibility:private"],
deps = [proto + "_proto"],
) for proto in WELL_KNOWN_PROTO_MAP.keys()]
################################################################################
# Protocol Buffers Compiler
################################################################################
cc_library(
name = "protoc_lib",
srcs = [
# AUTOGEN(protoc_lib_srcs)
"src/google/protobuf/compiler/code_generator.cc",
"src/google/protobuf/compiler/command_line_interface.cc",
"src/google/protobuf/compiler/cpp/cpp_enum.cc",
"src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
"src/google/protobuf/compiler/cpp/cpp_extension.cc",
"src/google/protobuf/compiler/cpp/cpp_field.cc",
"src/google/protobuf/compiler/cpp/cpp_file.cc",
"src/google/protobuf/compiler/cpp/cpp_generator.cc",
"src/google/protobuf/compiler/cpp/cpp_helpers.cc",
"src/google/protobuf/compiler/cpp/cpp_map_field.cc",
"src/google/protobuf/compiler/cpp/cpp_message.cc",
"src/google/protobuf/compiler/cpp/cpp_message_field.cc",
"src/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc",
"src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc",
"src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
"src/google/protobuf/compiler/cpp/cpp_service.cc",
"src/google/protobuf/compiler/cpp/cpp_string_field.cc",
"src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
"src/google/protobuf/compiler/csharp/csharp_enum.cc",
"src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
"src/google/protobuf/compiler/csharp/csharp_field_base.cc",
"src/google/protobuf/compiler/csharp/csharp_generator.cc",
"src/google/protobuf/compiler/csharp/csharp_helpers.cc",
"src/google/protobuf/compiler/csharp/csharp_map_field.cc",
"src/google/protobuf/compiler/csharp/csharp_message.cc",
"src/google/protobuf/compiler/csharp/csharp_message_field.cc",
"src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
"src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
"src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
"src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
"src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
"src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
"src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
"src/google/protobuf/compiler/java/java_context.cc",
"src/google/protobuf/compiler/java/java_doc_comment.cc",
"src/google/protobuf/compiler/java/java_enum.cc",
"src/google/protobuf/compiler/java/java_enum_field.cc",
"src/google/protobuf/compiler/java/java_enum_field_lite.cc",
"src/google/protobuf/compiler/java/java_enum_lite.cc",
"src/google/protobuf/compiler/java/java_extension.cc",
"src/google/protobuf/compiler/java/java_extension_lite.cc",
"src/google/protobuf/compiler/java/java_field.cc",
"src/google/protobuf/compiler/java/java_file.cc",
"src/google/protobuf/compiler/java/java_generator.cc",
"src/google/protobuf/compiler/java/java_generator_factory.cc",
"src/google/protobuf/compiler/java/java_helpers.cc",
"src/google/protobuf/compiler/java/java_kotlin_generator.cc",
"src/google/protobuf/compiler/java/java_map_field.cc",
"src/google/protobuf/compiler/java/java_map_field_lite.cc",
"src/google/protobuf/compiler/java/java_message.cc",
"src/google/protobuf/compiler/java/java_message_builder.cc",
"src/google/protobuf/compiler/java/java_message_builder_lite.cc",
"src/google/protobuf/compiler/java/java_message_field.cc",
"src/google/protobuf/compiler/java/java_message_field_lite.cc",
"src/google/protobuf/compiler/java/java_message_lite.cc",
"src/google/protobuf/compiler/java/java_name_resolver.cc",
"src/google/protobuf/compiler/java/java_primitive_field.cc",
"src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
"src/google/protobuf/compiler/java/java_service.cc",
"src/google/protobuf/compiler/java/java_shared_code_generator.cc",
"src/google/protobuf/compiler/java/java_string_field.cc",
"src/google/protobuf/compiler/java/java_string_field_lite.cc",
"src/google/protobuf/compiler/js/js_generator.cc",
"src/google/protobuf/compiler/js/well_known_types_embed.cc",
"src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
"src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
"src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
"src/google/protobuf/compiler/objectivec/objectivec_field.cc",
"src/google/protobuf/compiler/objectivec/objectivec_file.cc",
"src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
"src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
"src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
"src/google/protobuf/compiler/objectivec/objectivec_message.cc",
"src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
"src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
"src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
"src/google/protobuf/compiler/php/php_generator.cc",
"src/google/protobuf/compiler/plugin.cc",
"src/google/protobuf/compiler/plugin.pb.cc",
"src/google/protobuf/compiler/python/python_generator.cc",
"src/google/protobuf/compiler/ruby/ruby_generator.cc",
"src/google/protobuf/compiler/subprocess.cc",
"src/google/protobuf/compiler/zip_writer.cc",
],
copts = COPTS,
includes = ["src/"],
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [":protobuf"],
)
cc_binary(
name = "protoc",
srcs = ["src/google/protobuf/compiler/main.cc"],
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = [":protoc_lib"],
)
proto_lang_toolchain(
name = "cc_toolchain",
blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf",
visibility = ["//visibility:public"],
)
alias(
name = "objectivec",
actual = "//objectivec",
visibility = ["//visibility:public"],
)
alias(
name = "protobuf_objc",
actual = "//objectivec",
visibility = ["//visibility:public"],
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+122
View File
@@ -0,0 +1,122 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copied from https://github.com/tensorflow/tensorflow/blob/bdd8bf316e4ab7d699127d192d30eb614a158462/third_party/snappy.BUILD
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "snappy",
srcs = [
"config.h",
"snappy.cc",
"snappy.h",
"snappy-internal.h",
"snappy-sinksource.cc",
"snappy-stubs-internal.cc",
"snappy-stubs-internal.h",
"snappy-stubs-public.h",
],
hdrs = [
"snappy.h",
"snappy-sinksource.h",
],
copts = [
"-DHAVE_CONFIG_H",
"-fno-exceptions",
"-Wno-sign-compare",
"-Wno-shift-negative-value",
],
includes = ["."],
visibility = ["//visibility:public"],
)
genrule(
name = "config_h",
outs = ["config.h"],
cmd = "\n".join([
"cat <<'EOF' >$@",
"#define HAVE_STDDEF_H 1",
"#define HAVE_STDINT_H 1",
"",
"#ifdef __has_builtin",
"# if !defined(HAVE_BUILTIN_EXPECT) && __has_builtin(__builtin_expect)",
"# define HAVE_BUILTIN_EXPECT 1",
"# endif",
"# if !defined(HAVE_BUILTIN_CTZ) && __has_builtin(__builtin_ctzll)",
"# define HAVE_BUILTIN_CTZ 1",
"# endif",
"#elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)",
"# ifndef HAVE_BUILTIN_EXPECT",
"# define HAVE_BUILTIN_EXPECT 1",
"# endif",
"# ifndef HAVE_BUILTIN_CTZ",
"# define HAVE_BUILTIN_CTZ 1",
"# endif",
"#endif",
"",
"#ifdef __has_include",
"# if !defined(HAVE_BYTESWAP_H) && __has_include(<byteswap.h>)",
"# define HAVE_BYTESWAP_H 1",
"# endif",
"# if !defined(HAVE_UNISTD_H) && __has_include(<unistd.h>)",
"# define HAVE_UNISTD_H 1",
"# endif",
"# if !defined(HAVE_SYS_ENDIAN_H) && __has_include(<sys/endian.h>)",
"# define HAVE_SYS_ENDIAN_H 1",
"# endif",
"# if !defined(HAVE_SYS_MMAN_H) && __has_include(<sys/mman.h>)",
"# define HAVE_SYS_MMAN_H 1",
"# endif",
"# if !defined(HAVE_SYS_UIO_H) && __has_include(<sys/uio.h>)",
"# define HAVE_SYS_UIO_H 1",
"# endif",
"#endif",
"",
"#ifndef SNAPPY_IS_BIG_ENDIAN",
"# ifdef __s390x__",
"# define SNAPPY_IS_BIG_ENDIAN 1",
"# elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__",
"# define SNAPPY_IS_BIG_ENDIAN 1",
"# endif",
"#endif",
"EOF",
]),
)
genrule(
name = "snappy_stubs_public_h",
srcs = ["snappy-stubs-public.h.in"],
outs = ["snappy-stubs-public.h"],
cmd = ("sed " +
"-e 's/$${\\(.*\\)_01}/\\1/g' " +
"-e 's/$${SNAPPY_MAJOR}/1/g' " +
"-e 's/$${SNAPPY_MINOR}/1/g' " +
"-e 's/$${SNAPPY_PATCHLEVEL}/7/g' " +
"$< >$@"),
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+75
View File
@@ -0,0 +1,75 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
cmake(
name = "thrift",
cache_entries = {
"BUILD_COMPILER": "OFF",
"BUILD_TESTING": "OFF",
"BUILD_TUTORIALS": "OFF",
"WITH_AS3": "OFF",
"WITH_CPP": "ON",
"WITH_C_GLIB": "OFF",
"WITH_JAVA": "OFF",
"WITH_JAVASCRIPT": "OFF",
"WITH_NODEJS": "OFF",
"WITH_PYTHON": "OFF",
"BUILD_SHARED_LIBS": "OFF",
"Boost_USE_STATIC_LIBS": "ON",
"BOOST_ROOT": "$$EXT_BUILD_DEPS$$",
"LIBEVENT_INCLUDE_DIRS": "$$EXT_BUILD_DEPS$$/event/include",
"LIBEVENT_LIBRARIES": "$$EXT_BUILD_DEPS$$/event/lib/libevent.a",
"OPENSSL_ROOT_DIR": "$$EXT_BUILD_DEPS$$/openssl",
"ZLIB_ROOT": "$$EXT_BUILD_DEPS$$/zlib",
},
generate_args = ["-GNinja"],
lib_source = ":all_srcs",
linkopts = [
"-pthread",
],
out_static_libs = select({
"@platforms//os:windows": [
"thrift.lib",
"thriftnb.lib",
"thriftz.lib",
],
"//conditions:default": [
"libthrift.a",
"libthriftnb.a",
"libthriftz.a",
],
}),
visibility = ["//visibility:public"],
deps = [
"@boost//:algorithm",
"@boost//:locale",
"@boost//:noncopyable",
"@boost//:numeric_conversion",
"@boost//:scoped_array",
"@boost//:smart_ptr",
"@boost//:tokenizer",
"@com_github_libevent_libevent//:event",
"@com_github_madler_zlib//:zlib",
"@openssl//:crypto",
"@openssl//:ssl",
],
)
+17
View File
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Thie empty BUILD.bazel file is required to make Bazel treat
# this directory as a package.
+111
View File
@@ -0,0 +1,111 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2008 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Copied from https://github.com/protocolbuffers/protobuf/blob/v3.9.1/third_party/zlib.BUILD
load("@rules_cc//cc:defs.bzl", "cc_library")
_ZLIB_HEADERS = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
]
_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS]
# In order to limit the damage from the `includes` propagation
# via `:zlib`, copy the public headers to a subdirectory and
# expose those.
genrule(
name = "copy_public_headers",
srcs = _ZLIB_HEADERS,
outs = _ZLIB_PREFIXED_HEADERS,
cmd = "cp $(SRCS) $(@D)/zlib/include/",
visibility = ["//visibility:private"],
)
cc_library(
name = "zlib",
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
],
hdrs = _ZLIB_PREFIXED_HEADERS,
copts = select({
":windows": [],
"//conditions:default": [
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
}),
includes = ["zlib/include/"],
visibility = ["//visibility:public"],
)
config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
)
+23
View File
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This BUILD file marks bazel/tools/ as a Bazel package so that loads
# of the form `//bazel/tools:xxx.bzl` are valid. The directory only
# hosts .bzl files (brpc_proto_library.bzl / proto_gen.bzl) and does
# not define any build targets.
package(default_visibility = ["//visibility:public"])
exports_files(glob(["*.bzl"]))
+138
View File
@@ -0,0 +1,138 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# brpc_proto_library: a proto -> cc_library macro that is robust against
# protobuf and Bazel version churn.
#
# Background:
# - Old protobuf (< 3.21) used to expose a `cc_proto_library` macro
# via `@com_google_protobuf//:protobuf.bzl`; newer protobuf removed
# that macro.
# - Newer protobuf expects callers to use Bazel's native
# `proto_library` / `cc_proto_library` (or the `cc_proto_library`
# re-exported from `@com_google_protobuf//bazel:cc_proto_library.bzl`),
# but older protobuf does not surface a complete `ProtoInfo`, so
# the native rules cannot build it.
# - Bazel 8 additionally removed `cc_proto_library` from
# `@rules_cc//cc:defs.bzl` (the load now resolves to a stub rule
# that fails analysis), forcing every caller to either load it
# from `@com_google_protobuf` or replace it.
# - Bazel's `load()` is static and cannot be conditional on the
# protobuf version, so a single brpc_proto_library.bzl cannot
# directly satisfy both old and new protobuf by switching imports.
#
# Solution (inspired by https://github.com/trpc-group/trpc-cpp/blob/a69d2950f4a9c16b3cb40a2750c69d8940c96820/trpc/trpc.bzl):
# We implement the proto compilation rule from scratch (see
# proto_gen.bzl in this directory). Dependency information is
# propagated through Bazel's native `ProtoInfo` provider, and the
# default well-known-proto source is
# `@com_google_protobuf//:descriptor_proto` -- a `proto_library`
# whose name has been stable across protobuf 3.x / 27.x / 34.x.
load("//bazel/tools:proto_gen.bzl", "brpc_proto_gen")
# `:descriptor_proto` is the protobuf repo's `proto_library` target;
# its label has been stable since protobuf 3.x. We consume it through
# Bazel's native `ProtoInfo` provider, which is uniform across PB
# versions. If a caller's .proto needs additional well-known protos
# (any.proto, timestamp.proto, ...), they can pass extra entries via
# the `proto_deps` argument.
_DEFAULT_PROTO_DEPS = ["@com_google_protobuf//:descriptor_proto"]
def brpc_proto_library(
name,
srcs,
deps = [],
include = None,
proto_deps = None,
visibility = None,
testonly = 0):
"""Generate a cc_library from a set of .proto files.
Args:
name: target name.
srcs: list of .proto files, paths relative to the current package.
deps: list of other `brpc_proto_library` targets this target
depends on. The macro internally translates these labels
to the underlying `<name>_genproto` rule so that .proto
include paths and sources propagate.
include: protoc `-I` root AND the resulting cc_library `includes`
root, relative to the current package.
When omitted, "" or None, the include root is the
current package itself (suitable for .proto files
sitting directly under the package root, as in `test/`
and `example/...`). The root `BUILD.bazel` of brpc must
pass `"src"` so that code can reference the protos as
`import "brpc/foo.proto"`.
proto_deps: list of native `proto_library` dependencies
(well-known protos or external .proto libraries).
Defaults to
`["@com_google_protobuf//:descriptor_proto"]`.
Pass `[]` explicitly to disable the default; pass
None (the default) to use it.
visibility: same semantics as cc_library.
testonly: same semantics as cc_library.
"""
real_include = include if include != None else ""
real_proto_deps = proto_deps if proto_deps != None else _DEFAULT_PROTO_DEPS
gen_name = name + "_genproto"
brpc_proto_gen(
name = gen_name,
srcs = srcs,
# Rewrite each `brpc_proto_library` dep to its underlying
# `<dep>_genproto` rule, which exports BrpcProtoInfo.
deps = [d + "_genproto" for d in deps],
include = real_include,
proto_deps = real_proto_deps,
visibility = visibility,
testonly = testonly,
)
# Split the generated files into .pb.h / .pb.cc via OutputGroupInfo
# and feed them to cc_library's hdrs / srcs separately. Bazel
# rejects declaring the same File in both hdrs and srcs, so a
# plain DefaultInfo wouldn't work here.
native.filegroup(
name = gen_name + "_hdrs",
srcs = [":" + gen_name],
output_group = "hdrs",
visibility = visibility,
testonly = testonly,
)
native.filegroup(
name = gen_name + "_srcs",
srcs = [":" + gen_name],
output_group = "srcs",
visibility = visibility,
testonly = testonly,
)
native.cc_library(
name = name,
srcs = [":" + gen_name + "_srcs"],
hdrs = [":" + gen_name + "_hdrs"],
# cc_library `includes` is required, otherwise the .pb.cc
# files inside this cc_library cannot find the .pb.h headers
# they just generated (the headers live under
# bazel-bin/<package>/<include>/...). When include="" we pass
# "." to mean "the current package itself"; Bazel then exposes
# both `-I <package>` and `-I bazel-bin/<package>`
# automatically to dependents.
includes = [real_include if real_include else "."],
deps = deps + ["@com_google_protobuf//:protobuf"],
visibility = visibility,
testonly = testonly,
)
+240
View File
@@ -0,0 +1,240 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# brpc's self-implemented proto -> .pb.{h,cc} compilation rule.
#
# Cross-protobuf-version compatibility strategy (inspired by trpc.bzl):
# 1) Do NOT load `@com_google_protobuf//:protobuf.bzl` and do NOT
# call `native.cc_proto_library` -- this side-steps the double
# incompatibility of newer protobuf removing the macro and older
# protobuf missing a complete `ProtoInfo` provider.
# 2) Do NOT hardcode any protobuf-repo-internal filegroup names
# (such as `well_known_protos` / `descriptor_proto_srcs`) -- the
# names of those filegroups have shifted between protobuf 3.x
# and 27.x+.
# 3) Propagate dependencies via Bazel's native `ProtoInfo` provider:
# callers pass `proto_library` targets through `proto_deps`
# (defaulting to `@com_google_protobuf//:descriptor_proto`, a
# `proto_library` whose label has been stable across PB versions),
# and this rule walks `transitive_sources` / `transitive_proto_path`
# to collect .proto source files and protoc `-I` paths -- fully
# decoupled from the PB version.
# 4) Among `brpc_proto_gen` targets themselves, dependencies are
# propagated via the custom `BrpcProtoInfo` provider declared
# below.
#
# Note on minimum Bazel version: this rule itself does not call any
# Bazel-version-specific API, but it still consumes `ProtoInfo` from
# `proto_library` targets (e.g. `descriptor_proto`) defined inside
# the protobuf repo. Protobuf >= 34 calls
# `ProtoInfo(option_deps = ..., extension_declarations = ...)` in its
# own `proto_library` implementation, and those fields are only
# accepted by Bazel >= 8. In other words, the minimum Bazel version
# brpc requires is whatever the bundled protobuf version requires --
# we just don't add any extra requirement on top of that.
BrpcProtoInfo = provider(
doc = "Carries transitive .proto sources and protoc -I flags between brpc_proto_gen targets.",
fields = {
"transitive_srcs": "depset of all transitive .proto Files.",
"transitive_imports": "depset of strings, all -I flags needed by protoc.",
},
)
def _resolve_include_dir(ctx):
"""Compute this target's protoc include root (workspace-relative).
Examples:
ctx.label.package = "" + include = "src" -> "src"
ctx.label.package = "test" + include = "" -> "test"
ctx.label.package = "" + include = "" -> "."
"""
pkg = ctx.label.package
inc = ctx.attr.include.rstrip("/")
if pkg and inc:
return pkg + "/" + inc
if pkg:
return pkg
if inc:
return inc
return "."
def _proto_gen_impl(ctx):
srcs = ctx.files.srcs
include_dir = _resolve_include_dir(ctx)
bin_root = ctx.bin_dir.path
# `-I` flags for this target itself: the source-tree root plus
# the corresponding bin-dir root. The bin-dir entry is needed
# when a transitive dep generates .proto files into bazel-bin
# (e.g. via a custom code generator).
own_imports = ["-I" + include_dir]
if include_dir == ".":
own_imports.append("-I" + bin_root)
else:
own_imports.append("-I" + bin_root + "/" + include_dir)
# Collect transitive info from other `brpc_proto_gen` deps.
dep_srcs_list = [d[BrpcProtoInfo].transitive_srcs for d in ctx.attr.deps]
dep_imports_list = [d[BrpcProtoInfo].transitive_imports for d in ctx.attr.deps]
# Collect native `proto_library` deps (well-known protos or
# external .proto libraries). Key design: .proto sources and
# `-I` paths are obtained via Bazel's native `ProtoInfo`,
# avoiding any reliance on protobuf-repo-internal filegroup
# names (descriptor_proto_srcs / well_known_protos / ...).
# `transitive_proto_path` already accounts for the
# `_virtual_imports` paths created by `strip_import_prefix`, so
# protoc can consume the paths directly.
#
# Important: `strip_import_prefix` causes .proto files to live at
# virtual paths under bazel-out/<config>/bin/<workspace_root>/<virtual>
# (see trpc.bzl for prior art). For every `proto_dep` repo we
# therefore expose FOUR candidate `-I` paths to be safe:
# 1) <workspace_root> -- source root (plain proto_library)
# 2) <bin_dir>/<workspace_root> -- virtual root after strip_import_prefix
# 3) <workspace_root>/src -- fallback for older PB descriptor_proto without strip
# 4) <bin_dir>/<workspace_root>/src -- same as #3, under bin-dir
# protoc only warns on non-existent `-I` paths, so this is harmless.
proto_dep_src_depsets = []
proto_dep_imports = []
extra_pb_root_imports = []
# Belt-and-suspenders: also feed each `proto_dep`'s default outputs
# (i.e. the .proto files themselves) into `inputs`, in case the
# ProtoInfo's transitive_sources does not cover everything we need.
proto_dep_src_depsets.append(depset(direct = ctx.files.proto_deps))
for pd in ctx.attr.proto_deps:
pi = pd[ProtoInfo]
proto_dep_src_depsets.append(pi.transitive_sources)
for path in pi.transitive_proto_path.to_list():
proto_dep_imports.append("-I" + path)
wsroot = pd.label.workspace_root
if wsroot:
extra_pb_root_imports.append("-I" + wsroot)
extra_pb_root_imports.append("-I" + bin_root + "/" + wsroot)
extra_pb_root_imports.append("-I" + wsroot + "/src")
extra_pb_root_imports.append("-I" + bin_root + "/" + wsroot + "/src")
# Deduplicate the workspace-level `-I` entries so the same repo
# is not listed multiple times when several proto_deps share it.
proto_dep_imports.extend(depset(extra_pb_root_imports).to_list())
all_imports = depset(
direct = own_imports + proto_dep_imports,
transitive = dep_imports_list,
)
# Output files: every .proto produces a .pb.h and a .pb.cc.
# NB: the `path` argument of `ctx.actions.declare_file(path)` is
# *relative to the current package*, while `src.short_path` is
# *relative to the workspace root*. The two differ by the package
# prefix; we must strip that prefix before calling declare_file,
# otherwise the outputs would land at
# bazel-bin/<pkg>/<pkg>/... (one level too deep).
pkg = ctx.label.package
pkg_prefix = pkg + "/" if pkg else ""
outs = []
for src in srcs:
if not src.short_path.endswith(".proto"):
fail("brpc_proto_gen srcs must be .proto, got: %s" % src.short_path)
rel = src.short_path
if pkg_prefix and rel.startswith(pkg_prefix):
rel = rel[len(pkg_prefix):]
base = rel[:-len(".proto")]
outs.append(ctx.actions.declare_file(base + ".pb.h"))
outs.append(ctx.actions.declare_file(base + ".pb.cc"))
# protoc's --cpp_out points at the include root under bin_root.
# After protoc organizes outputs by their import-relative path,
# the .pb.{h,cc} files land exactly where declare_file declared
# them above.
if include_dir == ".":
cpp_out_dir = bin_root
else:
cpp_out_dir = bin_root + "/" + include_dir
args = ctx.actions.args()
args.add_all(all_imports.to_list())
args.add("--cpp_out=" + cpp_out_dir)
args.add_all([s.path for s in srcs])
ctx.actions.run(
executable = ctx.executable.protoc,
arguments = [args],
inputs = depset(
direct = srcs,
transitive = dep_srcs_list + proto_dep_src_depsets,
),
outputs = outs,
mnemonic = "BrpcProtoCompile",
progress_message = "BrpcProtoCompile %s" % ctx.label,
)
hdr_files = [f for f in outs if f.path.endswith(".pb.h")]
src_files = [f for f in outs if f.path.endswith(".pb.cc")]
return [
DefaultInfo(files = depset(outs)),
# Split outputs so the brpc_proto_library macro can route
# them to cc_library.hdrs vs cc_library.srcs separately.
OutputGroupInfo(
hdrs = depset(hdr_files),
srcs = depset(src_files),
),
BrpcProtoInfo(
transitive_srcs = depset(direct = srcs, transitive = dep_srcs_list),
transitive_imports = all_imports,
),
]
brpc_proto_gen = rule(
implementation = _proto_gen_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".proto"],
mandatory = True,
),
# Other `brpc_proto_gen` targets; deps are propagated via the
# custom `BrpcProtoInfo` provider.
"deps": attr.label_list(
providers = [BrpcProtoInfo],
default = [],
),
# The include root, relative to the current BUILD package
# (e.g. "src" for the brpc root BUILD).
"include": attr.string(default = ""),
"protoc": attr.label(
default = Label("@com_google_protobuf//:protoc"),
executable = True,
# `"host"` is the legacy spelling of `"exec"`. Modern
# Bazel (>= 6) prefers `"exec"`, but still accepts
# `"host"` as an alias through at least Bazel 8.x. We
# keep `"host"` here for the broad range of Bazel
# versions used to build brpc; switch to `"exec"` once
# `"host"` is finally removed (likely a future major
# Bazel release).
cfg = "host",
allow_files = True,
),
# Native `proto_library` deps (well-known protos or external
# .proto libraries). .proto sources and -I paths are obtained
# automatically through Bazel's native `ProtoInfo`, fully
# decoupled from the protobuf version.
"proto_deps": attr.label_list(
providers = [ProtoInfo],
default = [],
),
},
)