Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ buildifier:
build_flags:
- "--noenable_bzlmod"
- "--build_tag_filters=-integration-test"
# recent abseil-cpp requires C++17 which is not used by default in Bazel 7
- "--cxxopt=-std=c++17"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit more about this? I'm guessing this is coming from protobuf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, for protobuf 33.0 (and its dependency abseil-cpp) C++17 is the minimum supported version (https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md)

I'm trying to add these flags to make it work with Bazel 7 but it is not straightforward as it is still failing for tests on windows (https://buildkite.com/bazel/rules-python-python/builds/13428#0199f84a-0a7c-4ed7-8b30-6ab8ef898f71) where -std=c++17 is not recognized. Do you have any suggestions for that?

- "--host_cxxopt=-std=c++17"
test_flags:
- "--noenable_bzlmod"
- "--test_tag_filters=-integration-test"
# recent abseil-cpp requires C++17 which is not used by default in Bazel 7
- "--cxxopt=-std=c++17"
- "--host_cxxopt=-std=c++17"
.common_workspace_flags: &common_workspace_flags
skip_in_bazel_downstream_pipeline: "Bazel 9 doesn't support workspace"
test_flags:
Expand Down
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module(

bazel_dep(name = "bazel_features", version = "1.21.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "rules_cc", version = "0.2.10")
bazel_dep(name = "platforms", version = "0.0.11")

# Those are loaded only when using py_proto_library
# Use py_proto_library directly from protobuf repository
bazel_dep(name = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
bazel_dep(name = "protobuf", version = "33.0", repo_name = "com_google_protobuf")

rules_python_config = use_extension("//python/extensions:config.bzl", "config")
use_repo(
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ load("//:internal_dev_setup.bzl", "rules_python_internal_setup")

rules_python_internal_setup()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

compatibility_proxy_repo()

load("@pythons_hub//:versions.bzl", "PYTHON_VERSIONS")
load("//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")

Expand Down
7 changes: 7 additions & 0 deletions examples/build_file_generation/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist
# Perform general setup
py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

# We now register a hermetic Python interpreter rather than relying on a system-installed interpreter.
# This toolchain will allow bazel to download a specific python version, and use that version
# for compilation.
Expand Down
7 changes: 7 additions & 0 deletions examples/multi_python_versions/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

default_python_version = "3.9"

python_register_multi_toolchains(
Expand Down
7 changes: 7 additions & 0 deletions examples/pip_parse/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python_3_9",
python_version = "3.9.13",
Expand Down
7 changes: 7 additions & 0 deletions examples/pip_parse_vendored/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
Expand Down
7 changes: 7 additions & 0 deletions examples/pip_repository_annotations/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
Expand Down
20 changes: 11 additions & 9 deletions examples/py_proto_library/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist
# We install the rules_python dependencies using the function below.
py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
)

# Then we need to setup dependencies in order to use py_proto_library
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "com_google_protobuf",
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
strip_prefix = "protobuf-26.1",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v26.1.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

# Needed to load @compatibility_proxy for rules_java
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
rules_java_dependencies()
7 changes: 7 additions & 0 deletions gazelle/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ load("//:deps.bzl", _py_gazelle_deps = "gazelle_deps")

# gazelle:repository_macro deps.bzl%go_deps
_py_gazelle_deps()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()
12 changes: 6 additions & 6 deletions internal_dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def rules_python_internal_deps():

http_archive(
name = "com_google_protobuf",
sha256 = "23082dca1ca73a1e9c6cbe40097b41e81f71f3b4d6201e36c134acc30a1b3660",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc2/protobuf-29.0-rc2.zip",
strip_prefix = "protobuf-29.0-rc2",
sha256 = "aaddf29b205ed915100a5fd096e8252842b67da9accfb7ba91ec3680ea307e45",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v33.0/protobuf-33.0.zip",
strip_prefix = "protobuf-33.0",
)

# Needed for stardoc
Expand Down Expand Up @@ -238,9 +238,9 @@ def rules_python_internal_deps():

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"],
sha256 = "b8b918a85f9144c01f6cfe0f45e4f2838c7413961a8ff23bc0c6cdf8bb07a3b6",
strip_prefix = "rules_cc-0.1.5",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.2.10/rules_cc-0.2.10.tar.gz"],
sha256 = "774fd6cb9f90f98f1d26c776896b16a517a1af65337fcfaa705261df175f04a6",
strip_prefix = "rules_cc-0.2.10",
)

http_archive(
Expand Down
22 changes: 16 additions & 6 deletions python/private/py_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,30 @@ def py_repositories(transition_settings = []):
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
],
)

# For this version of rules_cc, loading compatibility_proxy_repo in WORKSPACE is needed
http_archive(
name = "rules_cc",
sha256 = "b8b918a85f9144c01f6cfe0f45e4f2838c7413961a8ff23bc0c6cdf8bb07a3b6",
strip_prefix = "rules_cc-0.1.5",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz"],
sha256 = "774fd6cb9f90f98f1d26c776896b16a517a1af65337fcfaa705261df175f04a6",
strip_prefix = "rules_cc-0.2.10",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.2.10/rules_cc-0.2.10.tar.gz"],
)

# Needed by rules_cc 0.2.10
http_archive(
name = "bazel_features",
sha256 = "adc8ddf121917f197f75c5245dfa8d7b1619f10a1002e25062b093b7957f2798",
strip_prefix = "bazel_features-1.37.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.37.0/bazel_features-v1.37.0.tar.gz",
)

# Needed by rules_cc, triggered by @rules_java_prebuilt in Bazel by using @rules_cc//cc:defs.bzl
# NOTE: This name must be com_google_protobuf until Bazel drops WORKSPACE
# support; Bazel itself has references to com_google_protobuf.
http_archive(
name = "com_google_protobuf",
sha256 = "23082dca1ca73a1e9c6cbe40097b41e81f71f3b4d6201e36c134acc30a1b3660",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc2/protobuf-29.0-rc2.zip",
strip_prefix = "protobuf-29.0-rc2",
sha256 = "aaddf29b205ed915100a5fd096e8252842b67da9accfb7ba91ec3680ea307e45",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v33.0/protobuf-33.0.zip",
strip_prefix = "protobuf-33.0",
)
pypi_deps()
7 changes: 7 additions & 0 deletions tests/integration/compile_pip_requirements/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/custom_commands/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python_3_11",
python_version = "3.11",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/ignore_root_user_error/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
ignore_root_user_error = True,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/local_toolchains/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module(name = "module_under_test")
bazel_dep(name = "rules_python", version = "0.0.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "rules_cc", version = "0.2.10")

local_path_override(
module_name = "rules_python",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/local_toolchains/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ py_repositories(
],
)

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

load("@rules_python//python/local_toolchains:repos.bzl", "local_runtime_repo", "local_runtime_toolchains_repo")

# Step 1: Define the python runtime.
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/pip_parse/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copy/pasting this same setup to every downstream workspace, create a second setup function and load and call that.

python/repositories_deps.bzl

which does the 4 lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried having a file load_cc_deps.bzl that looks like this:

load("@bazel_features//:deps.bzl", "bazel_features_deps")
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

def add_cc_deps():
  bazel_features_deps()
  compatibility_proxy_repo()

but it did not work:

ERROR: Failed to load Starlark extension '@@bazel_features_version//:version.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.

because bazel_features_deps() call needs to happen before the load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo") and we cannot have load statements in starlark functions, or what you're suggesting is different?

bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python39",
python_version = "3.9",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/py_cc_toolchain_registered/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_regist

py_repositories()

# Needed for rules_cc 0.2.10
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()

python_register_toolchains(
name = "python_3_11",
python_version = "3.11",
Expand Down