Skip to content

Commit a9df135

Browse files
committed
WIP adding support for cpython build_option
1 parent 5a06d94 commit a9df135

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

python/private/py_exec_tools_toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ py_exec_tools_toolchain = rule(
4343
Provides a toolchain for build time tools.
4444
4545
This provides `ToolchainInfo` with the following attributes:
46-
* `exec_tools`: {type}`PyExecToolsInfo`
46+
* `exec_tools`: {type}`PyExecToolsInfo`
4747
* `toolchain_label`: {type}`Label` _only present when `--visibile_for_testing=True`
4848
for internal testing_. The rule's label; this allows identifying what toolchain
4949
implmentation was selected for testing purposes.

python/private/python_register_toolchains.bzl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,37 @@ def python_register_toolchains(
109109
if not sha256:
110110
continue
111111

112+
build_option = tool_versions[python_version].get("build_option", None)
112113
loaded_platforms.append(platform)
113-
(release_filename, urls, strip_prefix, patches, patch_strip) = get_release_info(platform, python_version, base_url, tool_versions)
114+
(release_filename, urls, strip_prefix, patches, patch_strip, free_threading) = get_release_info(
115+
platform, python_version, base_url, tool_versions, build_option=build_option
116+
)
114117

118+
build_opt_str = ("_" + build_option.replace("+", "-")) if build_option else ""
119+
name_with_build_opt = "{name}{build_opt}".format(
120+
name = name,
121+
build_opt = build_opt_str
122+
)
115123
# allow passing in a tool version
116124
coverage_tool = None
117125
coverage_tool = tool_versions[python_version].get("coverage_tool", {}).get(platform, None)
118126
if register_coverage_tool and coverage_tool == None:
119127
coverage_tool = coverage_dep(
120128
name = "{name}_{platform}_coverage".format(
121-
name = name,
129+
name = name_with_build_opt,
122130
platform = platform,
123131
),
124132
python_version = python_version,
125133
platform = platform,
126134
visibility = ["@{name}_{platform}//:__subpackages__".format(
127-
name = name,
135+
name = name_with_build_opt,
128136
platform = platform,
129137
)],
130138
)
131139

132-
flag_values = tool_versions[python_version].get("flag_values", None)
133-
free_threading_label = "@rules_python//python/config_settings:free_threading"
134-
free_threading = False
135-
if flag_values:
136-
free_threading = flag_values.get(free_threading_label, False) == "yes"
137-
suffix = tool_versions[python_version].get("suffix", "")
138140
python_repository(
139141
name = "{name}_{platform}".format(
140-
name = name,
142+
name = name_with_build_opt,
141143
platform = platform,
142144
),
143145
sha256 = sha256,
@@ -166,12 +168,12 @@ def python_register_toolchains(
166168
platform = platform,
167169
))
168170

169-
host_toolchain(name = name + "_host")
171+
host_toolchain(name = name_with_build_opt + "_host")
170172

171173
toolchain_aliases(
172174
name = name,
173175
python_version = python_version,
174-
user_repository_name = name,
176+
user_repository_name = name_with_build_opt,
175177
platforms = loaded_platforms,
176178
)
177179

@@ -183,5 +185,5 @@ def python_register_toolchains(
183185
name = toolchain_repo_name,
184186
python_version = python_version,
185187
set_python_version_constraint = set_python_version_constraint,
186-
user_repository_name = name,
188+
user_repository_name = name_with_build_opt,
187189
)

python/private/python_repository.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ def _python_repository_impl(rctx):
127127
for patch in patches:
128128
rctx.patch(patch, strip = rctx.attr.patch_strip)
129129

130+
ft_postfix = "t" if free_threading else ""
130131
# Write distutils.cfg to the Python installation.
131132
if "windows" in platform:
132133
distutils_path = "Lib/distutils/distutils.cfg"
133134
else:
134-
ft_postfix = "t" if free_threading else ""
135135
distutils_path = "lib/python{}{}/distutils/distutils.cfg".format(python_short_version, ft_postfix)
136136
if rctx.attr.distutils:
137137
rctx.file(distutils_path, rctx.read(rctx.attr.distutils))
@@ -145,7 +145,7 @@ def _python_repository_impl(rctx):
145145
# dyld lookup errors. To fix, set the full path to the dylib as
146146
# it appears in the Bazel workspace as its LC_ID_DYLIB using
147147
# the `install_name_tool` bundled with macOS.
148-
dylib = "libpython{}.dylib".format(python_short_version)
148+
dylib = "libpython{}{}.dylib".format(python_short_version, ft_postfix)
149149
repo_utils.execute_checked(
150150
rctx,
151151
op = "python_repository.FixUpDyldIdPath",

python/versions.bzl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,16 @@ TOOL_VERSIONS = {
572572
"x86_64-unknown-linux-gnu": "455200e1a202e9d9ef4b630c04af701c0a91dcaa6462022efc76893fc762ec95",
573573
},
574574
"strip_prefix": "python",
575+
# "build_variants": {
576+
# "freethreaded+pgo-full": {
577+
# "sha256": {
578+
# "aarch64-apple-darwin": "da12e516f709b62548b6762c6d3ba23c38eadf06209c213a600d3b670eca055f",
579+
# "x86_64-apple-darwin": "ce0002d524a687db9094fc8777640f6df653efa3ca0676e7da17be4142ee796a",
580+
# "x86_64-pc-windows-msvc": "fc665561556f4dc843cd3eeba4d482f716aec65d5b89a657316829cfbdc9462a",
581+
# "x86_64-unknown-linux-gnu": "f36f79adfcbdbe13261ba364da4f06c6f3a081702fd4f155b63fe924ff1ee9a2",
582+
# },
583+
# }
584+
# }
575585
},
576586
}
577587

@@ -703,20 +713,28 @@ PLATFORMS = {
703713
),
704714
}
705715

