Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
 
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
 
"""Build a wheel for the onnxruntime-ep-webgpu package.
 
Combines pre-built plugin EP binaries with the Python package source to produce
a platform-specific wheel.
 
Usage:
    python build_wheel.py --binary_dir <path> --version <ver> --output_dir <path>
"""
 
import argparse
import platform
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
 
SCRIPT_DIR = Path(__file__).parent
MIN_ONNXRUNTIME_VERSION_FILE = SCRIPT_DIR.parent / "MIN_ONNXRUNTIME_VERSION"
 
# Import the shared template helper from _packaging_utils.py in the parent directory.
sys.path.insert(0, str(SCRIPT_DIR.parent))
from _packaging_utils import gen_file_from_template  # noqa: E402, I001  (path setup must precede import)
 
 
# Patterns for binaries to include in the package
BINARY_PATTERNS = [
    "onnxruntime_providers_webgpu.dll",
    "libonnxruntime_providers_webgpu.so",
    "libonnxruntime_providers_webgpu.dylib",
    # DXC dependencies (Windows)
    "dxcompiler.dll",
    # Dawn shared library (if built as shared)
    "webgpu_dawn.dll",
    "libwebgpu_dawn.so",
    "libwebgpu_dawn.dylib",
]
 
# Libraries to exclude from auditwheel bundling (user-provided drivers)
AUDITWHEEL_EXCLUDE = [
    "libvulkan.so.1",
]
 
 
def prepare_staging_dir(staging_dir: Path, binary_dir: Path, version: str):
    """Copy the package source tree into staging_dir, copy binaries, and stamp the version."""
    staging_dir.mkdir(parents=True, exist_ok=True)
 
    # Copy only the files needed to build the wheel
    shutil.copy2(SCRIPT_DIR / "setup.py", staging_dir / "setup.py")
    shutil.copytree(SCRIPT_DIR / "onnxruntime_ep_webgpu", staging_dir / "onnxruntime_ep_webgpu")
 
    # Stage the repo-root LICENSE and ThirdPartyNotices.txt next to setup.py so setuptools
    # can bundle them via the `license-files` entry in pyproject.toml (PEP 639).
    repo_root = SCRIPT_DIR.parents[1]
    for license_filename in ("LICENSE", "ThirdPartyNotices.txt"):
        src = repo_root / license_filename
        if not src.is_file():
            raise FileNotFoundError(f"Expected license file not found: {src}")
        shutil.copy2(src, staging_dir / license_filename)
 
    # Copy plugin binaries into the package directory
    # Note: The binaries are assumed to be directly under `binary_dir`.
    package_dir = staging_dir / "onnxruntime_ep_webgpu"
    copied = []
    for pattern in BINARY_PATTERNS:
        for src in binary_dir.glob(pattern):
            dst = package_dir / src.name
            print(f"Copying {src} -> {dst}")
            shutil.copy2(src, dst)
            copied.append(dst)
    if not copied:
        raise FileNotFoundError(f"No plugin binaries found in {binary_dir}. Looked for: {BINARY_PATTERNS}")
 
    # Substitute the minimum ORT version into the staged README in place.
    min_ort_version = MIN_ONNXRUNTIME_VERSION_FILE.read_text(encoding="utf-8").strip()
    if not min_ort_version:
        raise ValueError(f"{MIN_ONNXRUNTIME_VERSION_FILE} is empty")
 
    staged_readme = package_dir / "README.md"
    gen_file_from_template(
        staged_readme,
        staged_readme,
        {"min_onnxruntime_version": min_ort_version},
    )
 
    # Render pyproject.toml from its template
    gen_file_from_template(
        SCRIPT_DIR / "pyproject.toml.in",
        staging_dir / "pyproject.toml",
        {"version": version},
    )
 
 
def build_wheel(source_dir: Path, wheel_dir: Path):
    """Build the wheel using pip."""
    wheel_dir.mkdir(parents=True, exist_ok=True)
    cmd = [
        sys.executable,
        "-m",
        "pip",
        "wheel",
        str(source_dir),
        "--wheel-dir",
        str(wheel_dir),
        "--no-deps",
        "--no-build-isolation",
    ]
    print(f"Running: {' '.join(cmd)}")
    subprocess.check_call(cmd)
 
 
def auditwheel_repair(wheel_dir: Path):
    """Run auditwheel repair on Linux to produce a manylinux-compliant wheel."""
    if platform.system() != "Linux":
        return
 
    original_wheels = list(wheel_dir.glob("onnxruntime_ep_webgpu-*.whl"))
    if not original_wheels:
        raise RuntimeError(f"No wheel found in {wheel_dir} to repair with auditwheel")
 
    with tempfile.TemporaryDirectory() as repaired_dir_name:
        repaired_dir = Path(repaired_dir_name)
 
        for wheel in original_wheels:
            cmd = [sys.executable, "-m", "auditwheel", "repair", str(wheel), "--wheel-dir", str(repaired_dir)]
            for lib in AUDITWHEEL_EXCLUDE:
                cmd.extend(["--exclude", lib])
            print(f"Running: {' '.join(cmd)}")
            subprocess.check_call(cmd)
            # Remove the original wheel so only the repaired one remains
            wheel.unlink()
 
        repaired_wheels = list(repaired_dir.glob("*.whl"))
        if not repaired_wheels:
            raise RuntimeError(f"auditwheel repair produced no wheels in {repaired_dir}")
 
        # Move repaired wheels into wheel_dir
        for repaired_wheel in repaired_wheels:
            repaired_wheel.replace(wheel_dir / repaired_wheel.name)
 
 
def collect_wheels(wheel_dir: Path, output_dir: Path):
    """Copy built wheels to the output directory and verify at least one was produced."""
    wheels = list(wheel_dir.glob("onnxruntime_ep_webgpu-*.whl"))
    if not wheels:
        raise RuntimeError("No wheel was produced")
 
    output_dir.mkdir(parents=True, exist_ok=True)
 
    for wheel in wheels:
        dest = output_dir / wheel.name
        shutil.copy2(wheel, dest)
        print(f"Built wheel: {dest}")
 
 
def main():
    parser = argparse.ArgumentParser(description="Build onnxruntime-ep-webgpu wheel")
    parser.add_argument(
        "--binary_dir", required=True, type=Path, help="Directory containing the built plugin EP binaries"
    )
    parser.add_argument("--version", required=True, help="Package version string (PEP 440 format)")
    parser.add_argument("--output_dir", required=True, type=Path, help="Directory to place the built wheel")
    args = parser.parse_args()
 
    if not args.binary_dir.is_dir():
        raise FileNotFoundError(f"Binary directory does not exist: {args.binary_dir}")
 
    with tempfile.TemporaryDirectory(prefix="ort_webgpu_wheel_") as tmp:
        staging_dir = Path(tmp) / "package"
        wheel_dir = Path(tmp) / "wheels"
 
        prepare_staging_dir(staging_dir, args.binary_dir, args.version)
        build_wheel(staging_dir, wheel_dir)
        auditwheel_repair(wheel_dir)
        collect_wheels(wheel_dir, args.output_dir)
 
 
if __name__ == "__main__":
    main()