Skip to content

Commit c1bf8d0

Browse files
committed
Add riscv64 support patch for rules_python
bazel-contrib/rules_python#1907 bazel-contrib/rules_python#3350
1 parent d5fa396 commit c1bf8d0

File tree

6 files changed

+572
-0
lines changed

6 files changed

+572
-0
lines changed

third_party/py/python_init_rules.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ def python_init_rules():
1313
Label("//third_party/py:rules_python1.patch"),
1414
Label("//third_party/py:rules_python2.patch"),
1515
Label("//third_party/py:rules_python3.patch"),
16+
Label("//third_party/py:rules_python_riscv64_toolchain.patch"),
17+
Label("//third_party/py:rules_python_riscv64_pypi.patch"),
1618
],
1719
)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
diff --git a/python/private/pypi/requirements_files_by_platform.bzl b/python/private/pypi/requirements_files_by_platform.bzl
2+
index e3aafc08..0abbe546 100644
3+
--- a/python/private/pypi/requirements_files_by_platform.bzl
4+
+++ b/python/private/pypi/requirements_files_by_platform.bzl
5+
@@ -22,6 +22,7 @@ DEFAULT_PLATFORMS = [
6+
"linux_aarch64",
7+
"linux_arm",
8+
"linux_ppc",
9+
+ "linux_riscv64",
10+
"linux_s390x",
11+
"linux_x86_64",
12+
"osx_aarch64",
13+
diff --git a/python/private/pypi/whl_installer/platform.py b/python/private/pypi/whl_installer/platform.py
14+
index 83e42b0e..bb95b3be 100644
15+
--- a/python/private/pypi/whl_installer/platform.py
16+
+++ b/python/private/pypi/whl_installer/platform.py
17+
@@ -44,6 +44,7 @@ class Arch(Enum):
18+
ppc = 4
19+
s390x = 5
20+
arm = 6
21+
+ riscv64 = 7
22+
amd64 = x86_64
23+
arm64 = aarch64
24+
i386 = x86_32
25+
@@ -273,6 +274,8 @@ class Platform:
26+
return ""
27+
elif self.arch == Arch.ppc64le:
28+
return "ppc64le"
29+
+ elif self.arch == Arch.riscv64:
30+
+ return "riscv64"
31+
elif self.arch == Arch.s390x:
32+
return "s390x"
33+
else:
34+
diff --git a/python/private/pypi/whl_target_platforms.bzl b/python/private/pypi/whl_target_platforms.bzl
35+
index bdc44c69..8f2a1a82 100644
36+
--- a/python/private/pypi/whl_target_platforms.bzl
37+
+++ b/python/private/pypi/whl_target_platforms.bzl
38+
@@ -32,6 +32,7 @@ _CPU_ALIASES = {
39+
"ppc": "ppc",
40+
"ppc64": "ppc",
41+
"ppc64le": "ppc",
42+
+ "riscv64": "riscv64",
43+
"s390x": "s390x",
44+
"arm": "arm",
45+
"armv6l": "arm",
46+
diff --git a/tests/pypi/whl_installer/platform_test.py b/tests/pypi/whl_installer/platform_test.py
47+
index 7ced1e98..0182cca4 100644
48+
--- a/tests/pypi/whl_installer/platform_test.py
49+
+++ b/tests/pypi/whl_installer/platform_test.py
50+
@@ -34,17 +34,17 @@ class PlatformTest(unittest.TestCase):
51+
52+
def test_can_get_all_for_py_version(self):
53+
cp39 = Platform.all(minor_version=9)
54+
- self.assertEqual(18, len(cp39), f"Got {cp39}")
55+
+ self.assertEqual(21, len(cp39), f"Got {cp39}")
56+
self.assertEqual(cp39, Platform.from_string("cp39_*"))
57+
58+
def test_can_get_all_for_os(self):
59+
linuxes = Platform.all(OS.linux, minor_version=9)
60+
- self.assertEqual(6, len(linuxes))
61+
+ self.assertEqual(7, len(linuxes))
62+
self.assertEqual(linuxes, Platform.from_string("cp39_linux_*"))
63+
64+
def test_can_get_all_for_os_for_host_python(self):
65+
linuxes = Platform.all(OS.linux)
66+
- self.assertEqual(6, len(linuxes))
67+
+ self.assertEqual(7, len(linuxes))
68+
self.assertEqual(linuxes, Platform.from_string("linux_*"))
69+
70+
def test_specific_version_specializations(self):
71+
diff --git a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
72+
index a72bdc27..c3250387 100644
73+
--- a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
74+
+++ b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
75+
@@ -34,6 +34,9 @@ def _test_simple(env):
76+
"musllinux_1_1_ppc64le": [
77+
struct(os = "linux", cpu = "ppc", abi = None, target_platform = "linux_ppc", version = (1, 1)),
78+
],
79+
+ "musllinux_1_2_riscv64": [
80+
+ struct(os = "linux", cpu = "riscv64", abi = None, target_platform = "linux_riscv64", version = (1, 2)),
81+
+ ],
82+
"win_amd64": [
83+
struct(os = "windows", cpu = "x86_64", abi = None, target_platform = "windows_x86_64", version = (0, 0)),
84+
],
85+
@@ -63,6 +66,9 @@ def _test_with_abi(env):
86+
"musllinux_1_1_ppc64le": [
87+
struct(os = "linux", cpu = "ppc", abi = "cp311", target_platform = "cp311_linux_ppc", version = (1, 1)),
88+
],
89+
+ "musllinux_1_2_riscv64": [
90+
+ struct(os = "linux", cpu = "riscv64", abi = "cp311", target_platform = "cp311_linux_riscv64", version = (1, 2)),
91+
+ ],
92+
"win_amd64": [
93+
struct(os = "windows", cpu = "x86_64", abi = "cp311", target_platform = "cp311_windows_x86_64", version = (0, 0)),
94+
],
95+
@@ -93,6 +99,7 @@ def _can_parse_existing_tags(env):
96+
"manylinux2014_i686": 1,
97+
"manylinux2014_ppc64": 1,
98+
"manylinux2014_ppc64le": 1,
99+
+ "manylinux2014_riscv64": 1,
100+
"manylinux2014_s390x": 1,
101+
"manylinux2014_x86_64": 1,
102+
"manylinux_11_12_aarch64": 1,
103+
@@ -100,6 +107,7 @@ def _can_parse_existing_tags(env):
104+
"manylinux_11_12_i686": 1,
105+
"manylinux_11_12_ppc64": 1,
106+
"manylinux_11_12_ppc64le": 1,
107+
+ "manylinux_11_12_riscv64": 1,
108+
"manylinux_11_12_s390x": 1,
109+
"manylinux_11_12_x86_64": 1,
110+
"manylinux_1_2_aarch64": 1,
111+
@@ -108,6 +116,7 @@ def _can_parse_existing_tags(env):
112+
"musllinux_11_12_armv7l": 1,
113+
"musllinux_11_12_i686": 1,
114+
"musllinux_11_12_ppc64le": 1,
115+
+ "musllinux_11_12_riscv64": 1,
116+
"musllinux_11_12_s390x": 1,
117+
"musllinux_11_12_x86_64": 1,
118+
"win32": 1,
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
diff --git a/gazelle/deps.bzl b/gazelle/deps.bzl
2+
index 948d61e5..47b83f24 100644
3+
--- a/gazelle/deps.bzl
4+
+++ b/gazelle/deps.bzl
5+
@@ -29,9 +29,9 @@ def python_stdlib_list_deps():
6+
http_archive(
7+
name = "python_stdlib_list",
8+
build_file_content = """exports_files(glob(["stdlib_list/lists/*.txt"]))""",
9+
- sha256 = "3f6fc8fba0a99ce8fa76c1b794a24f38962f6275ea9d5cfb43a874abe472571e",
10+
- strip_prefix = "stdlib-list-0.10.0",
11+
- url = "https://github.com/pypi/stdlib-list/releases/download/v0.10.0/v0.10.0.tar.gz",
12+
+ sha256 = "aa21a4f219530e85ecc364f0bbff2df4e6097a8954c63652af060f4e64afa65d",
13+
+ strip_prefix = "stdlib-list-0.11.0",
14+
+ url = "https://github.com/pypi/stdlib-list/releases/download/v0.11.0/v0.11.0.tar.gz",
15+
)
16+
17+
def gazelle_deps():
18+
diff --git a/python/versions.bzl b/python/versions.bzl
19+
index ca19044a..facf63fd 100644
20+
--- a/python/versions.bzl
21+
+++ b/python/versions.bzl
22+
@@ -247,6 +247,22 @@ TOOL_VERSIONS = {
23+
"x86_64-apple-darwin": "193dc7f0284e4917d52b17a077924474882ee172872f2257cfe3375d6d468ed9",
24+
"x86_64-pc-windows-msvc": "5069008a237b90f6f7a86956903f2a0221b90d471daa6e4a94831eaa399e3993",
25+
"x86_64-unknown-linux-gnu": "c20ee831f7f46c58fa57919b75a40eb2b6a31e03fd29aaa4e8dab4b9c4b60d5d",
26+
+ "x86_64-unknown-linux-musl": "5c1cc348e317fe7af1acd6a7f665b46eccb554b20d6533f0e76c53f44d4556cc",
27+
+ },
28+
+ "strip_prefix": "python",
29+
+ },
30+
+ "3.9.21": {
31+
+ "url": "20250317/cpython-{python_version}+20250317-{platform}-{build}.tar.gz",
32+
+ "sha256": {
33+
+ "aarch64-apple-darwin": "2a7d83db10c082ce59e9c4b8bd6c5790310198fb759a7c94aceebac1d93676d3",
34+
+ "aarch64-unknown-linux-gnu": "758ebbc4d60b3ca26cf21720232043ad626373fbeb6632122e5db622a1f55465",
35+
+ "ppc64le-unknown-linux-gnu": "3c7c0cc16468659049ac2f843ffba29144dd987869c943b83c2730569b7f57bd",
36+
+ "riscv64-unknown-linux-gnu": "ef1463ad5349419309060854a5f942b0bd7bd0b9245b53980129836187e68ad9",
37+
+ "s390x-unknown-linux-gnu": "e66e52dcbe3e20153e7d5844451bf58a69f41b858348e0f59c547444bfe191ee",
38+
+ "x86_64-apple-darwin": "786ebd91e4dd0920acf60aa3428a627a937342d2455f7eb5e9a491517c32db3d",
39+
+ "x86_64-pc-windows-msvc": "5392cee2ef7cd20b34128384d0b31864fb3c02bdb7a8ae6995cfec621bb657bc",
40+
+ "x86_64-unknown-linux-gnu": "6f426b5494e90701ffa2753e229252e8b3ac61151a09c8cd6c0a649512df8ab2",
41+
+ "x86_64-unknown-linux-musl": "6113c6c5f88d295bb26279b8a49d74126ee12db137854e0d8c3077051a4eddc4",
42+
},
43+
"strip_prefix": "python",
44+
},
45+
@@ -366,6 +382,22 @@ TOOL_VERSIONS = {
46+
"x86_64-apple-darwin": "90b46dfb1abd98d45663c7a2a8c45d3047a59391d8586d71b459cec7b75f662b",
47+
"x86_64-pc-windows-msvc": "e48952619796c66ec9719867b87be97edca791c2ef7fbf87d42c417c3331609e",
48+
"x86_64-unknown-linux-gnu": "3db2171e03c1a7acdc599fba583c1b92306d3788b375c9323077367af1e9d9de",
49+
+ "x86_64-unknown-linux-musl": "ed519c47d9620eb916a6f95ec2875396e7b1a9ab993ee40b2f31b837733f318c",
50+
+ },
51+
+ "strip_prefix": "python",
52+
+ },
53+
+ "3.10.16": {
54+
+ "url": "20250317/cpython-{python_version}+20250317-{platform}-{build}.tar.gz",
55+
+ "sha256": {
56+
+ "aarch64-apple-darwin": "e99f8457d9c79592c036489c5cfa78df76e4762d170665e499833e045d82608f",
57+
+ "aarch64-unknown-linux-gnu": "76d0f04d2444e77200fdc70d1c57480e29cca78cb7420d713bc1c523709c198d",
58+
+ "ppc64le-unknown-linux-gnu": "39c9b3486de984fe1d72d90278229c70d6b08bcf69cd55796881b2d75077b603",
59+
+ "riscv64-unknown-linux-gnu": "ebe949ada9293581c17d9bcdaa8f645f67d95f73eac65def760a71ef9dd6600d",
60+
+ "s390x-unknown-linux-gnu": "9b2fc0b7f1c75b48e799b6fa14f7e24f5c61f2db82e3c65d13ed25e08f7f0857",
61+
+ "x86_64-apple-darwin": "e03e62dbe95afa2f56b7344ff3bd061b180a0b690ff77f9a1d7e6601935e05ca",
62+
+ "x86_64-pc-windows-msvc": "c7e0eb0ff5b36758b7a8cacd42eb223c056b9c4d36eded9bf5b9fe0c0b9aeb08",
63+
+ "x86_64-unknown-linux-gnu": "b350c7e63956ca8edb856b91316328e0fd003a840cbd63d08253af43b2c63643",
64+
+ "x86_64-unknown-linux-musl": "6ed64923ee4fbea4c5780f1a5a66651d239191ac10bd23420db4f5e4e0bf79c4",
65+
},
66+
"strip_prefix": "python",
67+
},
68+
@@ -480,6 +512,22 @@ TOOL_VERSIONS = {
69+
"x86_64-apple-darwin": "1e23ffe5bc473e1323ab8f51464da62d77399afb423babf67f8e13c82b69c674",
70+
"x86_64-pc-windows-msvc": "647b66ff4552e70aec3bf634dd470891b4a2b291e8e8715b3bdb162f577d4c55",
71+
"x86_64-unknown-linux-gnu": "8b50a442b04724a24c1eebb65a36a0c0e833d35374dbdf9c9470d8a97b164cd9",
72+
+ "x86_64-unknown-linux-musl": "d36fc77a8dd76155a7530f6235999a693b9e7c48aa11afeb5610a091cae5aa6f",
73+
+ },
74+
+ "strip_prefix": "python",
75+
+ },
76+
+ "3.11.11": {
77+
+ "url": "20250317/cpython-{python_version}+20250317-{platform}-{build}.tar.gz",
78+
+ "sha256": {
79+
+ "aarch64-apple-darwin": "19b147c7e4b742656da4cb6ba35bc3ea2f15aa5f4d1bbbc38d09e2e85551e927",
80+
+ "aarch64-unknown-linux-gnu": "7d52b5206afe617de2899af477f5a1d275ecbce80fb8300301b254ebf1da5a90",
81+
+ "ppc64le-unknown-linux-gnu": "17c049f70ce719adc89dd0ae26f4e6a28f6aaedc63c2efef6bbb9c112ea4d692",
82+
+ "riscv64-unknown-linux-gnu": "83ed50713409576756f5708e8f0549a15c17071bea22b71f15e11a7084f09481",
83+
+ "s390x-unknown-linux-gnu": "298507f1f8d962b1bb98cb506c99e7e0d291a63eb9117e1521141e6b3825fd56",
84+
+ "x86_64-apple-darwin": "a870cd965e7dded5100d13b1d34cab1c32a92811e000d10fbfe9bbdb36cdaa0e",
85+
+ "x86_64-pc-windows-msvc": "1cf5760eea0a9df3308ca2c4111b5cc18fd638b2a912dbe07606193e3f9aa123",
86+
+ "x86_64-unknown-linux-gnu": "51e47bc0d1b9f4bf68dd395f7a39f60c58a87cde854cab47264a859eb666bb69",
87+
+ "x86_64-unknown-linux-musl": "ee4d84f992c6a1df42096e26b970fe5938fd6c1eadd245894bc94c5737ff9977",
88+
},
89+
"strip_prefix": "python",
90+
},
91+
@@ -575,12 +623,28 @@ TOOL_VERSIONS = {
92+
},
93+
"strip_prefix": "python",
94+
},
95+
+ "3.12.9": {
96+
+ "url": "20250317/cpython-{python_version}+20250317-{platform}-{build}.tar.gz",
97+
+ "sha256": {
98+
+ "aarch64-apple-darwin": "7c7fd9809da0382a601a79287b5d62d61ce0b15f5a5ee836233727a516e85381",
99+
+ "aarch64-unknown-linux-gnu": "00c6bf9acef21ac741fea24dc449d0149834d30e9113429e50a95cce4b00bb80",
100+
+ "ppc64le-unknown-linux-gnu": "25d77599dfd5849f17391d92da0da99079e4e94f19a881f763f5cc62530ef7e1",
101+
+ "riscv64-unknown-linux-gnu": "e97ab0fdf443b302c56a52b4fd08f513bf3be66aa47263f0f9df3c6e60e05f2e",
102+
+ "s390x-unknown-linux-gnu": "7492d079ffa8425c8f6c58e43b237c37e3fb7b31e2e14635927bb4d3397ba21e",
103+
+ "x86_64-apple-darwin": "1ee1b1bb9fbce5c145c4bec9a3c98d7a4fa22543e09a7c1d932bc8599283c2dc",
104+
+ "x86_64-pc-windows-msvc": "d15361fd202dd74ae9c3eece1abdab7655f1eba90bf6255cad1d7c53d463ed4d",
105+
+ "x86_64-unknown-linux-gnu": "ef382fb88cbb41a3b0801690bd716b8a1aec07a6c6471010bcc6bd14cd575226",
106+
+ "x86_64-unknown-linux-musl": "94e3837da1adf9964aab2d6047b33f70167de3096d1f9a2d1fa9340b1bbf537d",
107+
+ },
108+
+ "strip_prefix": "python",
109+
+ },
110+
"3.13.2": {
111+
"url": "20250317/cpython-{python_version}+20250317-{platform}-{build}.{ext}",
112+
"sha256": {
113+
"aarch64-apple-darwin": "faa44274a331eb39786362818b21b3a4e74514e8805000b20b0e55c590cecb94",
114+
"aarch64-unknown-linux-gnu": "9c67260446fee6ea706dad577a0b32936c63f449c25d66e4383d5846b2ab2e36",
115+
"ppc64le-unknown-linux-gnu": "345b53d2f86c9dbd7f1320657cb227ff9a42ef63ff21f129abbbc8c82a375147",
116+
+ "riscv64-unknown-linux-gnu": "172d22b2330737f3a028ea538ffe497c39a066a8d3200b22dd4d177a3332ad85",
117+
"s390x-unknown-linux-gnu": "ec3b16ea8a97e3138acec72bc5ff35949950c62c8994a8ec8e213fd93f0e806b",
118+
"x86_64-apple-darwin": "ee4526e84b5ce5b11141c50060b385320f2773616249a741f90c96d460ce8e8f",
119+
"x86_64-pc-windows-msvc": "84d7b52f3558c8e35c670a4fa14080c75e3ec584adfae49fec8b51008b75b21e",
120+
@@ -589,6 +653,7 @@ TOOL_VERSIONS = {
121+
"aarch64-apple-darwin-freethreaded": "c98c9c977e6fa05c3813bd49f3553904d89d60fed27e2e36468da7afa1d6d5e2",
122+
"aarch64-unknown-linux-gnu-freethreaded": "b8635e59e3143fd17f19a3dfe8ccc246ee6587c87da359bd1bcab35eefbb5f19",
123+
"ppc64le-unknown-linux-gnu-freethreaded": "6ae8fa44cb2edf4ab49cff1820b53c40c10349c0f39e11b8cd76ce7f3e7e1def",
124+
+ "riscv64-unknown-linux-gnu-freethreaded": "2af1b8850c52801fb6189e7a17a51e0c93d9e46ddefcca72247b76329c97d02a",
125+
"s390x-unknown-linux-gnu-freethreaded": "c074144cc80c2af32c420b79a9df26e8db405212619990c1fbdd308bd75afe3f",
126+
"x86_64-apple-darwin-freethreaded": "0d73e4348d8d4b5159058609d2303705190405b485dd09ad05d870d7e0f36e0f",
127+
"x86_64-pc-windows-msvc-freethreaded": "c51b4845fda5421e044067c111192f645234081d704313f74ee77fa013a186ea",
128+
@@ -599,6 +664,7 @@ TOOL_VERSIONS = {
129+
"aarch64-unknown-linux-gnu": "python",
130+
"ppc64le-unknown-linux-gnu": "python",
131+
"s390x-unknown-linux-gnu": "python",
132+
+ "riscv64-unknown-linux-gnu": "python",
133+
"x86_64-apple-darwin": "python",
134+
"x86_64-pc-windows-msvc": "python",
135+
"x86_64-unknown-linux-gnu": "python",
136+
@@ -606,6 +672,7 @@ TOOL_VERSIONS = {
137+
"aarch64-apple-darwin-freethreaded": "python/install",
138+
"aarch64-unknown-linux-gnu-freethreaded": "python/install",
139+
"ppc64le-unknown-linux-gnu-freethreaded": "python/install",
140+
+ "riscv64-unknown-linux-gnu-freethreaded": "python/install",
141+
"s390x-unknown-linux-gnu-freethreaded": "python/install",
142+
"x86_64-apple-darwin-freethreaded": "python/install",
143+
"x86_64-pc-windows-msvc-freethreaded": "python/install",
144+
@@ -633,10 +700,10 @@ TOOL_VERSIONS = {
145+
# buildifier: disable=unsorted-dict-items
146+
MINOR_MAPPING = {
147+
"3.8": "3.8.20",
148+
- "3.9": "3.9.20",
149+
- "3.10": "3.10.15",
150+
- "3.11": "3.11.10",
151+
- "3.12": "3.12.8",
152+
+ "3.9": "3.9.21",
153+
+ "3.10": "3.10.16",
154+
+ "3.11": "3.11.11",
155+
+ "3.12": "3.12.9",
156+
"3.13": "3.13.2",
157+
"3.14": "3.14.0",
158+
}
159+
@@ -818,6 +885,7 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
160+
"aarch64-apple-darwin": "pgo+lto",
161+
"aarch64-unknown-linux-gnu": "lto",
162+
"ppc64le-unknown-linux-gnu": "lto",
163+
+ "riscv64-unknown-linux-gnu": "lto",
164+
"s390x-unknown-linux-gnu": "lto",
165+
"x86_64-apple-darwin": "pgo+lto",
166+
"x86_64-pc-windows-msvc": "pgo",

third_party/xla/third_party/py/python_init_rules.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ def python_init_rules():
1313
Label("//third_party/py:rules_python1.patch"),
1414
Label("//third_party/py:rules_python2.patch"),
1515
Label("//third_party/py:rules_python3.patch"),
16+
Label("//third_party/py:rules_python_riscv64_toolchain.patch"),
17+
Label("//third_party/py:rules_python_riscv64_pypi.patch"),
1618
],
1719
)

0 commit comments

Comments
 (0)