706-
def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_URL, tool_versions = TOOL_VERSIONS):
716+
def get_release_info(
717+
platform, python_version, base_url = DEFAULT_RELEASE_BASE_URL, tool_versions = TOOL_VERSIONS, build_option = None
718+
):
707719
"""Resolve the release URL for the requested interpreter version
708720
709721
Args:
710722
platform: The platform string for the interpreter
711723
python_version: The version of the interpreter to get
712724
base_url: The URL to prepend to the 'url' attr in the tool_versions dict
713725
tool_versions: A dict listing the interpreter versions, their SHAs and URL
726+
build_option: Python build option, default: "install_only"
714727
715728
Returns:
716-
A tuple of (filename, url, archive strip prefix, patches, patch_strip)
729+
A tuple of (filename, url, archive strip prefix, patches, patch_strip, free_threading)
717730
"""
718731

719732
url = tool_versions[python_version]["url"]
733+
if not build_option:
734+
build_option = "shared-install_only" if (WINDOWS_NAME in platform) else "install_only"
735+
free_threading = False
736+
else:
737+
free_threading = True if build_option.startswith("freethreaded") else False
720738

721739
if type(url) == type({}):
722740
url = url[platform]
@@ -734,7 +752,7 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
734752
release_filename = u.format(
735753
platform = platform,
736754
python_version = python_version,
737-
build = "shared-install_only" if (WINDOWS_NAME in platform) else "install_only",
755+
build = build_option,
738756
)
739757
if "://" in release_filename: # is absolute url?
740758
rendered_urls.append(release_filename)
@@ -757,7 +775,7 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
757775
else:
758776
patch_strip = None
759777

760-
return (release_filename, rendered_urls, strip_prefix, patches, patch_strip)
778+
return (release_filename, rendered_urls, strip_prefix, patches, patch_strip, free_threading)
761779

762780
def print_toolchains_checksums(name):
763781
native.genrule(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy