Skip to content

Commit ae9f24f

Browse files
lazcamusf0rmiga
andauthored
linux-arm64 python binary support (#669)
* add aarch64-unknown-linux-gnu python binary release * unittests run & pass on my m1 macbook in OSX and Linux * Note: most //examples/... tests fail when run due to lack of support for non-x86 in https://github.com/bazelbuild/bazel-integration-testing/, but those failing tests pass when run directly in the directory with bazel Co-authored-by: Thulio Ferraz Assis <[email protected]>
1 parent ddd8b74 commit ae9f24f

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

examples/wheel/BUILD

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
load("//python:defs.bzl", "py_library", "py_test")
1616
load("//python:packaging.bzl", "py_package", "py_wheel")
17+
load("//python:versions.bzl", "gen_python_config_settings")
1718

1819
package(default_visibility = ["//visibility:public"])
1920

@@ -196,11 +197,20 @@ py_wheel(
196197
],
197198
)
198199

200+
gen_python_config_settings()
201+
199202
py_wheel(
200203
name = "python_abi3_binary_wheel",
201204
abi = "abi3",
202205
distribution = "example_python_abi3_binary_wheel",
203-
platform = "manylinux2014_x86_64",
206+
# these platform strings must line up with test_python_abi3_binary_wheel() in wheel_test.py
207+
platform = select({
208+
":aarch64-apple-darwin": "macosx_11_0_arm64",
209+
":aarch64-unknown-linux-gnu": "manylinux2014_aarch64",
210+
":x86_64-apple-darwin": "macosx_11_0_x86_64", # this is typically macosx_10_9_x86_64?
211+
":x86_64-pc-windows-msvc": "win_amd64",
212+
":x86_64-unknown-linux-gnu": "manylinux2014_x86_64",
213+
}),
204214
python_requires = ">=3.8",
205215
python_tag = "cp38",
206216
version = "0.0.1",

examples/wheel/wheel_test.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import platform
17+
import subprocess
1718
import unittest
1819
import zipfile
1920

@@ -309,12 +310,22 @@ def test_python_requires_wheel(self):
309310
)
310311

311312
def test_python_abi3_binary_wheel(self):
313+
arch = "amd64"
314+
if platform.system() != "Windows":
315+
arch = subprocess.check_output(["uname", "-m"]).strip().decode()
316+
# These strings match the strings from py_wheel() in BUILD
317+
os_strings = {
318+
"Linux": "manylinux2014",
319+
"Darwin": "macosx_11_0",
320+
"Windows": "win",
321+
}
322+
os_string = os_strings[platform.system()]
312323
filename = os.path.join(
313324
os.environ["TEST_SRCDIR"],
314325
"rules_python",
315326
"examples",
316327
"wheel",
317-
"example_python_abi3_binary_wheel-0.0.1-cp38-abi3-manylinux2014_x86_64.whl",
328+
f"example_python_abi3_binary_wheel-0.0.1-cp38-abi3-{os_string}_{arch}.whl",
318329
)
319330
with zipfile.ZipFile(filename) as zf:
320331
metadata_contents = zf.read(
@@ -336,12 +347,12 @@ def test_python_abi3_binary_wheel(self):
336347
"example_python_abi3_binary_wheel-0.0.1.dist-info/WHEEL"
337348
)
338349
self.assertEqual(
339-
wheel_contents,
340-
b"""\
350+
wheel_contents.decode(),
351+
f"""\
341352
Wheel-Version: 1.0
342353
Generator: bazel-wheelmaker 1.0
343354
Root-Is-Purelib: false
344-
Tag: cp38-abi3-manylinux2014_x86_64
355+
Tag: cp38-abi3-{os_string}_{arch}
345356
""",
346357
)
347358

python/versions.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TOOL_VERSIONS = {
4040
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
4141
"sha256": {
4242
"aarch64-apple-darwin": "f9a3cbb81e0463d6615125964762d133387d561b226a30199f5b039b20f1d944",
43+
# no aarch64-unknown-linux-gnu build available for 3.8.12
4344
"x86_64-apple-darwin": "f323fbc558035c13a85ce2267d0fad9e89282268ecb810e364fff1d0a079d525",
4445
"x86_64-pc-windows-msvc": "924f9fd51ff6ccc533ed8e96c5461768da5781eb3dfc11d846f9e300fab44eda",
4546
"x86_64-unknown-linux-gnu": "5be9c6d61e238b90dfd94755051c0d3a2d8023ebffdb4b0fa4e8fedd09a6cab6",
@@ -50,6 +51,7 @@ TOOL_VERSIONS = {
5051
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
5152
"sha256": {
5253
"aarch64-apple-darwin": "ad66c2a3e7263147e046a32694de7b897a46fb0124409d29d3a93ede631c8aee",
54+
"aarch64-unknown-linux-gnu": "12dd1f125762f47975990ec744532a1cf3db74ad60f4dfb476ca42deb7f78ca4",
5355
"x86_64-apple-darwin": "fdaf594142446029e314a9beb91f1ac75af866320b50b8b968181e592550cd68",
5456
"x86_64-pc-windows-msvc": "5bc65ce023614bf496a6748e41dca934b70fc5fac6dfacc46aa8dbcad772afc2",
5557
"x86_64-unknown-linux-gnu": "455089cc576bd9a58db45e919d1fc867ecdbb0208067dffc845cc9bbf0701b70",
@@ -60,6 +62,7 @@ TOOL_VERSIONS = {
6062
"url": "20220227/cpython-{python_version}+20220227-{platform}-{build}.tar.gz",
6163
"sha256": {
6264
"aarch64-apple-darwin": "1409acd9a506e2d1d3b65c1488db4e40d8f19d09a7df099667c87a506f71c0ef",
65+
"aarch64-unknown-linux-gnu": "8f351a8cc348bb45c0f95b8634c8345ec6e749e483384188ad865b7428342703",
6366
"x86_64-apple-darwin": "8146ad4390710ec69b316a5649912df0247d35f4a42e2aa9615bffd87b3e235a",
6467
"x86_64-pc-windows-msvc": "a293c5838dd9c8438a84372fb95dda9752df63928a8a2ae516438f187f89567d",
6568
"x86_64-unknown-linux-gnu": "9b64eca2a94f7aff9409ad70bdaa7fbbf8148692662e764401883957943620dd",
@@ -86,6 +89,17 @@ PLATFORMS = {
8689
# repository_ctx.execute(["uname", "-m"]).stdout.strip()
8790
arch = "arm64",
8891
),
92+
"aarch64-unknown-linux-gnu": struct(
93+
compatible_with = [
94+
"@platforms//os:linux",
95+
"@platforms//cpu:aarch64",
96+
],
97+
os_name = LINUX_NAME,
98+
# Note: this string differs between OSX and Linux
99+
# Matches the value returned from:
100+
# repository_ctx.execute(["uname", "-m"]).stdout.strip()
101+
arch = "aarch64",
102+
),
89103
"x86_64-apple-darwin": struct(
90104
compatible_with = [
91105
"@platforms//os:macos",
@@ -176,3 +190,10 @@ def _commands_for_version(python_version):
176190
)
177191
for platform in TOOL_VERSIONS[python_version]["sha256"].keys()
178192
])
193+
194+
def gen_python_config_settings(name = ""):
195+
for platform in PLATFORMS.keys():
196+
native.config_setting(
197+
name = "{name}{platform}".format(name = name, platform = platform),
198+
constraint_values = PLATFORMS[platform].compatible_with,
199+
)

0 commit comments

Comments
 (0)