From 3c4e3ebdaee666ccac290b1656f1b6559541d59d Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Tue, 18 Feb 2025 11:22:47 -0500 Subject: [PATCH 1/3] Upgrade to Bazel 6, modern protobufs, etc * Upgrade to Protobuf 29.3 and fix resulting minor breakages to APIs and build rules. This is necessary in order for stout to be used with Bazel projects that depend on newer versions of Protobuf. * Upgrade to recent abseil. This is necessary due to the protobuf upgrade. We take care to use the version of abseil required by gRPC 1.68.2, which is the version that the mono repo will be using once we land the Bazel 6. * Upgrade to Bazel 6. This is necessary because recent abseil does not build with Bazel 5. * Use `proto_library` and `cc_proto_library` from @com_google_protobuf, rather than `rules_proto` and `rules_cc`, respectively. The latter sources are deprecated. --- .bazeliskrc | 2 +- BUILD.bazel | 1 + bazel/deps.bzl | 10 ++++++++++ bazel/repos.bzl | 17 +++++++++-------- include/stout/flags/flags.cc | 14 +++++++------- include/stout/flags/v1/BUILD.bazel | 4 ++-- tests/flags/BUILD.bazel | 6 ++++-- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.bazeliskrc b/.bazeliskrc index bd4a535..89b6466 100644 --- a/.bazeliskrc +++ b/.bazeliskrc @@ -1 +1 @@ -USE_BAZEL_VERSION=5.4.1 +USE_BAZEL_VERSION=6.5.0 diff --git a/BUILD.bazel b/BUILD.bazel index 2e84638..5fc910d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -49,6 +49,7 @@ cc_library( "@com_github_google_glog//:glog", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", + "@com_google_protobuf//:duration_cc_proto", ], ) diff --git a/bazel/deps.bzl b/bazel/deps.bzl index c1f1680..8502806 100644 --- a/bazel/deps.bzl +++ b/bazel/deps.bzl @@ -1,5 +1,6 @@ """Dependency specific initialization for stout.""" +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@com_github_3rdparty_bazel_rules_picojson//bazel:deps.bzl", picojson_deps = "deps") load("@com_github_3rdparty_bazel_rules_rapidjson//bazel:deps.bzl", rapidjson_deps = "deps") load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps") @@ -21,4 +22,13 @@ def deps(repo_mapping = {}): repo_mapping = repo_mapping, ) + # Needed because protobuf_deps brings rules_python 0.26.0 which is broken: + # https://github.com/bazelbuild/rules_python/issues/1543 + http_archive( + name = "rules_python", + sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036", + strip_prefix = "rules_python-0.25.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz", + ) + protobuf_deps() diff --git a/bazel/repos.bzl b/bazel/repos.bzl index 02946dc..d21e564 100644 --- a/bazel/repos.bzl +++ b/bazel/repos.bzl @@ -35,10 +35,12 @@ def repos(external = True, repo_mapping = {}): maybe( http_archive, name = "com_google_absl", - urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.tar.gz"], - strip_prefix = "abseil-cpp-20211102.0", - sha256 = "dcf71b9cba8dc0ca9940c4b316a0c796be8fab42b070bb6b7cab62b48f0e66c4", - repo_mapping = repo_mapping, + sha256 = "f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3", + strip_prefix = "abseil-cpp-20240722.0", + urls = [ + "https://storage.googleapis.com/grpc-bazel-mirror/github.com/abseil/abseil-cpp/archive/20240722.0.tar.gz", + "https://github.com/abseil/abseil-cpp/archive/20240722.0.tar.gz", + ], ) maybe( @@ -81,12 +83,11 @@ def repos(external = True, repo_mapping = {}): maybe( http_archive, name = "com_google_protobuf", - strip_prefix = "protobuf-3.19.1", + sha256 = "008a11cc56f9b96679b4c285fd05f46d317d685be3ab524b2a310be0fbad987e", + strip_prefix = "protobuf-29.3", urls = [ - "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz", - "https://github.com/protocolbuffers/protobuf/archive/v3.19.1.tar.gz", + "https://github.com/protocolbuffers/protobuf/archive/v29.3.tar.gz", ], - sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422", repo_mapping = repo_mapping, ) diff --git a/include/stout/flags/flags.cc b/include/stout/flags/flags.cc index 843dba9..4ac28dc 100644 --- a/include/stout/flags/flags.cc +++ b/include/stout/flags/flags.cc @@ -678,19 +678,19 @@ void Parser::SetFieldMessageOrAggregateErrors( // error for us to print out later. struct ErrorCollector : public google::protobuf::io::ErrorCollector { // TODO(artur): include also 'line' and 'column' for easier debugging. - void AddError( + void RecordError( int /* line */, - int /* column */, - const std::string& message) override { + google::protobuf::io::ColumnNumber /* column */, + absl::string_view message) override { error += message; } - void AddWarning( + void RecordWarning( int line, - int column, - const std::string& message) override { + google::protobuf::io::ColumnNumber column, + absl::string_view message) override { // For now we treat all warnings as errors. - AddError(line, column, message); + RecordError(line, column, message); } std::string error; diff --git a/include/stout/flags/v1/BUILD.bazel b/include/stout/flags/v1/BUILD.bazel index 527dcd2..5fd61d9 100644 --- a/include/stout/flags/v1/BUILD.bazel +++ b/include/stout/flags/v1/BUILD.bazel @@ -1,5 +1,5 @@ -load("@rules_cc//cc:defs.bzl", "cc_proto_library") -load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") proto_library( name = "flag_proto", diff --git a/tests/flags/BUILD.bazel b/tests/flags/BUILD.bazel index 71a100e..381f3f3 100644 --- a/tests/flags/BUILD.bazel +++ b/tests/flags/BUILD.bazel @@ -1,5 +1,6 @@ -load("@rules_cc//cc:defs.bzl", "cc_proto_library", "cc_test") -load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_cc//cc:defs.bzl", "cc_test") proto_library( name = "test_proto", @@ -44,6 +45,7 @@ cc_test( deps = [ ":test_proto_library", "//:flags", + "@com_google_protobuf//:time_util", "@gtest//:gtest_main", ], ) From cb4c2f2fb91cf68c1c6221ab100b02867c97aaef Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Mon, 24 Feb 2025 11:08:45 -0500 Subject: [PATCH 2/3] Use C++17 for both cxxopt and host_cxxopt For some reason (and only on some platforms -- in particular, the `macos-latest` GitHub runner), it seems that Bazel decides to use `host_cxxopt` (and not `cxxopt`) when compiling the abseil dependency. This breaks the build, because Abseil requires >= C++14. --- .bazelrc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.bazelrc b/.bazelrc index a0ddfd7..b19922f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,9 +1,8 @@ # Specific Bazel build/test options. +build:macos --cxxopt='-std=c++17' --host_cxxopt='-std=c++17' -build:macos --cxxopt='-std=c++17' +build:linux --cxxopt='-std=c++17' --host_cxxopt='-std=c++17' -build:linux --cxxopt='-std=c++17' - -build:windows --cxxopt="/std:c++17" +build:windows --cxxopt="/std:c++17" --host_cxxopt='/std:c++17' build --enable_platform_specific_config From 74f32597cf4c4b62fbc58a158eb606af9c8eef4e Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Tue, 25 Feb 2025 10:26:33 -0500 Subject: [PATCH 3/3] Add comment giving context for disabling Windows build --- .github/workflows/build_and_test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e6caeb2..47a4218 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,4 +1,4 @@ -# Workflow for building and testing flags on macOS and Ubuntu. +# Workflow for building and testing stout on macOS and Ubuntu. name: Build and Run all tests # We use action's triggers 'push' and 'pull_request'. @@ -31,6 +31,9 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: + # TODO: CI on Windows is disabled at the moment, because building + # Protobuf with MSVC and Bazel is not well-supported (#80). Re-enable + # once we have a better build story on Windows. os: ["macos-latest", "ubuntu-latest"] defaults: run: