Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions python/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,19 @@ string_flag(
visibility = ["//visibility:public"],
)

config_setting(
alias(
name = "is_py_freethreaded",
flag_values = {":py_freethreaded": FreeThreadedFlag.YES},
actual = ":_is_py_freethreaded_yes",
deprecation = "not actually public, please create your own config_setting using the flag that rules_python exposes",
tags = ["manual"],
visibility = ["//visibility:public"],
)

config_setting(
alias(
name = "is_py_non_freethreaded",
flag_values = {":py_freethreaded": FreeThreadedFlag.NO},
actual = ":_is_py_freethreaded_no",
deprecation = "not actually public, please create your own config_setting using the flag that rules_python exposes",
tags = ["manual"],
visibility = ["//visibility:public"],
)

Expand Down
2 changes: 1 addition & 1 deletion python/private/config_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def construct_config_settings(*, name, default_version, versions, minor_mapping,
)
native.config_setting(
name = "_is_py_linux_libc_musl",
flag_values = {libc: "glibc"},
flag_values = {libc: "musl"},
visibility = _NOT_ACTUALLY_PUBLIC,
)
freethreaded = Label("//python/config_settings:py_freethreaded")
Expand Down
19 changes: 10 additions & 9 deletions python/private/hermetic_runtime_repo_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ load(":glob_excludes.bzl", "glob_excludes")
load(":py_exec_tools_toolchain.bzl", "py_exec_tools_toolchain")
load(":version.bzl", "version")

_IS_FREETHREADED = Label("//python/config_settings:is_py_freethreaded")
_IS_FREETHREADED_YES = Label("//python/config_settings:_is_py_freethreaded_yes")
_IS_FREETHREADED_NO = Label("//python/config_settings:_is_py_freethreaded_no")

def define_hermetic_runtime_toolchain_impl(
*,
Expand Down Expand Up @@ -87,16 +88,16 @@ def define_hermetic_runtime_toolchain_impl(
cc_import(
name = "interface",
interface_library = select({
_IS_FREETHREADED: "libs/python{major}{minor}t.lib".format(**version_dict),
"//conditions:default": "libs/python{major}{minor}.lib".format(**version_dict),
_IS_FREETHREADED_YES: "libs/python{major}{minor}t.lib".format(**version_dict),
_IS_FREETHREADED_NO: "libs/python{major}{minor}.lib".format(**version_dict),
}),
system_provided = True,
)
cc_import(
name = "abi3_interface",
interface_library = select({
_IS_FREETHREADED: "libs/python3t.lib",
"//conditions:default": "libs/python3.lib",
_IS_FREETHREADED_YES: "libs/python3t.lib",
_IS_FREETHREADED_NO: "libs/python3.lib",
}),
system_provided = True,
)
Expand All @@ -115,10 +116,10 @@ def define_hermetic_runtime_toolchain_impl(
includes = [
"include",
] + select({
_IS_FREETHREADED: [
_IS_FREETHREADED_YES: [
"include/python{major}.{minor}t".format(**version_dict),
],
"//conditions:default": [
_IS_FREETHREADED_NO: [
"include/python{major}.{minor}".format(**version_dict),
"include/python{major}.{minor}m".format(**version_dict),
],
Expand Down Expand Up @@ -224,8 +225,8 @@ def define_hermetic_runtime_toolchain_impl(
implementation_name = "cpython",
# See https://peps.python.org/pep-3147/ for pyc tag infix format
pyc_tag = select({
_IS_FREETHREADED: "cpython-{major}{minor}t".format(**version_dict),
"//conditions:default": "cpython-{major}{minor}".format(**version_dict),
_IS_FREETHREADED_YES: "cpython-{major}{minor}t".format(**version_dict),
_IS_FREETHREADED_NO: "cpython-{major}{minor}".format(**version_dict),
}),
)

Expand Down
22 changes: 11 additions & 11 deletions python/private/pypi/config_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ FLAGS = struct(
"is_pip_whl_auto",
"is_pip_whl_no",
"is_pip_whl_only",
"is_py_freethreaded",
"is_py_non_freethreaded",
"_is_py_freethreaded_yes",
"_is_py_freethreaded_no",
"pip_whl_glibc_version",
"pip_whl_muslc_version",
"pip_whl_osx_arch",
Expand Down Expand Up @@ -205,12 +205,12 @@ def _dist_config_settings(*, suffix, plat_flag_values, python_version, **kwargs)
for name, f, compatible_with in [
("py_none", _flags.whl, None),
("py3_none", _flags.whl_py3, None),
("py3_abi3", _flags.whl_py3_abi3, (FLAGS.is_py_non_freethreaded,)),
("py3_abi3", _flags.whl_py3_abi3, (FLAGS._is_py_freethreaded_no,)),
("none", _flags.whl_pycp3x, None),
("abi3", _flags.whl_pycp3x_abi3, (FLAGS.is_py_non_freethreaded,)),
("abi3", _flags.whl_pycp3x_abi3, (FLAGS._is_py_freethreaded_no,)),
# The below are not specializations of one another, they are variants
(cpv, _flags.whl_pycp3x_abicp, (FLAGS.is_py_non_freethreaded,)),
(cpv + "t", _flags.whl_pycp3x_abicp, (FLAGS.is_py_freethreaded,)),
(cpv, _flags.whl_pycp3x_abicp, (FLAGS._is_py_freethreaded_no,)),
(cpv + "t", _flags.whl_pycp3x_abicp, (FLAGS._is_py_freethreaded_yes,)),
]:
if (f, compatible_with) in used_flags:
# This should never happen as all of the different whls should have
Expand All @@ -237,12 +237,12 @@ def _dist_config_settings(*, suffix, plat_flag_values, python_version, **kwargs)
for name, f, compatible_with in [
("py_none", _flags.whl_plat, None),
("py3_none", _flags.whl_plat_py3, None),
("py3_abi3", _flags.whl_plat_py3_abi3, (FLAGS.is_py_non_freethreaded,)),
("py3_abi3", _flags.whl_plat_py3_abi3, (FLAGS._is_py_freethreaded_no,)),
("none", _flags.whl_plat_pycp3x, None),
("abi3", _flags.whl_plat_pycp3x_abi3, (FLAGS.is_py_non_freethreaded,)),
("abi3", _flags.whl_plat_pycp3x_abi3, (FLAGS._is_py_freethreaded_no,)),
# The below are not specializations of one another, they are variants
(cpv, _flags.whl_plat_pycp3x_abicp, (FLAGS.is_py_non_freethreaded,)),
(cpv + "t", _flags.whl_plat_pycp3x_abicp, (FLAGS.is_py_freethreaded,)),
(cpv, _flags.whl_plat_pycp3x_abicp, (FLAGS._is_py_freethreaded_no,)),
(cpv + "t", _flags.whl_plat_pycp3x_abicp, (FLAGS._is_py_freethreaded_yes,)),
]:
if (f, compatible_with) in used_flags:
# This should never happen as all of the different whls should have
Expand Down Expand Up @@ -329,7 +329,7 @@ def _dist_config_setting(*, name, compatible_with = None, native = native, **kwa
compatible_with: {type}`tuple[Label]` A collection of config settings that are
compatible with the given dist config setting. For example, if only
non-freethreaded python builds are allowed, add
FLAGS.is_py_non_freethreaded here.
FLAGS._is_py_freethreaded_no here.
native (struct): The struct containing alias and config_setting rules
to use for creating the objects. Can be overridden for unit tests
reasons.
Expand Down
12 changes: 9 additions & 3 deletions python/private/toolchain_aliases.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

"""Create toolchain alias targets."""

load("@rules_python//python:versions.bzl", "PLATFORMS")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("//python:versions.bzl", "PLATFORMS")

def toolchain_aliases(*, name, platforms, visibility = None, native = native):
"""Create toolchain aliases for the python toolchains.
Expand All @@ -30,12 +31,17 @@ def toolchain_aliases(*, name, platforms, visibility = None, native = native):
if platform not in platforms:
continue

_platform = "_" + platform
native.config_setting(
name = platform,
flag_values = PLATFORMS[platform].flag_values,
name = _platform,
constraint_values = PLATFORMS[platform].compatible_with,
visibility = ["//visibility:private"],
)
selects.config_setting_group(
name = platform,
match_all = PLATFORMS[platform].target_settings + [_platform],
visibility = ["//visibility:private"],
)

prefix = name
for name in [
Expand Down
8 changes: 8 additions & 0 deletions tests/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
load(":defs.bzl", "define_toolchain_tests")
Expand All @@ -30,3 +31,10 @@ py_reconfig_test(
"@platforms//cpu:x86_64",
] if BZLMOD_ENABLED else ["@platforms//:incompatible"],
)

build_test(
name = "build_test",
targets = [
"@python_3_11//:python_headers",
],
)