Skip to content

Commit 49706aa

Browse files
gnsinfiWang
authored andcommitted
Add riscv64 support patch for rules_python
bazel-contrib/rules_python#3350
1 parent 030955c commit 49706aa

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

third_party/py/python_init_rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ def python_init_rules(extra_patches = []):
4444
Label("//third_party/py:rules_python_pip_version.patch"),
4545
Label("//third_party/py:rules_python_freethreaded.patch"),
4646
Label("//third_party/py:rules_python_versions.patch"),
47+
Label("//third_party/py:rules_python_riscv64_pypi.patch"),
4748
] + extra_patches,
4849
)
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
From 96deeabe2cd454edcaafea289934eada14784521 Mon Sep 17 00:00:00 2001
2+
From: Levi Zim <[email protected]>
3+
Date: Tue, 14 Oct 2025 19:45:36 +0800
4+
Subject: [PATCH 1/2] fix: Add linux_riscv64 to _pip_repository_impl
5+
6+
Fix https://github.com/bazel-contrib/rules_python/discussions/2729
7+
---
8+
CHANGELOG.md | 4 +++-
9+
python/private/pypi/pip_repository.bzl | 1 +
10+
python/private/pypi/whl_installer/platform.py | 3 +++
11+
python/private/pypi/whl_target_platforms.bzl | 1 +
12+
tests/pypi/whl_installer/platform_test.py | 6 +++---
13+
.../whl_target_platforms/whl_target_platforms_tests.bzl | 9 +++++++++
14+
6 files changed, 20 insertions(+), 4 deletions(-)
15+
16+
diff --git a/CHANGELOG.md b/CHANGELOG.md
17+
index d7c480582a..77e8ed3c61 100644
18+
--- a/CHANGELOG.md
19+
+++ b/CHANGELOG.md
20+
@@ -110,6 +110,8 @@ END_UNRELEASED_TEMPLATE
21+
([#3339](https://github.com/bazel-contrib/rules_python/issues/3339)).
22+
* (uv) {obj}`//python/uv:lock.bzl%lock` now works with a local platform
23+
runtime.
24+
+* (pypi) `linux_riscv64` is added to the platforms list in `_pip_repository_impl`,
25+
+ which fixes [a build issue for tensorflow on riscv64](https://github.com/bazel-contrib/rules_python/discussions/2729).
26+
* (toolchains) WORKSPACE builds now correctly register musl and freethreaded
27+
variants. Setting {obj}`--py_linux_libc=musl` and `--py_freethreaded=yes` now
28+
activate them, respectively.
29+
@@ -1980,4 +1982,4 @@ Breaking changes:
30+
* (pip) Create all_data_requirements alias
31+
* Expose Python C headers through the toolchain.
32+
33+
-[0.24.0]: https://github.com/bazel-contrib/rules_python/releases/tag/0.24.0
34+
\ No newline at end of file
35+
+[0.24.0]: https://github.com/bazel-contrib/rules_python/releases/tag/0.24.0
36+
diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl
37+
index e9a4c44da3..d635651039 100644
38+
--- a/python/private/pypi/pip_repository.bzl
39+
+++ b/python/private/pypi/pip_repository.bzl
40+
@@ -96,6 +96,7 @@ def _pip_repository_impl(rctx):
41+
"linux_aarch64",
42+
"linux_arm",
43+
"linux_ppc",
44+
+ "linux_riscv64",
45+
"linux_s390x",
46+
"linux_x86_64",
47+
"osx_aarch64",
48+
diff --git a/python/private/pypi/whl_installer/platform.py b/python/private/pypi/whl_installer/platform.py
49+
index ff267fe4aa..0757d86990 100644
50+
--- a/python/private/pypi/whl_installer/platform.py
51+
+++ b/python/private/pypi/whl_installer/platform.py
52+
@@ -45,6 +45,7 @@ class Arch(Enum):
53+
ppc64le = 5
54+
s390x = 6
55+
arm = 7
56+
+ riscv64 = 8
57+
amd64 = x86_64
58+
arm64 = aarch64
59+
i386 = x86_32
60+
@@ -269,6 +270,8 @@ def platform_machine(self) -> str:
61+
return "ppc"
62+
elif self.arch == Arch.ppc64le:
63+
return "ppc64le"
64+
+ elif self.arch == Arch.riscv64:
65+
+ return "riscv64"
66+
elif self.arch == Arch.s390x:
67+
return "s390x"
68+
else:
69+
diff --git a/python/private/pypi/whl_target_platforms.bzl b/python/private/pypi/whl_target_platforms.bzl
70+
index 6c3dd5da83..28547c679c 100644
71+
--- a/python/private/pypi/whl_target_platforms.bzl
72+
+++ b/python/private/pypi/whl_target_platforms.bzl
73+
@@ -30,6 +30,7 @@ _CPU_ALIASES = {
74+
"ppc": "ppc",
75+
"ppc64": "ppc",
76+
"ppc64le": "ppc64le",
77+
+ "riscv64": "riscv64",
78+
"s390x": "s390x",
79+
"arm": "arm",
80+
"armv6l": "arm",
81+
diff --git a/tests/pypi/whl_installer/platform_test.py b/tests/pypi/whl_installer/platform_test.py
82+
index ad65650779..0d944bb196 100644
83+
--- a/tests/pypi/whl_installer/platform_test.py
84+
+++ b/tests/pypi/whl_installer/platform_test.py
85+
@@ -38,17 +38,17 @@ def test_can_get_specific_from_string(self):
86+
87+
def test_can_get_all_for_py_version(self):
88+
cp39 = Platform.all(minor_version=9, micro_version=0)
89+
- self.assertEqual(21, len(cp39), f"Got {cp39}")
90+
+ self.assertEqual(24, len(cp39), f"Got {cp39}")
91+
self.assertEqual(cp39, Platform.from_string("cp39.0_*"))
92+
93+
def test_can_get_all_for_os(self):
94+
linuxes = Platform.all(OS.linux, minor_version=9)
95+
- self.assertEqual(7, len(linuxes))
96+
+ self.assertEqual(8, len(linuxes))
97+
self.assertEqual(linuxes, Platform.from_string("cp39_linux_*"))
98+
99+
def test_can_get_all_for_os_for_host_python(self):
100+
linuxes = Platform.all(OS.linux)
101+
- self.assertEqual(7, len(linuxes))
102+
+ self.assertEqual(8, len(linuxes))
103+
self.assertEqual(linuxes, Platform.from_string("linux_*"))
104+
105+
def test_platform_sort(self):
106+
diff --git a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
107+
index a976a0cf95..8b7f0ad02b 100644
108+
--- a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
109+
+++ b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
110+
@@ -34,6 +34,9 @@ def _test_simple(env):
111+
"musllinux_1_1_ppc64le": [
112+
struct(os = "linux", cpu = "ppc64le", abi = None, target_platform = "linux_ppc64le", version = (1, 1)),
113+
],
114+
+ "musllinux_1_2_riscv64": [
115+
+ struct(os = "linux", cpu = "riscv64", abi = None, target_platform = "linux_riscv64", version = (1, 2)),
116+
+ ],
117+
"win_amd64": [
118+
struct(os = "windows", cpu = "x86_64", abi = None, target_platform = "windows_x86_64", version = (0, 0)),
119+
],
120+
@@ -66,6 +69,9 @@ def _test_with_abi(env):
121+
"musllinux_1_1_ppc64le": [
122+
struct(os = "linux", cpu = "ppc64le", abi = "cp311", target_platform = "cp311_linux_ppc64le", version = (1, 1)),
123+
],
124+
+ "musllinux_1_2_riscv64": [
125+
+ struct(os = "linux", cpu = "riscv64", abi = "cp311", target_platform = "cp311_linux_riscv64", version = (1, 2)),
126+
+ ],
127+
"win_amd64": [
128+
struct(os = "windows", cpu = "x86_64", abi = "cp311", target_platform = "cp311_windows_x86_64", version = (0, 0)),
129+
],
130+
@@ -96,6 +102,7 @@ def _can_parse_existing_tags(env):
131+
"manylinux2014_i686": 1,
132+
"manylinux2014_ppc64": 1,
133+
"manylinux2014_ppc64le": 1,
134+
+ "manylinux2014_riscv64": 1,
135+
"manylinux2014_s390x": 1,
136+
"manylinux2014_x86_64": 1,
137+
"manylinux_11_12_aarch64": 1,
138+
@@ -103,6 +110,7 @@ def _can_parse_existing_tags(env):
139+
"manylinux_11_12_i686": 1,
140+
"manylinux_11_12_ppc64": 1,
141+
"manylinux_11_12_ppc64le": 1,
142+
+ "manylinux_11_12_riscv64": 1,
143+
"manylinux_11_12_s390x": 1,
144+
"manylinux_11_12_x86_64": 1,
145+
"manylinux_1_2_aarch64": 1,
146+
@@ -111,6 +119,7 @@ def _can_parse_existing_tags(env):
147+
"musllinux_11_12_armv7l": 1,
148+
"musllinux_11_12_i686": 1,
149+
"musllinux_11_12_ppc64le": 1,
150+
+ "musllinux_11_12_riscv64": 1,
151+
"musllinux_11_12_s390x": 1,
152+
"musllinux_11_12_x86_64": 1,
153+
"win32": 1,
154+
155+
From f03ff72726015e64aa3e9af6adf34cb651a92c88 Mon Sep 17 00:00:00 2001
156+
From: Levi Zim <[email protected]>
157+
Date: Tue, 14 Oct 2025 20:26:34 +0800
158+
Subject: [PATCH 2/2] Empty commit to retry CI
159+
160+
CI fails with connection timed out

0 commit comments

Comments
 (0)