Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bzlmod): support cross-platform whl setups within the main hub repo #1837

Merged
merged 20 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9d35b35
fix(pip.parse): make the pip extension reproducible if PyPI is not ca…
aignas Jun 2, 2024
3fd6821
comment: address comments and set the internal pip extension to use P…
aignas Jun 3, 2024
4c4b46f
fix(bzlmod): do not throw away yanked PyPI packages
aignas Jun 3, 2024
0587c37
fix(whl_library): add `arm` to the list of known architectures
aignas Jun 3, 2024
52a7a5e
fix(dev_pip): we only have `//dev_pip:sphinx` dependencies for non-wi…
aignas Jun 3, 2024
cc1857b
feat(internal): add a function to get a unique pip repo name
aignas Jun 3, 2024
870cada
feat(internal): add a function to generate config settings for all whls
aignas Jun 3, 2024
2d20670
feat(internal): support inferring the config settings from dist filen…
aignas Jun 3, 2024
c3dc7b0
feat(toolchain): use `py_linux_libc` flag value
aignas Jun 3, 2024
bf4c35c
feat(bzlmod): fetch and configure platform specific wheels
aignas Jun 3, 2024
4e2d7df
Merge branch 'main' into feat/multi-platform-whls
aignas Jun 3, 2024
8a6bda5
fixup! feat(toolchain): use `py_linux_libc` flag value
aignas Jun 4, 2024
319409d
fixup! fixup! feat(toolchain): use `py_linux_libc` flag value
aignas Jun 4, 2024
65d8278
fixup! feat(internal): add a function to generate config settings for…
aignas Jun 4, 2024
bc1cdef
fixup! feat(internal): add a function to generate config settings for…
aignas Jun 4, 2024
6cdb534
fixup! feat(internal): support inferring the config settings from dis…
aignas Jun 4, 2024
445337e
fixup! fixup! feat(internal): support inferring the config settings f…
aignas Jun 4, 2024
57d7a3f
Merge branch 'main' into feat/multi-platform-whls
aignas Jun 6, 2024
495758c
doc: add a not to CHANGELOG on the naming of the repos
aignas Jun 6, 2024
6dde587
test: add an additional test to ensure that the aliases are the same
aignas Jun 6, 2024
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
2 changes: 2 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ bzl_library(
name = "py_toolchain_suite_bzl",
srcs = ["py_toolchain_suite.bzl"],
deps = [
":config_settings_bzl",
":text_util_bzl",
":toolchain_types_bzl",
"@bazel_skylib//lib:selects",
],
Expand Down
59 changes: 46 additions & 13 deletions python/private/py_toolchain_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
"""Create the toolchain defs in a BUILD.bazel file."""

load("@bazel_skylib//lib:selects.bzl", "selects")
load(":config_settings.bzl", "is_python_config_setting")
load(
":toolchain_types.bzl",
"EXEC_TOOLS_TOOLCHAIN_TYPE",
"PY_CC_TOOLCHAIN_TYPE",
"TARGET_TOOLCHAIN_TYPE",
)

def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_python_version_constraint, **kwargs):
def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_python_version_constraint, flag_values, **kwargs):
"""For internal use only.

Args:
prefix: Prefix for toolchain target names.
user_repository_name: The name of the user repository.
python_version: The full (X.Y.Z) version of the interpreter.
set_python_version_constraint: True or False as a string.
flag_values: Extra flag values to match for this toolchain.
**kwargs: extra args passed to the `toolchain` calls.

"""
Expand All @@ -38,23 +40,54 @@ def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_pyth
# string as we cannot have list of bools in build rule attribues.
# This if statement does not appear to work unless it is in the
# toolchain file.
if set_python_version_constraint == "True":
if set_python_version_constraint in ["True", "False"]:
major_minor, _, _ = python_version.rpartition(".")

match_any = []
for i, v in enumerate([major_minor, python_version]):
name = "{prefix}_{python_version}_{i}".format(
prefix = prefix,
python_version = python_version,
i = i,
)
match_any.append(name)
if flag_values:
is_python_config_setting(
name = name,
python_version = v,
flag_values = flag_values,
visibility = ["//visibility:private"],
)
else:
native.alias(
name = name,
actual = Label("//python/config_settings:is_python_%s" % v),
visibility = ["//visibility:private"],
)

if set_python_version_constraint == "False":
name = "{prefix}_version_setting_no_python_version".format(prefix = prefix)
match_any.append(name)
native.config_setting(
name = name,
flag_values = flag_values | {
str(Label("//python/config_settings:python_version")): "",
},
visibility = ["//visibility:private"],
)

name = "{prefix}_version_setting_{python_version}".format(
prefix = prefix,
python_version = python_version,
visibility = ["//visibility:private"],
)
selects.config_setting_group(
name = prefix + "_version_setting",
match_any = [
Label("//python/config_settings:is_python_%s" % v)
for v in [
major_minor,
python_version,
]
],
name = name,
match_any = match_any,
visibility = ["//visibility:private"],
)
target_settings = [prefix + "_version_setting"]
elif set_python_version_constraint == "False":
target_settings = []

target_settings = [name]
else:
fail(("Invalid set_python_version_constraint value: got {} {}, wanted " +
"either the string 'True' or the string 'False'; " +
Expand Down
8 changes: 7 additions & 1 deletion python/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ load(
"WINDOWS_NAME",
)
load("//python/private:repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
load("//python/private:text_util.bzl", "render")

def get_repository_name(repository_workspace):
dummy_label = "//:_"
Expand Down Expand Up @@ -64,10 +65,15 @@ py_toolchain_suite(
user_repository_name = "{user_repository_name}_{platform}",
prefix = "{prefix}{platform}",
target_compatible_with = {compatible_with},
flag_values = {flag_values},
python_version = "{python_version}",
set_python_version_constraint = "{set_python_version_constraint}",
)""".format(
compatible_with = meta.compatible_with,
compatible_with = render.indent(render.list(meta.compatible_with)).lstrip(),
flag_values = render.indent(render.dict(
aignas marked this conversation as resolved.
Show resolved Hide resolved
meta.flag_values,
key_repr = lambda x: repr(str(x)), # this is to correctly display labels
)).lstrip(),
platform = platform,
set_python_version_constraint = set_python_version_constraint,
user_repository_name = user_repository_name,
Expand Down
21 changes: 21 additions & 0 deletions python/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ PLATFORMS = {
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
flag_values = {},
os_name = MACOS_NAME,
# Matches the value returned from:
# repository_ctx.execute(["uname", "-m"]).stdout.strip()
Expand All @@ -511,6 +512,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
# Note: this string differs between OSX and Linux
# Matches the value returned from:
Expand All @@ -522,6 +526,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:armv7",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
arch = "armv7",
),
Expand All @@ -530,6 +537,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
# Note: this string differs between OSX and Linux
# Matches the value returned from:
Expand All @@ -541,6 +551,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:riscv64",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
arch = "riscv64",
),
Expand All @@ -549,6 +562,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
# Note: this string differs between OSX and Linux
# Matches the value returned from:
Expand All @@ -560,6 +576,7 @@ PLATFORMS = {
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
flag_values = {},
os_name = MACOS_NAME,
arch = "x86_64",
),
Expand All @@ -568,6 +585,7 @@ PLATFORMS = {
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
flag_values = {},
os_name = WINDOWS_NAME,
arch = "x86_64",
),
Expand All @@ -576,6 +594,9 @@ PLATFORMS = {
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
flag_values = {
Label("//python/config_settings:py_linux_libc"): "glibc",
},
os_name = LINUX_NAME,
arch = "x86_64",
),
Expand Down