fix: fix errors with bazel@head (#2332)
Fix various errors with upcoming Bazel versions
* Use rules_cc 0.0.13 for integration tests.
* Set `allow_empty=True` in local toolchains setup
Fixes https://github.com/bazelbuild/rules_python/issues/2310
diff --git a/python/private/local_runtime_repo_setup.bzl b/python/private/local_runtime_repo_setup.bzl
index 23fa99d..3fa484e 100644
--- a/python/private/local_runtime_repo_setup.bzl
+++ b/python/private/local_runtime_repo_setup.bzl
@@ -61,7 +61,11 @@
cc_library(
name = "_python_headers",
# NOTE: Keep in sync with watch_tree() called in local_runtime_repo
- srcs = native.glob(["include/**/*.h"]),
+ srcs = native.glob(
+ ["include/**/*.h"],
+ # A Python install may not have C headers
+ allow_empty = True,
+ ),
includes = ["include"],
)
@@ -69,10 +73,14 @@
name = "_libpython",
# Don't use a recursive glob because the lib/ directory usually contains
# a subdirectory of the stdlib -- lots of unrelated files
- srcs = native.glob([
- "lib/*{}".format(lib_ext), # Match libpython*.so
- "lib/*{}*".format(lib_ext), # Also match libpython*.so.1.0
- ]),
+ srcs = native.glob(
+ [
+ "lib/*{}".format(lib_ext), # Match libpython*.so
+ "lib/*{}*".format(lib_ext), # Also match libpython*.so.1.0
+ ],
+ # A Python install may not have shared libraries.
+ allow_empty = True,
+ ),
hdrs = [":_python_headers"],
)
diff --git a/tests/integration/compile_pip_requirements/WORKSPACE b/tests/integration/compile_pip_requirements/WORKSPACE
index 0eeab20..fdd6b1d 100644
--- a/tests/integration/compile_pip_requirements/WORKSPACE
+++ b/tests/integration/compile_pip_requirements/WORKSPACE
@@ -1,3 +1,19 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+ name = "protobuf",
+ sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
+ strip_prefix = "protobuf-27.0",
+ url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
+)
+
+http_archive(
+ name = "rules_cc",
+ sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
+ strip_prefix = "rules_cc-0.0.13",
+ urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
+)
+
local_repository(
name = "rules_python",
path = "../../..",
diff --git a/tests/integration/ignore_root_user_error/WORKSPACE b/tests/integration/ignore_root_user_error/WORKSPACE
index c21b01e..a1aa5b5 100644
--- a/tests/integration/ignore_root_user_error/WORKSPACE
+++ b/tests/integration/ignore_root_user_error/WORKSPACE
@@ -1,3 +1,19 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+ name = "protobuf",
+ sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
+ strip_prefix = "protobuf-27.0",
+ url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
+)
+
+http_archive(
+ name = "rules_cc",
+ sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
+ strip_prefix = "rules_cc-0.0.13",
+ urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
+)
+
local_repository(
name = "rules_python",
path = "../../..",
@@ -13,8 +29,6 @@
python_version = "3.9",
)
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
http_archive(
name = "bazel_skylib",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
diff --git a/tests/integration/pip_parse/WORKSPACE b/tests/integration/pip_parse/WORKSPACE
index db0cd0c..e22fbed 100644
--- a/tests/integration/pip_parse/WORKSPACE
+++ b/tests/integration/pip_parse/WORKSPACE
@@ -1,3 +1,19 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+ name = "protobuf",
+ sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
+ strip_prefix = "protobuf-27.0",
+ url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
+)
+
+http_archive(
+ name = "rules_cc",
+ sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
+ strip_prefix = "rules_cc-0.0.13",
+ urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
+)
+
local_repository(
name = "rules_python",
path = "../../..",
diff --git a/tests/integration/py_cc_toolchain_registered/WORKSPACE b/tests/integration/py_cc_toolchain_registered/WORKSPACE
index de90854..b9d9f0f 100644
--- a/tests/integration/py_cc_toolchain_registered/WORKSPACE
+++ b/tests/integration/py_cc_toolchain_registered/WORKSPACE
@@ -1,3 +1,19 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+ name = "protobuf",
+ sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
+ strip_prefix = "protobuf-27.0",
+ url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
+)
+
+http_archive(
+ name = "rules_cc",
+ sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
+ strip_prefix = "rules_cc-0.0.13",
+ urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
+)
+
local_repository(
name = "rules_python",
path = "../../..",