Skip to content

Commit 0c408b1

Browse files
infiWangGoogle-ML-Automation
authored andcommitted
PR #102607: Add support for Linux RISC-V 64
Imported from GitHub PR tensorflow/tensorflow#102607 This commit fixes #102159 which prevented TensorFlow from compiling on RISC-V 64 due to missing codepath in the build system. RFC: Currently this patch overrides timeout of rules_python for all platforms which is obviously not ideal. How do we set pip package timeout here in Tensorflow? See also: - bazelbuild/bazel#25236 - bazelbuild/bazel#25699 - bazel-contrib/rules_python#3350 - #32812 - tensorflow/runtime#135 Copybara import of the project: -- 13b7db883e6ea0aa631490fb5f806c55ceea7cb5 by gns <[email protected]>: [XLA:CPU] Add support for riscv64 Co-authored-by: Levi Zim <[email protected]> -- a00c3a3ba94664798960cbc2fb0a6746fe0c3ac1 by gns <[email protected]>: Add missing llvm:: namespace qualifiers for DTensor Add the `llvm::` namespace prefix to `cast` and `isa` where it was missing in the DTensor MLIR code. -- febc5abc56ab302f5f39fe20176ed00c0c95cb7e by gns <[email protected]>: runtime: add missing stdint header Co-authored-by: Levi Zim <[email protected]> -- 6bf63fec56a6d961b06d932fe69b76eae89d8cb7 by gns <[email protected]>: Add riscv64 support patch for rules_python bazel-contrib/rules_python#3350 -- 68c44fa9613d5577f36c51a192c932795e13ed83 by gns <[email protected]>: tools: py: add riscv64 to pip and manylinux compilance test -- 3f2fe1e0256476449f64658219d997727c9cc534 by gns <[email protected]>: Lift timeout of rules_python for BFS wheels -- 252a9b7ad2336b7abbb94e269b4a976b45d5d6e7 by gns <[email protected]>: Revert llvm toolchain patch for riscv64 As already upstreamed. Co-authored-by: Levi Zim <[email protected]> -- 51047a86131e991ffea74fccb8f55e3521237a64 by gns <[email protected]>: Lift timeout for BFS wheels during pip init -- 3b8276420031969423c9a1f150341a0e41fa372e by gns <[email protected]>: Refresh `rules_python` riscv64 patch Co-authored-by: Levi Zim <[email protected]> Merging this change closes #102607 FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#102607 from infiWang:riscv64 3b8276420031969423c9a1f150341a0e41fa372e PiperOrigin-RevId: 825073762
1 parent dcbfe13 commit 0c408b1

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

