forked from bazelbuild/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(toolchains): register py cc toolchain for workspace builds
The workspace `python_register_toolchains()` only registered the plain Python toolchain by its specific name. The py cc toolchain wasn't also being named. This meant things like `//python/cc:current_py_cc_headers` couldn't find their toolchain. Bzlmod doesn't have this problem because it uses the `:all` pattern to register everything. To fix, also register the py cc toolchain where the plain Python toolchain is registered, which makes it available. Fixes bazelbuild#1669
- Loading branch information
Showing
10 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This aids debugging on failure | ||
build --toolchain_resolution_debug=python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load(":defs.bzl", "py_cc_toolchain_available_test") | ||
|
||
# Simple test to verify that the py_cc_toolchain is registered and available | ||
# by default (for bzlmod) and when users setup a hermetic toolchain (workspace) | ||
py_cc_toolchain_available_test(name = "py_cc_toolchain_available_test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module(name = "py_cc_toolchain_registered") | ||
|
||
bazel_dep(name = "rules_python", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_python", | ||
path = "../../..", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local_repository( | ||
name = "rules_python", | ||
path = "../../..", | ||
) | ||
|
||
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") | ||
|
||
py_repositories() | ||
|
||
python_register_toolchains( | ||
name = "python_3_11", | ||
python_version = "3.11", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2022 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
def _py_cc_toolchain_available_test_impl(ctx): | ||
toolchain = ctx.toolchains["@rules_python//python/cc:toolchain_type"] | ||
|
||
if toolchain == None: | ||
fail("expected @rules_python//python/cc:toolchain_type toolchain " + | ||
"to be found, but it was not found") | ||
|
||
executable = ctx.actions.declare_file(ctx.label.name) | ||
ctx.actions.write(executable, "# no-op file", is_executable = True) | ||
return [DefaultInfo( | ||
executable = executable, | ||
)] | ||
|
||
py_cc_toolchain_available_test = rule( | ||
implementation = _py_cc_toolchain_available_test_impl, | ||
toolchains = [ | ||
config_common.toolchain_type( | ||
"@rules_python//python/cc:toolchain_type", | ||
mandatory = False, | ||
), | ||
], | ||
test = True, | ||
) |