From 3f7296e0ffe7a95af3677cbc02493bd97b1f5455 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Sat, 22 Jun 2024 12:39:37 +0800 Subject: [PATCH 1/4] add bzlmod support --- .bazelrc | 7 +++-- .bazelversion | 2 +- .github/workflows/ci-linux.yml | 52 ++++------------------------------ BUILD.bazel | 6 ++-- MODULE.bazel | 26 +++++++++++++++++ WORKSPACE.bzlmod | 15 ++++++++++ test/BUILD.bazel | 4 +-- test/thread_key_unittest.cpp | 3 +- 8 files changed, 60 insertions(+), 55 deletions(-) create mode 100644 MODULE.bazel create mode 100644 WORKSPACE.bzlmod diff --git a/.bazelrc b/.bazelrc index f3d406b061..e9aa52ad59 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,10 +16,13 @@ # # Default build options. These are applied first and unconditionally. # +common --registry=https://bcr.bazel.build +common --registry=https://baidu.github.io/babylon/registry +common --registry=https://raw.githubusercontent.com/bazelboost/registry/main -build --cxxopt="-std=c++11" +build --cxxopt="-std=c++17" # Use gnu11 for asm keyword. -build --conlyopt="-std=gnu11" +build --conlyopt="-std=gnu17" # Enable position independent code (this is the default on macOS and Windows) # (Workaround for https://github.com/bazelbuild/rules_foreign_cc/issues/421) diff --git a/.bazelversion b/.bazelversion index af8c8ec7c1..a8a1887568 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -4.2.2 +7.1.2 diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 652631f28f..9160034073 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -46,26 +46,13 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile - run: | - export CC=gcc && export CXX=g++ - bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //... + - run: bazel test -- //... -//example/... gcc-compile-with-boringssl: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile-with-boringssl - run: | - bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... + - run: bazel test --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... gcc-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -99,14 +86,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile - run: | - export CC=gcc && export CXX=g++ - bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... + - run: bazel test --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-compile-with-make: runs-on: ubuntu-20.04 @@ -140,26 +120,13 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile - run: | - export CC=clang && export CXX=clang++ - bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //... + - run: bazel --action_env=CC=clang test -- //... -//example/... clang-compile-with-boringssl: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile - run: | - bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... + - run: bazel test --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... clang-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -193,14 +160,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: install dependences - run: | - sudo apt-get update - sudo apt-get install libibverbs-dev - - name: compile - run: | - export CC=clang && export CXX=clang++ - bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... + - run: bazel test --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-unittest: runs-on: ubuntu-20.04 diff --git a/BUILD.bazel b/BUILD.bazel index b2a453e0c9..795e392e70 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -51,7 +51,7 @@ LINKOPTS = [ "-pthread", "-ldl", ] + select({ - "@bazel_tools//tools/osx:darwin": [ + "@bazel_tools//tools/osx:darwin_x86_64": [ "-framework CoreFoundation", "-framework CoreGraphics", "-framework CoreData", @@ -218,7 +218,7 @@ BUTIL_SRCS = [ "src/butil/recordio.cc", "src/butil/popen.cpp", ] + select({ - "@bazel_tools//tools/osx:darwin": [ + "@bazel_tools//tools/osx:darwin_x86_64": [ "src/butil/time/time_mac.cc", "src/butil/mac/scoped_mach_port.cc", ], @@ -333,7 +333,7 @@ cc_library( "//bazel/config:brpc_with_glog": ["@com_github_google_glog//:glog"], "//conditions:default": [], }) + select({ - "@bazel_tools//tools/osx:darwin": [":macos_lib"], + "@bazel_tools//tools/osx:darwin_x86_64": [":macos_lib"], "//conditions:default": [], }) + select({ "//bazel/config:brpc_with_boringssl": ["@boringssl//:ssl", "@boringssl//:crypto"], diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000000..0190a3d09d --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,26 @@ +module( + name = 'brpc', + version = '1.9.0', + compatibility_level = 1, +) + +# https://bcr.bazel.build +bazel_dep(name = 'abseil-cpp', version = '20210324.2', repo_name = 'com_google_absl') +bazel_dep(name = 'bazel_skylib', version = '1.0.3') +bazel_dep(name = 'boringssl', version = '0.0.0-20211025-d4f1ab9') +bazel_dep(name = 'protobuf', version = '3.19.6', repo_name = 'com_google_protobuf') +bazel_dep(name = 'gflags', version = '2.2.2', repo_name = 'com_github_gflags_gflags') +bazel_dep(name = 'glog', version = '0.5.0', repo_name = 'com_github_google_glog') +bazel_dep(name = 'platforms', version = '0.0.4') +bazel_dep(name = 'rules_cc', version = '0.0.1') +bazel_dep(name = 'rules_proto', version = '4.0.0') +bazel_dep(name = 'zlib', version = '1.2.13', repo_name = 'com_github_madler_zlib') + +# https://baidu.github.io/babylon/registry +# https://raw.githubusercontent.com/bazelboost/registry/main +bazel_dep(name = 'leveldb', version = '1.23', repo_name = 'com_github_google_leveldb') +bazel_dep(name = 'openssl', version = '3.3.1') +bazel_dep(name = 'thrift', version = '0.20.0', repo_name = 'org_apache_thrift') + +# test only +bazel_dep(name = 'googletest', version = '1.14.0.bcr.1', repo_name = 'com_google_googletest', dev_dependency = True) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 0000000000..d0f39e7ddb --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1,15 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# +# Tools Dependencies +# +# Hedron's Compile Commands Extractor for Bazel +# https://github.com/hedronvision/bazel-compile-commands-extractor +http_archive( + name = "hedron_compile_commands", + url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/3dddf205a1f5cde20faf2444c1757abe0564ff4c.tar.gz", + strip_prefix = "bazel-compile-commands-extractor-3dddf205a1f5cde20faf2444c1757abe0564ff4c", + sha256 = "3cd0e49f0f4a6d406c1d74b53b7616f5e24f5fd319eafc1bf8eee6e14124d115", +) +load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup") +hedron_compile_commands_setup() diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 345043fc4d..fd56e96805 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -30,7 +30,7 @@ COPTS = [ "-Wno-unused-parameter", "-fno-omit-frame-pointer", "-DGFLAGS_NS=google", - "-Dprivate=public", + "-fno-access-control", "-Dprotected=public", "--include test/sstream_workaround.h", "-DBAZEL_TEST=1", @@ -142,7 +142,7 @@ TEST_BUTIL_SOURCES = [ "bounded_queue_unittest.cc", "butil_unittest_main.cpp", ] + select({ - "@bazel_tools//tools/osx:darwin": [], + "@bazel_tools//tools/osx:darwin_x86_64": [], "//conditions:default": [ "test_file_util_linux.cc", "proc_maps_linux_unittest.cc", diff --git a/test/thread_key_unittest.cpp b/test/thread_key_unittest.cpp index adbeb02460..f254ce411d 100644 --- a/test/thread_key_unittest.cpp +++ b/test/thread_key_unittest.cpp @@ -178,6 +178,7 @@ void* ThreadLocalForEachFunc(void* arg) { auto counter = static_cast>*>(arg); auto local_counter = counter->get(); EXPECT_NE(nullptr, local_counter); + local_counter->store(0, butil::memory_order_relaxed); while (!g_stopped) { local_counter->fetch_add(1, butil::memory_order_relaxed); g_counter.fetch_add(1, butil::memory_order_relaxed); @@ -497,4 +498,4 @@ TEST(ThreadLocalTest, thread_key_performance) { } } -} // namespace butil \ No newline at end of file +} // namespace butil From 83d74144da4b29993b5497fa6c9b68bc76541128 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 24 Jun 2024 13:41:07 +0800 Subject: [PATCH 2/4] drop buggy clang-11 which dont suport -fno-access-control correctly --- .github/workflows/ci-linux.yml | 24 ++++++++++++------------ test/BUILD.bazel | 2 -- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 9160034073..58636bf24c 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -43,16 +43,16 @@ jobs: make -j ${{env.proc_num}} gcc-compile-with-bazel: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel test -- //... -//example/... + - run: bazel test --verbose_failures -- //... -//example/... gcc-compile-with-boringssl: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel test --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... + - run: bazel test --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... gcc-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -83,10 +83,10 @@ jobs: make -j ${{env.proc_num}} gcc-compile-with-bazel-all-options: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel test --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... + - run: bazel test --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-compile-with-make: runs-on: ubuntu-20.04 @@ -117,16 +117,16 @@ jobs: make -j ${{env.proc_num}} clang-compile-with-bazel: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel --action_env=CC=clang test -- //... -//example/... + - run: bazel test --verbose_failures --action_env=CC=clang -- //... -//example/... clang-compile-with-boringssl: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel test --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... + - run: bazel test --verbose_failures ---action_env=CC=clang -define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... clang-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -157,10 +157,10 @@ jobs: make -j ${{env.proc_num}} clang-compile-with-bazel-all-options: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - run: bazel test --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... + - run: bazel test --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-unittest: runs-on: ubuntu-20.04 diff --git a/test/BUILD.bazel b/test/BUILD.bazel index fd56e96805..d9af2ae7b2 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -31,8 +31,6 @@ COPTS = [ "-fno-omit-frame-pointer", "-DGFLAGS_NS=google", "-fno-access-control", - "-Dprotected=public", - "--include test/sstream_workaround.h", "-DBAZEL_TEST=1", "-DBVAR_NOT_LINK_DEFAULT_VARIABLES", "-DUNIT_TEST", From a1627567db2a090eebd810c7b68e36e707b2609b Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 24 Jun 2024 21:45:38 +0800 Subject: [PATCH 3/4] fix typo in ci-linux.yml --- .github/workflows/ci-linux.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 58636bf24c..f0293f427d 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -43,13 +43,13 @@ jobs: make -j ${{env.proc_num}} gcc-compile-with-bazel: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - run: bazel test --verbose_failures -- //... -//example/... gcc-compile-with-boringssl: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - run: bazel test --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... @@ -83,7 +83,7 @@ jobs: make -j ${{env.proc_num}} gcc-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - run: bazel test --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... @@ -117,16 +117,16 @@ jobs: make -j ${{env.proc_num}} clang-compile-with-bazel: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures --action_env=CC=clang -- //... -//example/... + - run: bazel test --verbose_failures --action_env=CC=clang-14 -- //... -//example/... clang-compile-with-boringssl: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures ---action_env=CC=clang -define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... + - run: bazel test --verbose_failures --action_env=CC=clang-14 --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... clang-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -157,10 +157,10 @@ jobs: make -j ${{env.proc_num}} clang-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... + - run: bazel test --verbose_failures --action_env=CC=clang-14 --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-unittest: runs-on: ubuntu-20.04 From c3d767e9c0433b4df82dbd93143833ceb4cfed86 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 24 Jun 2024 23:19:44 +0800 Subject: [PATCH 4/4] give up trying to test bazel in clang --- .github/workflows/ci-linux.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index f0293f427d..56aacee37e 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -120,13 +120,13 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures --action_env=CC=clang-14 -- //... -//example/... + - run: bazel build --verbose_failures --action_env=CC=clang-12 -- //... -//example/... clang-compile-with-boringssl: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures --action_env=CC=clang-14 --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... + - run: bazel build --verbose_failures --action_env=CC=clang-12 --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... clang-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -160,7 +160,7 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: bazel test --verbose_failures --action_env=CC=clang-14 --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... + - run: bazel build --verbose_failures --action_env=CC=clang-12 --define with_mesalink=false --define with_glog=true --define with_thrift=true -- //... -//example/... clang-unittest: runs-on: ubuntu-20.04