third_party/py/python_init_pip.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ cc_library(
3939
"numpy": ["numpy_headers"],
4040
},
4141
requirements_lock = REQUIREMENTS_WITH_LOCAL_WHEELS,
42+
timeout = 3600,
4243
)

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: Sun, 26 Oct 2025 12:35:53 +0800
3+
Subject: [PATCH] fix: Add linux_riscv64 to _pip_repository_impl (#3350)
4+
5+
Add `linux_riscv64` support for pulling pip dependencies. This is not
6+
adding any hermetic toolchain support - user has to provide a working
7+
toolchain.
8+
9+
Fix #2729
10+
11+
---------
12+
13+
Co-authored-by: Ignas Anikevicius <[email protected]>
14+
---
15+
python/private/pypi/pip_repository.bzl | 1 +
16+
python/private/pypi/whl_installer/platform.py | 3 +++
17+
python/private/pypi/whl_target_platforms.bzl | 1 +
18+
tests/pypi/whl_installer/platform_test.py | 6 +++---
19+
.../whl_target_platforms/whl_target_platforms_tests.bzl | 8 ++++++++
20+
5 files changed, 16 insertions(+), 3 deletions(-)
21+
22+
diff --git a/python/private/pypi/pip_repository.bzl b/python/private/pypi/pip_repository.bzl
23+
index e9a4c44da3..d635651039 100644
24+
--- a/python/private/pypi/pip_repository.bzl
25+
+++ b/python/private/pypi/pip_repository.bzl
26+
@@ -96,6 +96,7 @@ def _pip_repository_impl(rctx):
27+
"linux_aarch64",
28+
"linux_arm",
29+
"linux_ppc",
30+
+ "linux_riscv64",
31+
"linux_s390x",
32+
"linux_x86_64",
33+
"osx_aarch64",
34+
diff --git a/python/private/pypi/whl_installer/platform.py b/python/private/pypi/whl_installer/platform.py
35+
index ff267fe4aa..0757d86990 100644
36+
--- a/python/private/pypi/whl_installer/platform.py
37+
+++ b/python/private/pypi/whl_installer/platform.py
38+
@@ -45,6 +45,7 @@ class Arch(Enum):
39+
ppc64le = 5
40+
s390x = 6
41+
arm = 7
42+
+ riscv64 = 8
43+
amd64 = x86_64
44+
arm64 = aarch64
45+
i386 = x86_32
46+
@@ -269,6 +270,8 @@ def platform_machine(self) -> str:
47+
return "ppc"
48+
elif self.arch == Arch.ppc64le:
49+
return "ppc64le"
50+
+ elif self.arch == Arch.riscv64:
51+
+ return "riscv64"
52+
elif self.arch == Arch.s390x:
53+
return "s390x"
54+
else:
55+
diff --git a/python/private/pypi/whl_target_platforms.bzl b/python/private/pypi/whl_target_platforms.bzl
56+
index 6c3dd5da83..28547c679c 100644
57+
--- a/python/private/pypi/whl_target_platforms.bzl
58+
+++ b/python/private/pypi/whl_target_platforms.bzl
59+
@@ -30,6 +30,7 @@ _CPU_ALIASES = {
60+
"ppc": "ppc",
61+
"ppc64": "ppc",
62+
"ppc64le": "ppc64le",
63+
+ "riscv64": "riscv64",
64+
"s390x": "s390x",
65+
"arm": "arm",
66+
"armv6l": "arm",
67+
diff --git a/tests/pypi/whl_installer/platform_test.py b/tests/pypi/whl_installer/platform_test.py
68+
index ad65650779..0d944bb196 100644
69+
--- a/tests/pypi/whl_installer/platform_test.py
70+
+++ b/tests/pypi/whl_installer/platform_test.py
71+
@@ -38,17 +38,17 @@ def test_can_get_specific_from_string(self):
72+
73+
def test_can_get_all_for_py_version(self):
74+
cp39 = Platform.all(minor_version=9, micro_version=0)
75+
- self.assertEqual(21, len(cp39), f"Got {cp39}")
76+
+ self.assertEqual(24, len(cp39), f"Got {cp39}")
77+
self.assertEqual(cp39, Platform.from_string("cp39.0_*"))
78+
79+
def test_can_get_all_for_os(self):
80+
linuxes = Platform.all(OS.linux, minor_version=9)
81+
- self.assertEqual(7, len(linuxes))
82+
+ self.assertEqual(8, len(linuxes))
83+
self.assertEqual(linuxes, Platform.from_string("cp39_linux_*"))
84+
85+
def test_can_get_all_for_os_for_host_python(self):
86+
linuxes = Platform.all(OS.linux)
87+
- self.assertEqual(7, len(linuxes))
88+
+ self.assertEqual(8, len(linuxes))
89+
self.assertEqual(linuxes, Platform.from_string("linux_*"))
90+
91+
def test_platform_sort(self):
92+
diff --git a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
93+
index a976a0cf95..6bec26c10c 100644
94+
--- a/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
95+
+++ b/tests/pypi/whl_target_platforms/whl_target_platforms_tests.bzl
96+
@@ -34,6 +34,9 @@ def _test_simple(env):
97+
"musllinux_1_1_ppc64le": [
98+
struct(os = "linux", cpu = "ppc64le", abi = None, target_platform = "linux_ppc64le", version = (1, 1)),
99+
],
100+
+ "musllinux_1_2_riscv64": [
101+
+ struct(os = "linux", cpu = "riscv64", abi = None, target_platform = "linux_riscv64", version = (1, 2)),
102+
+ ],
103+
"win_amd64": [
104+
struct(os = "windows", cpu = "x86_64", abi = None, target_platform = "windows_x86_64", version = (0, 0)),
105+
],
106+
@@ -66,6 +69,9 @@ def _test_with_abi(env):
107+
"musllinux_1_1_ppc64le": [
108+
struct(os = "linux", cpu = "ppc64le", abi = "cp311", target_platform = "cp311_linux_ppc64le", version = (1, 1)),
109+
],
110+
+ "musllinux_1_2_riscv64": [
111+
+ struct(os = "linux", cpu = "riscv64", abi = "cp311", target_platform = "cp311_linux_riscv64", version = (1, 2)),
112+
+ ],
113+
"win_amd64": [
114+
struct(os = "windows", cpu = "x86_64", abi = "cp311", target_platform = "cp311_windows_x86_64", version = (0, 0)),
115+
],
116+
@@ -103,6 +109,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 +118,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)