Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79bd1f5

Browse filesBrowse files
aignasrickeylev
andauthored
refactor(toolchain): use bazel to extract zstd archives (bazel-contrib#2412)
Here we remove the dependence on the `zstd` archive downloaded from GH for extracting `zstd` toolchains because bazel now supports `zstd` extraction for a long time. This mainly cleans up the code which is again used a lot more due to bazel-contrib#2386. Co-authored-by: Richard Levasseur <rlevasseur@google.com>
1 parent b28db69 commit 79bd1f5
Copy full SHA for 79bd1f5

File tree

Expand file treeCollapse file tree

4 files changed

+36
-56
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-56
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Unreleased changes template.
5252

5353
{#v0-0-0-changed}
5454
### Changed
55-
* Nothing changed.
55+
* (python_repository) Start honoring the `strip_prefix` field for `zstd` archives.
5656

5757
{#v0-0-0-fixed}
5858
### Fixed
@@ -89,6 +89,11 @@ Unreleased changes template.
8989
### Removed
9090
* (publish) Remove deprecated `requirements.txt` for the `twine` dependencies.
9191
Please use `requirements_linux.txt` instead.
92+
* (python_repository) Use bazel's built in `zstd` support and remove attributes
93+
for customizing the `zstd` binary to be used for `zstd` archives in the
94+
{bzl:obj}`python_repository` repository_rule. This affects the
95+
{bzl:obj}`python_register_toolchains` and
96+
{bzl:obj}`python_register_multi_toolchains` callers in the `WORKSPACE`.
9297

9398
{#v0-39-0}
9499
## [0.39.0] - 2024-11-13

‎python/private/python.bzl

Copy file name to clipboardExpand all lines: python/private/python.bzl
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def _get_toolchain_config(*, modules, _fail = fail):
462462
"strip_prefix": {
463463
platform: item["strip_prefix"]
464464
for platform in item["sha256"]
465-
},
465+
} if type(item["strip_prefix"]) == type("") else item["strip_prefix"],
466466
"url": {
467467
platform: [item["url"]]
468468
for platform in item["sha256"]

‎python/private/python_repository.bzl

Copy file name to clipboardExpand all lines: python/private/python_repository.bzl
+10-51Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""This file contains repository rules and macros to support toolchain registration.
1616
"""
1717

18-
load("//python:versions.bzl", "FREETHREADED", "PLATFORMS")
18+
load("//python:versions.bzl", "FREETHREADED", "INSTALL_ONLY", "PLATFORMS")
1919
load(":auth.bzl", "get_auth")
2020
load(":repo_utils.bzl", "REPO_DEBUG_ENV_VAR", "repo_utils")
2121
load(":text_util.bzl", "render")
@@ -72,51 +72,13 @@ def _python_repository_impl(rctx):
7272
urls = rctx.attr.urls or [rctx.attr.url]
7373
auth = get_auth(rctx, urls)
7474

75-
if release_filename.endswith(".zst"):
76-
rctx.download(
75+
if INSTALL_ONLY in release_filename:
76+
rctx.download_and_extract(
7777
url = urls,
7878
sha256 = rctx.attr.sha256,
79-
output = release_filename,
79+
stripPrefix = rctx.attr.strip_prefix,
8080
auth = auth,
8181
)
82-
unzstd = rctx.which("unzstd")
83-
if not unzstd:
84-
url = rctx.attr.zstd_url.format(version = rctx.attr.zstd_version)
85-
rctx.download_and_extract(
86-
url = url,
87-
sha256 = rctx.attr.zstd_sha256,
88-
auth = auth,
89-
)
90-
working_directory = "zstd-{version}".format(version = rctx.attr.zstd_version)
91-
92-
repo_utils.execute_checked(
93-
rctx,
94-
op = "python_repository.MakeZstd",
95-
arguments = [
96-
repo_utils.which_checked(rctx, "make"),
97-
"--jobs=4",
98-
],
99-
timeout = 600,
100-
quiet = True,
101-
working_directory = working_directory,
102-
logger = logger,
103-
)
104-
zstd = "{working_directory}/zstd".format(working_directory = working_directory)
105-
unzstd = "./unzstd"
106-
rctx.symlink(zstd, unzstd)
107-
108-
repo_utils.execute_checked(
109-
rctx,
110-
op = "python_repository.ExtractRuntime",
111-
arguments = [
112-
repo_utils.which_checked(rctx, "tar"),
113-
"--extract",
114-
"--strip-components=2",
115-
"--use-compress-program={unzstd}".format(unzstd = unzstd),
116-
"--file={}".format(release_filename),
117-
],
118-
logger = logger,
119-
)
12082
else:
12183
rctx.download_and_extract(
12284
url = urls,
@@ -125,6 +87,12 @@ def _python_repository_impl(rctx):
12587
auth = auth,
12688
)
12789

90+
# Strip the things that are not present in the INSTALL_ONLY builds
91+
# NOTE: if the dirs are not present, we will not fail here
92+
rctx.delete("python/build")
93+
rctx.delete("python/licenses")
94+
rctx.delete("python/PYTHON.json")
95+
12896
patches = rctx.attr.patches
12997
if patches:
13098
for patch in patches:
@@ -378,15 +346,6 @@ function defaults (e.g. `single_version_override` for `MODULE.bazel` files.
378346
"urls": attr.string_list(
379347
doc = "The URL of the interpreter to download. Exactly one of url and urls must be set.",
380348
),
381-
"zstd_sha256": attr.string(
382-
default = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
383-
),
384-
"zstd_url": attr.string(
385-
default = "https://github.com/facebook/zstd/releases/download/v{version}/zstd-{version}.tar.gz",
386-
),
387-
"zstd_version": attr.string(
388-
default = "1.5.2",
389-
),
390349
"_rule_name": attr.string(default = "python_repository"),
391350
},
392351
environ = [REPO_DEBUG_ENV_VAR],

‎python/versions.bzl

Copy file name to clipboardExpand all lines: python/versions.bzl
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ MACOS_NAME = "mac os"
2020
LINUX_NAME = "linux"
2121
WINDOWS_NAME = "windows"
2222
FREETHREADED = "freethreaded"
23+
INSTALL_ONLY = "install_only"
2324

2425
DEFAULT_RELEASE_BASE_URL = "https://github.com/indygreg/python-build-standalone/releases/download"
2526

@@ -52,7 +53,7 @@ TOOL_VERSIONS = {
5253
"x86_64-apple-darwin": "8d06bec08db8cdd0f64f4f05ee892cf2fcbc58cfb1dd69da2caab78fac420238",
5354
"x86_64-unknown-linux-gnu": "aec8c4c53373b90be7e2131093caa26063be6d9d826f599c935c0e1042af3355",
5455
},
55-
"strip_prefix": "python",
56+
"strip_prefix": "python/install",
5657
},
5758
"3.8.12": {
5859
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
@@ -579,7 +580,22 @@ TOOL_VERSIONS = {
579580
"x86_64-pc-windows-msvc-freethreaded": "bfd89f9acf866463bc4baf01733da5e767d13f5d0112175a4f57ba91f1541310",
580581
"x86_64-unknown-linux-gnu-freethreaded": "a73adeda301ad843cce05f31a2d3e76222b656984535a7b87696a24a098b216c",
581582
},
582-
"strip_prefix": "python",
583+
"strip_prefix": {
584+
"aarch64-apple-darwin": "python",
585+
"aarch64-unknown-linux-gnu": "python",
586+
"ppc64le-unknown-linux-gnu": "python",
587+
"s390x-unknown-linux-gnu": "python",
588+
"x86_64-apple-darwin": "python",
589+
"x86_64-pc-windows-msvc": "python",
590+
"x86_64-unknown-linux-gnu": "python",
591+
"aarch64-apple-darwin-freethreaded": "python/install",
592+
"aarch64-unknown-linux-gnu-freethreaded": "python/install",
593+
"ppc64le-unknown-linux-gnu-freethreaded": "python/install",
594+
"s390x-unknown-linux-gnu-freethreaded": "python/install",
595+
"x86_64-apple-darwin-freethreaded": "python/install",
596+
"x86_64-pc-windows-msvc-freethreaded": "python/install",
597+
"x86_64-unknown-linux-gnu-freethreaded": "python/install",
598+
},
583599
},
584600
}
585601

@@ -777,7 +793,7 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
777793
}[p],
778794
)
779795
else:
780-
build = "install_only"
796+
build = INSTALL_ONLY
781797

782798
if WINDOWS_NAME in platform:
783799
build = "shared-" + build

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.