-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!(toolchain): remove uname dep in the repository_rule stage (#…
…2406) Before this PR we would shell out to `uname` on UNIX systems to get the `arch` of the toolchain - on Windows we would not need to do it because there used to be only a single Windows platform. With this change we can correctly support the resolution of the python interpreter on various platforms and I have also added an env variable to customize the selection, so that users can use `musl` or a `freethreaded` interpreter if they wish. As part of this change, I have restricted visibility of the config settings used in the toolchain alias repo so that we are creating fewer targets. This is a very good time to do this before `1.0.0`. Fixes #2145 Work towards #2276 Work towards #2386 Work towards #1211 to unblock #2402 Work towards #1361 --------- Co-authored-by: Richard Levasseur <[email protected]>
- Loading branch information
Showing
10 changed files
with
195 additions
and
109 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,74 @@ | ||
# 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. | ||
|
||
"""Create toolchain alias targets.""" | ||
|
||
load("@rules_python//python:versions.bzl", "PLATFORMS") | ||
|
||
def toolchain_aliases(*, name, platforms, visibility = None, native = native): | ||
"""Create toolchain aliases for the python toolchains. | ||
Args: | ||
name: {type}`str` The name of the current repository. | ||
platforms: {type}`platforms` The list of platforms that are supported | ||
for the current toolchain repository. | ||
visibility: {type}`list[Target] | None` The visibility of the aliases. | ||
native: The native struct used in the macro, useful for testing. | ||
""" | ||
for platform in PLATFORMS.keys(): | ||
if platform not in platforms: | ||
continue | ||
|
||
native.config_setting( | ||
name = platform, | ||
flag_values = PLATFORMS[platform].flag_values, | ||
constraint_values = PLATFORMS[platform].compatible_with, | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
prefix = name | ||
for name in [ | ||
"files", | ||
"includes", | ||
"libpython", | ||
"py3_runtime", | ||
"python_headers", | ||
"python_runtimes", | ||
]: | ||
native.alias( | ||
name = name, | ||
actual = select({ | ||
":" + platform: "@{}_{}//:{}".format(prefix, platform, name) | ||
for platform in platforms | ||
}), | ||
visibility = visibility, | ||
) | ||
|
||
native.alias( | ||
name = "python3", | ||
actual = select({ | ||
":" + platform: "@{}_{}//:{}".format(prefix, platform, "python.exe" if "windows" in platform else "bin/python3") | ||
for platform in platforms | ||
}), | ||
visibility = visibility, | ||
) | ||
native.alias( | ||
name = "pip", | ||
actual = select({ | ||
":" + platform: "@{}_{}//:python_runtimes".format(prefix, platform) | ||
for platform in platforms | ||
if "windows" not in platform | ||
}), | ||
visibility = visibility, | ||
) |
Oops, something went wrong.