Skip to content

Commit eff9e17

Browse files
committed
Add riscv64 support patch for rules_python
bazel-contrib/rules_python#3350
1 parent de616bd commit eff9e17

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-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: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
From: Levi Zim <[email protected]>
2+
Date: Tue, 14 Oct 2025 19:45:36 +0800
3+
Subject: [PATCH] fix: Add linux_riscv64 to _pip_repository_impl
4+
5+
Fix https://github.com/bazel-contrib/rules_python/discussions/2729
6+
---
7+
python/private/pypi/pip_repository.bzl | 1 +
8+
python/private/pypi/whl_installer/platform.py | 3 +++
9+
python/private/pypi/whl_target_platforms.bzl | 1 +
10+
tests/pypi/whl_installer/platform_test.py | 6 +++---
11+
.../whl_target_platforms/whl_target_platforms_tests.bzl | 9 +++++++++
12+
5 files changed, 17 insertions(+), 3 deletions(-)
13+
14+
diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl
15+
index e9a4c44da3..d635651039 100644
16+
--- a/python/private/pypi/pip_repository.bzl
17+
+++ b/python/private/pypi/pip_repository.bzl
18+
@@ -96,6 +96,7 @@ def _pip_repository_impl(rctx):
19+
"linux_aarch64",
20+
"linux_arm",
21+
"linux_ppc",
22+
+ "linux_riscv64",
23+
"linux_s390x",
24+
"linux_x86_64",
25+
"osx_aarch64",
26+
diff --git a/python/private/pypi/whl_installer/platform.py b/python/private/pypi/whl_installer/platform.py
27+
index ff267fe4aa..0757d86990 100644
28+
--- a/python/private/pypi/whl_installer/platform.py
29+
+++ b/python/private/pypi/whl_installer/platform.py
30+
@@ -45,6 +45,7 @@ class Arch(Enum):
31+
ppc64le = 5
32+
s390x = 6
33+
arm = 7
34+
+ riscv64 = 8
35+
amd64 = x86_64
36+
arm64 = aarch64
37+
i386 = x86_32
38+
@@ -269,6 +270,8 @@ def platform_machine(self) -> str:
39+
return "ppc"
40+
elif self.arch == Arch.ppc64le:
41+
return "ppc64le"
42+
+ elif self.arch == Arch.riscv64:
43+
+ return "riscv64"
44+
elif self.arch == Arch.s390x:
45+
return "s390x"
46+
else:
47+
diff --git a/python/private/pypi/whl_target_platforms.bzl b/python/private/pypi/whl_target_platforms.bzl
48+
index 6c3dd5da83..28547c679c 100644
49+
--- a/python/private/pypi/whl_target_platforms.bzl
50+
+++ b/python/private/pypi/whl_target_platforms.bzl
51+
@@ -30,6 +30,7 @@ _CPU_ALIASES = {
52+
"ppc": "ppc",
53+
"ppc64": "ppc",
54+
"ppc64le": "ppc64le",
55+
+ "riscv64": "riscv64",
56+
"s390x": "s390x",
57+
"arm": "arm",
58+
"armv6l": "arm",
59+
diff --git a/tests/pypi/whl_installer/platform_test.py b/tests/pypi/whl_installer/platform_test.py
60+
index ad65650779..0d944bb196 100644
61+
--- a/tests/pypi/whl_installer/platform_test.py
62+
+++ b/tests/pypi/whl_installer/platform_test.py
63+
@@ -38,17 +38,17 @@ def test_can_get_specific_from_string(self):
64+
65+
def test_can_get_all_for_py_version(self):
66+
cp39 = Platform.all(minor_version=9, micro_version=0)
67+
- self.assertEqual(21, len(cp39), f"Got {cp39}")
68+
+ self.assertEqual(24, len(cp39), f"Got {cp39}")
69+
self.assertEqual(cp39, Platform.from_string("cp39.0_*"))
70+
71+
def test_can_get_all_for_os(self):
72+
linuxes = Platform.all(OS.linux, minor_version=9)
73+
- self.assertEqual(7, len(linuxes))
74+
+ self.assertEqual(8, len(linuxes))
75+
self.assertEqual(linuxes, Platform.from_string("cp39_linux_*"))
76+
77+
def test_can_get_all_for_os_for_host_python(self):
78+
linuxes = Platform.all(OS.linux)
79+
- self.assertEqual(7, len(linuxes))
80+
+ self.assertEqual(8, len(linuxes))
81+
self.assertEqual(linuxes, Platform.from_string("linux_*"))
82+
83+
def test_platform_sort(self):
84+
diff --git a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
85+
index a976a0cf95..8b7f0ad02b 100644
86+
--- a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
87+
+++ b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
88+
@@ -34,6 +34,9 @@ def _test_simple(env):
89+
"musllinux_1_1_ppc64le": [
90+
struct(os = "linux", cpu = "ppc64le", abi = None, target_platform = "linux_ppc64le", version = (1, 1)),
91+
],
92+
+ "musllinux_1_2_riscv64": [
93+
+ struct(os = "linux", cpu = "riscv64", abi = None, target_platform = "linux_riscv64", version = (1, 2)),
94+
+ ],
95+
"win_amd64": [
96+
struct(os = "windows", cpu = "x86_64", abi = None, target_platform = "windows_x86_64", version = (0, 0)),
97+
],
98+
@@ -66,6 +69,9 @@ def _test_with_abi(env):
99+
"musllinux_1_1_ppc64le": [
100+
struct(os = "linux", cpu = "ppc64le", abi = "cp311", target_platform = "cp311_linux_ppc64le", version = (1, 1)),
101+
],
102+
+ "musllinux_1_2_riscv64": [
103+
+ struct(os = "linux", cpu = "riscv64", abi = "cp311", target_platform = "cp311_linux_riscv64", version = (1, 2)),
104+
+ ],
105+
"win_amd64": [
106+
struct(os = "windows", cpu = "x86_64", abi = "cp311", target_platform = "cp311_windows_x86_64", version = (0, 0)),
107+
],
108+
@@ -96,6 +102,7 @@ def _can_parse_existing_tags(env):
109+
"manylinux2014_i686": 1,
110+
"manylinux2014_ppc64": 1,
111+
"manylinux2014_ppc64le": 1,
112+
+ "manylinux2014_riscv64": 1,
113+
"manylinux2014_s390x": 1,
114+
"manylinux2014_x86_64": 1,
115+
"manylinux_11_12_aarch64": 1,
116+
@@ -103,6 +110,7 @@ def _can_parse_existing_tags(env):
117+
"manylinux_11_12_i686": 1,
118+
"manylinux_11_12_ppc64": 1,
119+
"manylinux_11_12_ppc64le": 1,
120+
+ "manylinux_11_12_riscv64": 1,
121+
"manylinux_11_12_s390x": 1,
122+
"manylinux_11_12_x86_64": 1,
123+
"manylinux_1_2_aarch64": 1,
124+
@@ -111,6 +119,7 @@ def _can_parse_existing_tags(env):
125+
"musllinux_11_12_armv7l": 1,
126+
"musllinux_11_12_i686": 1,
127+
"musllinux_11_12_ppc64le": 1,
128+
+ "musllinux_11_12_riscv64": 1,
129+
"musllinux_11_12_s390x": 1,
130+
"musllinux_11_12_x86_64": 1,
131+
"win32": 1,

0 commit comments

Comments
 (0)