diff --git a/.github/workflows/build-wheels.yaml b/.github/workflows/build-wheels.yaml index 002ae044..462bc611 100644 --- a/.github/workflows/build-wheels.yaml +++ b/.github/workflows/build-wheels.yaml @@ -41,7 +41,24 @@ jobs: run: | ls -lh ./wheelhouse/ - ls -lh ./wheelhouse/*.whl + - name: Install patchelf + if: matrix.os == 'ubuntu-latest' + shell: bash + run: | + sudo apt-get update -q + sudo apt-get install -q -y patchelf + patchelf --help + + - name: Patch wheels + shell: bash + if: matrix.os == 'ubuntu-latest' + run: | + mkdir ./wheels + sudo ./scripts/wheel/patch_wheel.py --in-dir ./wheelhouse --out-dir ./wheels + + ls -lh ./wheels/ + rm -rf ./wheelhouse + mv ./wheels ./wheelhouse - uses: actions/upload-artifact@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index ef9ce213..79d5b4b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR) project(sherpa-onnx) -set(SHERPA_ONNX_VERSION "1.6.0") +set(SHERPA_ONNX_VERSION "1.6.1") # Disable warning about # diff --git a/scripts/wheel/patch_wheel.py b/scripts/wheel/patch_wheel.py new file mode 100755 index 00000000..73be9966 --- /dev/null +++ b/scripts/wheel/patch_wheel.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# Copyright 2023 Xiaomi Corp. (authors: Fangjun Kuang) + +import argparse +import glob +import shutil +import subprocess +import sys +from pathlib import Path + + +def get_args(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--in-dir", + type=Path, + required=True, + help="Input directory.", + ) + + parser.add_argument( + "--out-dir", + type=Path, + required=True, + help="Output directory.", + ) + return parser.parse_args() + + +def process(out_dir: Path, whl: Path): + tmp_dir = out_dir / "tmp" + subprocess.check_call(f"unzip {whl} -d {tmp_dir}", shell=True) + if "cp37" in str(whl): + py_version = "3.7" + elif "cp38" in str(whl): + py_version = "3.8" + elif "cp39" in str(whl): + py_version = "3.9" + elif "cp310" in str(whl): + py_version = "3.10" + elif "cp311" in str(whl): + py_version = "3.11" + else: + py_version = "3.12" + + rpath_list = [ + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx/lib", + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_onnx/lib", + # + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx/lib64", + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_onnx/lib64", + # + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_onnx.libs", + ] + rpaths = ":".join(rpath_list) + + for filename in glob.glob( + f"{tmp_dir}/sherpa_onnx-*data/data/bin/*", recursive=True + ): + print(filename) + existing_rpath = ( + subprocess.check_output(["patchelf", "--print-rpath", filename]) + .decode() + .strip() + ) + target_rpaths = rpaths + ":" + existing_rpath + subprocess.check_call( + f"patchelf --force-rpath --set-rpath '{target_rpaths}' {filename}", + shell=True, + ) + + outwheel = Path(shutil.make_archive(whl, "zip", tmp_dir)) + Path(outwheel).rename(out_dir / whl.name) + + shutil.rmtree(tmp_dir) + + +def main(): + args = get_args() + print(args) + in_dir = args.in_dir + out_dir = args.out_dir + out_dir.mkdir(exist_ok=True, parents=True) + + for whl in in_dir.glob("*.whl"): + process(out_dir, whl) + + +if __name__ == "__main__": + main()