正在显示
3 个修改的文件
包含
109 行增加
和
2 行删除
| @@ -41,7 +41,24 @@ jobs: | @@ -41,7 +41,24 @@ jobs: | ||
| 41 | run: | | 41 | run: | |
| 42 | ls -lh ./wheelhouse/ | 42 | ls -lh ./wheelhouse/ |
| 43 | 43 | ||
| 44 | - ls -lh ./wheelhouse/*.whl | 44 | + - name: Install patchelf |
| 45 | + if: matrix.os == 'ubuntu-latest' | ||
| 46 | + shell: bash | ||
| 47 | + run: | | ||
| 48 | + sudo apt-get update -q | ||
| 49 | + sudo apt-get install -q -y patchelf | ||
| 50 | + patchelf --help | ||
| 51 | + | ||
| 52 | + - name: Patch wheels | ||
| 53 | + shell: bash | ||
| 54 | + if: matrix.os == 'ubuntu-latest' | ||
| 55 | + run: | | ||
| 56 | + mkdir ./wheels | ||
| 57 | + sudo ./scripts/wheel/patch_wheel.py --in-dir ./wheelhouse --out-dir ./wheels | ||
| 58 | + | ||
| 59 | + ls -lh ./wheels/ | ||
| 60 | + rm -rf ./wheelhouse | ||
| 61 | + mv ./wheels ./wheelhouse | ||
| 45 | 62 | ||
| 46 | - uses: actions/upload-artifact@v2 | 63 | - uses: actions/upload-artifact@v2 |
| 47 | with: | 64 | with: |
scripts/wheel/patch_wheel.py
0 → 100755
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# Copyright 2023 Xiaomi Corp. (authors: Fangjun Kuang) | ||
| 3 | + | ||
| 4 | +import argparse | ||
| 5 | +import glob | ||
| 6 | +import shutil | ||
| 7 | +import subprocess | ||
| 8 | +import sys | ||
| 9 | +from pathlib import Path | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +def get_args(): | ||
| 13 | + parser = argparse.ArgumentParser() | ||
| 14 | + parser.add_argument( | ||
| 15 | + "--in-dir", | ||
| 16 | + type=Path, | ||
| 17 | + required=True, | ||
| 18 | + help="Input directory.", | ||
| 19 | + ) | ||
| 20 | + | ||
| 21 | + parser.add_argument( | ||
| 22 | + "--out-dir", | ||
| 23 | + type=Path, | ||
| 24 | + required=True, | ||
| 25 | + help="Output directory.", | ||
| 26 | + ) | ||
| 27 | + return parser.parse_args() | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +def process(out_dir: Path, whl: Path): | ||
| 31 | + tmp_dir = out_dir / "tmp" | ||
| 32 | + subprocess.check_call(f"unzip {whl} -d {tmp_dir}", shell=True) | ||
| 33 | + if "cp37" in str(whl): | ||
| 34 | + py_version = "3.7" | ||
| 35 | + elif "cp38" in str(whl): | ||
| 36 | + py_version = "3.8" | ||
| 37 | + elif "cp39" in str(whl): | ||
| 38 | + py_version = "3.9" | ||
| 39 | + elif "cp310" in str(whl): | ||
| 40 | + py_version = "3.10" | ||
| 41 | + elif "cp311" in str(whl): | ||
| 42 | + py_version = "3.11" | ||
| 43 | + else: | ||
| 44 | + py_version = "3.12" | ||
| 45 | + | ||
| 46 | + rpath_list = [ | ||
| 47 | + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx/lib", | ||
| 48 | + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_onnx/lib", | ||
| 49 | + # | ||
| 50 | + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx/lib64", | ||
| 51 | + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_onnx/lib64", | ||
| 52 | + # | ||
| 53 | + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx.libs", | ||
| 54 | + ] | ||
| 55 | + rpaths = ":".join(rpath_list) | ||
| 56 | + | ||
| 57 | + for filename in glob.glob( | ||
| 58 | + f"{tmp_dir}/sherpa_onnx-*data/data/bin/*", recursive=True | ||
| 59 | + ): | ||
| 60 | + print(filename) | ||
| 61 | + existing_rpath = ( | ||
| 62 | + subprocess.check_output(["patchelf", "--print-rpath", filename]) | ||
| 63 | + .decode() | ||
| 64 | + .strip() | ||
| 65 | + ) | ||
| 66 | + target_rpaths = rpaths + ":" + existing_rpath | ||
| 67 | + subprocess.check_call( | ||
| 68 | + f"patchelf --force-rpath --set-rpath '{target_rpaths}' {filename}", | ||
| 69 | + shell=True, | ||
| 70 | + ) | ||
| 71 | + | ||
| 72 | + outwheel = Path(shutil.make_archive(whl, "zip", tmp_dir)) | ||
| 73 | + Path(outwheel).rename(out_dir / whl.name) | ||
| 74 | + | ||
| 75 | + shutil.rmtree(tmp_dir) | ||
| 76 | + | ||
| 77 | + | ||
| 78 | +def main(): | ||
| 79 | + args = get_args() | ||
| 80 | + print(args) | ||
| 81 | + in_dir = args.in_dir | ||
| 82 | + out_dir = args.out_dir | ||
| 83 | + out_dir.mkdir(exist_ok=True, parents=True) | ||
| 84 | + | ||
| 85 | + for whl in in_dir.glob("*.whl"): | ||
| 86 | + process(out_dir, whl) | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +if __name__ == "__main__": | ||
| 90 | + main() |
-
请 注册 或 登录 后发表评论