wrp
wrp

Reputation: 99

Can't use python gRPC rules in bazel - getting "Constraints from @bazel_tools//platforms have been removed" error

Trying to create a Python gRPC library, using gRPC v1.45.0 (upgrading could be complicated and also produced different issues; more on that in a moment). In my WORKSPACE, I have

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()

When I attempt to build my gRPC library, I get the following bazel error:

Repository rule http_archive defined at:
  /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/bazel_tools/tools/build_defs/repo/http.bzl:370:31: in <toplevel>
ERROR: /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/bazel_tools/platforms/BUILD:89:6: in alias rule @bazel_tools//platforms:windows: Constraints from @bazel_tools//platforms have been removed. Please use constraints from @platforms repository embedded in Bazel, or preferably declare dependency on https://github.com/bazelbuild/platforms. See https://github.com/bazelbuild/bazel/issues/8622 for details.
ERROR: /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/bazel_tools/platforms/BUILD:89:6: Analysis of target '@bazel_tools//platforms:windows' failed
INFO: Repository cython instantiated at:
  /usr/local/home/bill/depot/src/project/WORKSPACE:448:10: in <toplevel>
  /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/com_github_grpc_grpc/bazel/grpc_deps.bzl:458:21: in grpc_deps
  /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/com_github_grpc_grpc/bazel/grpc_python_deps.bzl:69:21: in grpc_python_deps
Repository rule http_archive defined at:
  /usr/local/home/bill/.cache/bazel/_bazel_bill/254c50c69c3701cca4e904bef759573b/external/bazel_tools/tools/build_defs/repo/http.bzl:370:31: in <toplevel>

I checked the bug; it suggests adding the flag --incompatible_use_platforms_repo_for_constraints. Adding the flag at build does not remove this error.

I tried upgrading my gRPC to a new version (1.50.0), and I get a different error on grpc_extra_deps: Error in fail: go_register_toolchains: version set after go sdk rule declared (go_sdk). Apparently grpc_extra_deps also tries to set the version after grpc_deps, and I don't know how to make it not do that.

Both of these issues occur within the gRPC package itself, so I don't know how to get around it in my own build setup. Is there a fix for this?

Upvotes: 3

Views: 1303

Answers (2)

Bohdan Yarema
Bohdan Yarema

Reputation: 121

I traced this error down to a new release of bazelbuild (6.0.0). You can force it to use the previous release by setting the environment variable

USE_BAZEL_VERSION=5.4.0

This fixed the error for me. Good luck!

Upvotes: 2

SG_Bazel
SG_Bazel

Reputation: 355

For the first error please check whether you used any constraints in building it with grpc. Try using the platforms. 2. Remove if there are any deps used, if not solved then refer this

Upvotes: -1

Related Questions