-
-
Notifications
You must be signed in to change notification settings - Fork 594
Added windows support to hermetic toolchains #628
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
Changes from all commits
227aa3d
09c57bd
8a53ef4
3ce5c91
e063c20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,89 +27,79 @@ def py_repositories(): | |
######## | ||
# Remaining content of the file is only used to support toolchains. | ||
######## | ||
_DOC = "Fetch external tools needed for python toolchain." | ||
_ATTRS = { | ||
"integrity": attr.string(mandatory = True), | ||
"platform": attr.string(mandatory = True, values = PLATFORMS.keys()), | ||
"python_version": attr.string(mandatory = True, values = TOOL_VERSIONS.keys() + MINOR_MAPPING.keys()), | ||
} | ||
|
||
def _python_repository_impl(rctx): | ||
python_version = rctx.attr.python_version | ||
platform = rctx.attr.platform | ||
release_filename = "cpython-{version}-{platform}-pgo+lto-{release_date}.tar.zst".format( | ||
is_host_windows = "win" in rctx.os.name | ||
is_target_windows = "windows" in rctx.attr.platform | ||
python_version = rctx.attr.python_version | ||
build = "static-install_only" if is_target_windows else "install_only" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a Windows user. Would a static binary for Windows have the same limitation as a fully static binary for Linux that a shared object (i.e. a native Python extension) cannot be loaded at runtime (not able to do dlopen)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure myself, but this was the only artifact that worked. My thought was to hopefully see something merged that works in some cases and fix other issues as they're reported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this could possibly be a blocker for merging my PR into main. I'll take this for now, but will have to investigate before releasing this feature. |
||
release_filename = "cpython-{version}+{release_date}-{platform}-{build}.tar.gz".format( | ||
build = build, | ||
platform = platform, | ||
release_date = RELEASE_DATE, | ||
version = python_version, | ||
platform = platform, | ||
) | ||
url = "{release_url}/{release_filename}".format( | ||
release_url = RELEASE_URL, | ||
release_filename = release_filename, | ||
) | ||
integrity = rctx.attr.integrity | ||
rctx.download( | ||
download_result = rctx.download_and_extract( | ||
url = url, | ||
integrity = integrity, | ||
output = release_filename, | ||
integrity = rctx.attr.integrity, | ||
stripPrefix = "python", | ||
) | ||
unzstd = rctx.which("unzstd") | ||
if not unzstd: | ||
url = rctx.attr._zstd_url.format(version = rctx.attr._zstd_version) | ||
rctx.download_and_extract( | ||
url = url, | ||
sha256 = rctx.attr._zstd_sha256, | ||
) | ||
working_directory = "zstd-{version}".format(version = rctx.attr._zstd_version) | ||
rctx.execute( | ||
["make", "--jobs=4"], | ||
timeout = 600, | ||
quiet = True, | ||
working_directory = working_directory, | ||
) | ||
zstd = "{working_directory}/zstd".format(working_directory = working_directory) | ||
unzstd = "./unzstd" | ||
rctx.symlink(zstd, unzstd) | ||
|
||
exec_result = rctx.execute([ | ||
"tar", | ||
"--extract", | ||
"--strip-components=2", | ||
"--use-compress-program={unzstd}".format(unzstd = unzstd), | ||
"--file={}".format(release_filename), | ||
]) | ||
if exec_result.return_code: | ||
fail(exec_result.stderr) | ||
|
||
# Remove files with spaces. | ||
exec_result = rctx.execute([ | ||
"find", | ||
".", | ||
"-type", | ||
"f", | ||
"-name", | ||
"*[[:space:]]*", | ||
"-delete", | ||
]) | ||
if is_host_windows: | ||
arguments = [ | ||
"powershell.exe", | ||
"-c", | ||
"""Get-ChildItem -File -Path "$(Get-Location)" -Include "* *" -Recurse | Remove-Item -Force -Verbose""", | ||
] | ||
else: | ||
arguments = [ | ||
"find", | ||
".", | ||
"-type", | ||
"f", | ||
"-name", | ||
"*[[:space:]]*", | ||
"-delete", | ||
] | ||
exec_result = rctx.execute(arguments) | ||
if exec_result.return_code: | ||
fail(exec_result.stderr) | ||
|
||
python_bin = "python.exe" if is_target_windows else "bin/python3" | ||
|
||
build_content = """\ | ||
# Generated by python/repositories.bzl | ||
|
||
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "files", | ||
srcs = glob([ | ||
"bin/**", | ||
"include/**", | ||
"lib/**", | ||
"share/**", | ||
]), | ||
visibility = ["//visibility:public"], | ||
srcs = glob( | ||
include = [ | ||
"bin/**", | ||
"DLLs/**", | ||
"extensions/**", | ||
"include/**", | ||
"lib/**", | ||
"libs/**", | ||
"Scripts/**", | ||
"share/**", | ||
], | ||
Comment on lines
+86
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A |
||
exclude = [ | ||
"**/__pycache__/**", | ||
], | ||
), | ||
) | ||
|
||
exports_files(["bin/python3"]) | ||
exports_files(["{python_path}"]) | ||
|
||
py_runtime( | ||
name = "py2_runtime", | ||
|
@@ -120,7 +110,7 @@ py_runtime( | |
py_runtime( | ||
name = "py3_runtime", | ||
files = [":files"], | ||
interpreter = "bin/python3", | ||
interpreter = "{python_path}", | ||
python_version = "PY3", | ||
) | ||
|
||
|
@@ -129,30 +119,37 @@ py_runtime_pair( | |
py2_runtime = ":py2_runtime", | ||
py3_runtime = ":py3_runtime", | ||
) | ||
""" | ||
""".format( | ||
python_path = python_bin, | ||
) | ||
rctx.file("BUILD.bazel", build_content) | ||
|
||
return { | ||
"integrity": integrity, | ||
"integrity": download_result.integrity, | ||
"name": rctx.attr.name, | ||
"platform": platform, | ||
"python_version": python_version, | ||
} | ||
|
||
python_repository = repository_rule( | ||
_python_repository_impl, | ||
doc = _DOC, | ||
attrs = dict({ | ||
"_zstd_sha256": attr.string( | ||
default = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", | ||
doc = "Fetches the external tools needed for the Python toolchain.", | ||
attrs = { | ||
"integrity": attr.string( | ||
doc = "The integrity hash for the Python interpreter tarball.", | ||
mandatory = True, | ||
), | ||
"_zstd_url": attr.string( | ||
default = "https://github.com/facebook/zstd/releases/download/v{version}/zstd-{version}.tar.gz", | ||
"platform": attr.string( | ||
doc = "The platform name for the Python interpreter tarball.", | ||
mandatory = True, | ||
values = PLATFORMS.keys(), | ||
), | ||
"_zstd_version": attr.string( | ||
default = "1.5.2", | ||
"python_version": attr.string( | ||
doc = "The Python version.", | ||
mandatory = True, | ||
values = TOOL_VERSIONS.keys() + MINOR_MAPPING.keys(), | ||
), | ||
}, **_ATTRS), | ||
}, | ||
) | ||
|
||
# Wrapper macro around everything above, this is the primary API. | ||
|
Uh oh!
There was an error while loading. Please reload this page.