|
| 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