Skip to content

Commit

Permalink
Merge branch 'refactor/remove-uname-dep' into feat/musl-linux-toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed Nov 14, 2024
2 parents 758f4d6 + c5b8b16 commit 7d81375
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 496 deletions.
3 changes: 2 additions & 1 deletion .bcr/gazelle/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bcr_test_module:
module_path: "../examples/bzlmod_build_file_generation"
matrix:
platform: ["debian11", "macos", "ubuntu2004", "windows"]
bazel: [6.x, 7.x]
# last_rc is to get latest 8.x release. Replace with 8.x when available.
bazel: [7.x, last_rc]
tasks:
run_tests:
name: "Run test module"
Expand Down
3 changes: 2 additions & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bcr_test_module:
module_path: "examples/bzlmod"
matrix:
platform: ["debian11", "macos", "ubuntu2004", "windows"]
bazel: [6.x, 7.x]
# last_rc is to get latest 8.x release. Replace with 8.x when available.
bazel: [7.x, last_rc]
tasks:
run_tests:
name: "Run test module"
Expand Down
30 changes: 27 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,46 @@ Unreleased changes template.

{#v0-0-0-changed}
### Changed
* Nothing yet.

**Breaking**:
* (toolchains) stop exposing config settings in python toolchain alias repos.
Please consider depending on the flags defined in
`//python/config_setting/...` and the `@platforms` package instead.
* (toolchains) consumers who were depending on the `MACOS_NAME` and the `arch`
attribute in the `PLATFORMS` list, please update your code to respect the new
values. The values now correspond to the values available in the
`@platforms//` package constraint values.
* (toolchains) `host_platform` and `interpreter` constants are no longer created
in the `toolchain` generated alias `.bzl` files. If you need to access the
host interpreter during the `repository_rule` evaluation, please use the
`@python_{version}_host//:python` targets created by
{bzl:obj}`python_register_toolchains` and
{bzl:obj}`python_register_multi_toolchains` macros or the {bzl:obj}`python`
bzlmod extension.

Other changes:
* Nothing yet

{#v0-0-0-fixed}
### Fixed
* Nothing yet.
* (toolchains) stop depending on `uname` to get the value of the host platform.

{#v0-0-0-added}
### Added
* (toolchains) allow users to select which variant of the support host toolchain
they would like to use through
`RULES_PYTHON_REPO_TOOLCHAIN_{VERSION}_{OS}_{ARCH}` env variable setting. For
example, this allows one to use `freethreaded` python interpreter in the
`repository_rule` to build a wheel from `sdist`.
* (toolchain) The python interpreters targeting `muslc` libc have been added
for the latest toolchain versions for each minor Python version. You can control
the toolchain selection by using the
{bzl:obj}`//python/config_settings:py_linux_libc` build flag.

{#v0-0-0-removed}
### Removed
* Nothing yet.
* (publish) Remove deprecated `requirements.txt` for the `twine` dependencies.
Please use `requirements_linux.txt` instead.

{#v0-39-0}
## [0.39.0] - 2024-11-13
Expand Down
12 changes: 1 addition & 11 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.
bazel_dep(name = "rules_go", version = "0.41.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_python_gazelle_plugin", version = "0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
single_version_override(
module_name = "gazelle",
patch_strip = 1,
patches = [
# Can be removed once https://github.com/bazel-contrib/bazel-gazelle/issues/1959
# is fixed and released.
"patches/gazelle_native_sh.patch",
],
version = "0.33.0",
)
bazel_dep(name = "gazelle", version = "0.40.0", dev_dependency = True, repo_name = "bazel_gazelle")

internal_dev_deps = use_extension(
"//python/private:internal_dev_deps.bzl",
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps
_py_gazelle_deps()

# This interpreter is used for various rules_python dev-time tools
load("@python//3.11.9:defs.bzl", "interpreter")
interpreter = "@python_3_11_9_host//:python"

#####################
# Install twine for our own runfiles wheel publishing.
Expand All @@ -98,7 +98,7 @@ pip_parse(
name = "rules_python_publish_deps",
python_interpreter_target = interpreter,
requirements_darwin = "//tools/publish:requirements_darwin.txt",
requirements_lock = "//tools/publish:requirements.txt",
requirements_lock = "//tools/publish:requirements_linux.txt",
requirements_windows = "//tools/publish:requirements_windows.txt",
)

Expand Down
32 changes: 0 additions & 32 deletions patches/gazelle_native_sh.patch

This file was deleted.

1 change: 0 additions & 1 deletion private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ multirun(
"//tools/publish:{}.update".format(r)
for r in [
"requirements_universal",
"requirements",
"requirements_darwin",
"requirements_windows",
"requirements_linux",
Expand Down
6 changes: 5 additions & 1 deletion python/private/python_register_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def python_register_toolchains(
platform = platform,
))

host_toolchain(name = name + "_host")
host_toolchain(
name = name + "_host",
platforms = loaded_platforms,
python_version = python_version,
)

toolchain_aliases(
name = name,
Expand Down
74 changes: 74 additions & 0 deletions python/private/toolchain_aliases.bzl
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):
"""Cretae 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,
)
Loading

0 comments on commit 7d81375

Please sign in to comment.