diff --git a/.github/workflows/build-wheels-aarch64.yaml b/.github/workflows/build-wheels-aarch64.yaml index f43607ba..16694f15 100644 --- a/.github/workflows/build-wheels-aarch64.yaml +++ b/.github/workflows/build-wheels-aarch64.yaml @@ -26,7 +26,7 @@ jobs: python-version: ["cp37", "cp38", "cp39", "cp310", "cp311", "cp312"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -38,8 +38,15 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 env: + CIBW_BEFORE_ALL: | + git clone --depth 1 https://github.com/alsa-project/alsa-lib + cd alsa-lib + ./gitcompile + cd .. + echo "PWD" + ls -lh /project/alsa-lib/src/.libs + CIBW_ENVIRONMENT: CPLUS_INCLUDE_PATH=/project/alsa-lib/include:$CPLUS_INCLUDE_PATH SHERPA_NCNN_ALSA_LIB_DIR=/project/alsa-lib/src/.libs LD_LIBRARY_PATH=/project/build/bdist.linux-x86_64/wheel/sherpa_ncnn/lib:$SHERPA_NCNN_ALSA_LIB_DIR SHERPA_NCNN_MAKE_ARGS="VERBOSE=1" SHERPA_NCNN_ENABLE_ALSA=1 SHERPA_NCNN_CMAKE_ARGS='-DCMAKE_C_FLAGS="-march=armv8-a" -DCMAKE_CXX_FLAGS="-march=armv8-a"' CIBW_BUILD: "${{ matrix.python-version}}-* " - CIBW_ENVIRONMENT: SHERPA_NCNN_CMAKE_ARGS='-DCMAKE_C_FLAGS="-march=armv8-a" -DCMAKE_CXX_FLAGS="-march=armv8-a"' CIBW_SKIP: "cp27-* cp35-* cp36-* *-win32 pp* *-musllinux* *-manylinux_i686" CIBW_BUILD_VERBOSITY: 3 CIBW_ARCHS_LINUX: aarch64 @@ -49,10 +56,9 @@ jobs: run: | ls -lh ./wheelhouse/ - ls -lh ./wheelhouse/*.whl - - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: + name: ${{ matrix.python-version }} path: ./wheelhouse/*.whl - name: Publish wheels to PyPI diff --git a/.github/workflows/build-wheels-linux.yaml b/.github/workflows/build-wheels-linux.yaml index 82534fd6..7945fb11 100644 --- a/.github/workflows/build-wheels-linux.yaml +++ b/.github/workflows/build-wheels-linux.yaml @@ -26,15 +26,24 @@ jobs: python-version: ["cp37", "cp38", "cp39", "cp310", "cp311", "cp312"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # see https://cibuildwheel.readthedocs.io/en/stable/changelog/ # for a list of versions - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 env: + CIBW_BEFORE_ALL: | + git clone --depth 1 https://github.com/alsa-project/alsa-lib + cd alsa-lib + ./gitcompile + cd .. + echo "PWD" + ls -lh /project/alsa-lib/src/.libs + + CIBW_ENVIRONMENT: CPLUS_INCLUDE_PATH=/project/alsa-lib/include:$CPLUS_INCLUDE_PATH SHERPA_NCNN_ALSA_LIB_DIR=/project/alsa-lib/src/.libs LD_LIBRARY_PATH=/project/build/bdist.linux-x86_64/wheel/sherpa_ncnn/lib:$SHERPA_NCNN_ALSA_LIB_DIR SHERPA_NCNN_MAKE_ARGS="VERBOSE=1" SHERPA_NCNN_ENABLE_ALSA=1 CIBW_BUILD: "${{ matrix.python-version}}-* " - CIBW_SKIP: "cp27-* cp35-* *-win32 pp* *-musllinux*" + CIBW_SKIP: "cp27-* cp35-* cp36-* *-win32 pp* *-musllinux* *-manylinux_i686" CIBW_BUILD_VERBOSITY: 3 - name: Display wheels @@ -42,17 +51,35 @@ 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 + - uses: actions/upload-artifact@v4 with: + name: ${{ matrix.python-version }} path: ./wheelhouse/*.whl - name: Publish to huggingface if: matrix.python-version == 'cp38' env: HF_TOKEN: ${{ secrets.HF_TOKEN }} - uses: nick-fields/retry@v2 + uses: nick-fields/retry@v3 with: max_attempts: 20 timeout_seconds: 200 diff --git a/scripts/wheel/patch_wheel.py b/scripts/wheel/patch_wheel.py new file mode 100755 index 00000000..a72672f6 --- /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_ncnn/lib", + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_ncnn/lib", + # + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_ncnn/lib64", + f"$ORIGIN/../lib/python{py_version}/dist-packages/sherpa_ncnn/lib64", + # + f"$ORIGIN/../lib/python{py_version}/site-packages/sherpa_ncnn.libs", + ] + rpaths = ":".join(rpath_list) + + for filename in glob.glob( + f"{tmp_dir}/sherpa_ncnn-*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() diff --git a/sherpa-ncnn/python/csrc/faked-alsa.cc b/sherpa-ncnn/python/csrc/faked-alsa.cc index 3cd1bbf2..ae295cf1 100644 --- a/sherpa-ncnn/python/csrc/faked-alsa.cc +++ b/sherpa-ncnn/python/csrc/faked-alsa.cc @@ -2,17 +2,17 @@ // // Copyright (c) 2024 Xiaomi Corporation -#include "sherpa-ncnn/csrc/macros.h" +#include + #include "sherpa-ncnn/python/csrc/alsa.h" namespace sherpa_ncnn { - class FakedAlsa { public: explicit FakedAlsa(const char *) { - SHERPA_NCNN_LOGE("This function is for Linux only."); + fprintf(stderr, "This function is for Linux only."); #if (SHERPA_NCNN_ENABLE_ALSA == 0) && (defined(__unix__) || defined(__unix)) - SHERPA_NCNN_LOGE(R"doc( + fprintf(stderr, R"doc( sherpa-ncnn is compiled without alsa support. To enable that, please run (1) sudo apt-get install alsa-utils libasound2-dev (2) rebuild sherpa-ncnn @@ -43,5 +43,3 @@ void PybindAlsa(py::module *m) { } } // namespace sherpa_ncnn - -#endif // SHERPA_NCNN_PYTHON_CSRC_FAKED_ALSA_H_