Skip to content

Commit 5a6eedf

Browse files
committed
Add patch for onnxruntime 1.22.1
1 parent b578c0d commit 5a6eedf

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

graalpython/lib-graalpython/patches/metadata.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ dist-type = 'sdist'
388388
version = '1.17.1'
389389
url = 'https://github.com/microsoft/onnxruntime/archive/refs/tags/v1.17.1.tar.gz'
390390

391+
[[onnxruntime.rules]]
392+
version = '== 1.22.1'
393+
patch = 'onnxruntime-1.22.1.patch'
394+
license = 'MIT'
395+
dist-type = 'sdist'
396+
397+
[[onnxruntime.add-sources]]
398+
version = '1.22.1'
399+
url = 'https://github.com/microsoft/onnxruntime/archive/refs/tags/v1.22.1.tar.gz'
400+
391401
[[orjson.rules]]
392402
version = '== 3.9.7'
393403
patch = 'orjson-3.9.7.patch'
@@ -538,6 +548,7 @@ patch = 'pyarrow-20.0.0.patch'
538548
license = 'Apache-2.0'
539549

540550
[[pybind11.rules]]
551+
# Note: This patch file is also used directly outside of pip during onnxruntime build
541552
note = "This patch was accepted upstream."
542553
install-priority = 0
543554
# Note: This patch is also inlined in torch
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
diff --git a/onnxruntime_build_backend.py b/onnxruntime_build_backend.py
2+
new file mode 100644
3+
index 0000000..4b365db
4+
--- /dev/null
5+
+++ b/onnxruntime_build_backend.py
6+
@@ -0,0 +1,59 @@
7+
+import os
8+
+import re
9+
+import sys
10+
+import tarfile
11+
+import subprocess
12+
+import tempfile
13+
+import shutil
14+
+from pathlib import Path
15+
+
16+
+
17+
+def build_sdist(sdist_directory, config_settings=None):
18+
+ nv = 'onnxruntime-1.22.1'
19+
+ srcdir = Path(__file__).parent
20+
+ archive_path = Path(sdist_directory) / f'{nv}.tar.gz'
21+
+
22+
+ def tarfilter(info):
23+
+ if re.match(r'\./(?:.git|venv|[^-/]+-venv|dist)', info.name):
24+
+ return None
25+
+ info.name = f'./{nv}/{info.name}'
26+
+ return info
27+
+
28+
+ with tarfile.open(archive_path, 'w:gz') as tar:
29+
+ tar.add('.', filter=tarfilter)
30+
+ return archive_path.name
31+
+
32+
+
33+
+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
34+
+ wheel_directory = Path(wheel_directory).absolute()
35+
+ build_type = 'Release'
36+
+ build_dir = Path(f'build/{build_type}')
37+
+ parallel = os.environ.get('CMAKE_BUILD_PARALLEL_LEVEL', os.cpu_count())
38+
+ build_cmd = [
39+
+ sys.executable,
40+
+ 'tools/ci_build/build.py',
41+
+ '--build_dir', 'build',
42+
+ '--skip_submodule_sync',
43+
+ '--skip_tests',
44+
+ '--config', build_type,
45+
+ '--enable_pybind',
46+
+ '--parallel', str(parallel),
47+
+ ]
48+
+ if sys.implementation.name == 'graalpy':
49+
+ # The cmake build downloads a bunch of sources that need to be patched
50+
+ subprocess.check_call(build_cmd)
51+
+ marker = build_dir / 'graalpy-patched-marker'
52+
+ if not marker.exists():
53+
+ subprocess.check_call([sys.executable, '-m', 'autopatch_capi', '.'])
54+
+ pybind11_dir = build_dir / '_deps/pybind11_project-src'
55+
+ patches_dir = Path(__graalpython__.core_home) / 'patches'
56+
+ with open(patches_dir / 'pybind11-2.11.patch') as f:
57+
+ subprocess.check_call(['patch', '-p2', '-f'], stdin=f, cwd=pybind11_dir)
58+
+ with open(marker, 'w') as f:
59+
+ pass
60+
+ subprocess.check_call([*build_cmd, '--build_wheel'])
61+
+ wheels = list((build_dir / 'dist').glob('*.whl'))
62+
+ assert len(wheels) == 1, f"Expected 1 wheel, found {len(wheels)}"
63+
+ wheel = wheels[0]
64+
+ shutil.copyfile(wheel, wheel_directory / wheel.name)
65+
+ return str(wheel.name)
66+
diff --git a/pyproject.toml b/pyproject.toml
67+
index eed772f..1da5261 100644
68+
--- a/pyproject.toml
69+
+++ b/pyproject.toml
70+
@@ -1,3 +1,8 @@
71+
+[build-system]
72+
+requires = ["setuptools >= 40.6.0", "wheel", "packaging", "numpy>=1.24.2"]
73+
+build-backend = "onnxruntime_build_backend"
74+
+backend-path = ["."]
75+
+
76+
[tool.pydocstyle]
77+
convention = "google"
78+
79+
diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py
80+
index 2a06916..c790a21 100644
81+
--- a/tools/ci_build/build.py
82+
+++ b/tools/ci_build/build.py
83+
@@ -399,6 +399,12 @@ def generate_build_tree(
84+
"-Ddml_EXTERNAL_PROJECT=ON",
85+
]
86+
87+
+ if not args.test:
88+
+ cmake_args += [
89+
+ "-Donnxruntime_BUILD_UNIT_TESTS=OFF",
90+
+ ]
91+
+
92+
+
93+
if args.use_gdk:
94+
cmake_args += [
95+
"-DCMAKE_TOOLCHAIN_FILE=" + os.path.join(source_dir, "cmake", "gdk_toolchain.cmake"),

0 commit comments

Comments
 (0)