diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2025-05-05 18:23:51 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2025-06-24 12:56:57 +0200 |
commit | 5e9234326754cc83140ecaae798c31fe3ec5c165 (patch) | |
tree | d3341471eb15bd7cf5e4f7af5992f19e0108bd30 | |
parent | cb85f75e9c6bdfbb69edb020dc49e83f77f792b9 (diff) | |
download | justbuild-5e9234326754cc83140ecaae798c31fe3ec5c165.tar.gz |
BazelNetwork: Read supported remote RBE version
4 files changed, 41 insertions, 1 deletions
diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index 7fccc2c6..fc46db70 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -42,6 +42,7 @@ ] , "proto": [ ["@", "bazel_remote_apis", "", "remote_execution_proto"] + , ["@", "bazel_remote_apis", "", "semver_proto"] , ["@", "googleapis", "", "google_bytestream_proto"] , ["@", "googleapis", "", "google_longrunning_operations_proto"] , ["@", "googleapis", "", "google_rpc_status_proto"] diff --git a/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.cpp index 20a1dce1..00d113d8 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.cpp @@ -21,6 +21,7 @@ #include <grpcpp/grpcpp.h> +#include "build/bazel/semver/semver.pb.h" #include "fmt/core.h" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/common/remote/client_common.hpp" @@ -28,6 +29,14 @@ #include "src/buildtool/logging/log_level.hpp" namespace { + +[[nodiscard]] auto ParseSemVer(build::bazel::semver::SemVer const& + version) noexcept -> Capabilities::Version { + return Capabilities::Version{.major = version.major(), + .minor = version.minor(), + .patch = version.patch()}; +} + [[nodiscard]] auto Parse(std::optional<bazel_re::ServerCapabilities> response) noexcept -> Capabilities { if (not response.has_value()) { @@ -50,8 +59,16 @@ namespace { } return Capabilities{ .MaxBatchTransferSize = max_batch, - }; + .low_api_version = response->has_deprecated_api_version() + ? ParseSemVer(response->deprecated_api_version()) + : (response->has_low_api_version() // NOLINT + ? ParseSemVer(response->low_api_version()) + : Capabilities::kMinVersion), + .high_api_version = response->has_high_api_version() + ? ParseSemVer(response->high_api_version()) + : Capabilities::kMaxVersion}; } + } // namespace BazelCapabilitiesClient::BazelCapabilitiesClient( diff --git a/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.hpp b/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.hpp index b33bb2de..ddff0ef0 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.hpp @@ -16,7 +16,9 @@ #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_CAPABILITIES_CLIENT_HPP #include <cstddef> +#include <cstdint> #include <functional> +#include <limits> #include <memory> #include <shared_mutex> #include <string> @@ -34,8 +36,24 @@ namespace bazel_re = build::bazel::remote::execution::v2; struct Capabilities final { using Ptr = gsl::not_null<std::shared_ptr<Capabilities>>; + struct Version { + std::int32_t major{}; + std::int32_t minor{}; + std::int32_t patch{}; + + [[nodiscard]] auto operator<=>(Version const& other) const noexcept = + default; + }; + + static constexpr Version kMinVersion{.major = 0, .minor = 0, .patch = 0}; + static constexpr Version kMaxVersion{ + .major = std::numeric_limits<std::int32_t>::max(), + .minor = std::numeric_limits<std::int32_t>::max(), + .patch = std::numeric_limits<std::int32_t>::max()}; std::size_t const MaxBatchTransferSize = MessageLimits::kMaxGrpcLength; + Version const low_api_version = kMinVersion; + Version const high_api_version = kMaxVersion; }; class BazelCapabilitiesClient final { diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp index 4dbf1467..403e0f05 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp @@ -97,6 +97,10 @@ class BazelNetwork { std::vector<std::string> const& output_files) const noexcept -> std::optional<bazel_re::ActionResult>; + [[nodiscard]] auto GetCapabilities() const noexcept -> Capabilities::Ptr { + return capabilities_->GetCapabilities(instance_name_); + } + private: std::string const instance_name_; std::unique_ptr<BazelCapabilitiesClient> capabilities_; |