From e24c3650eaf1a8ea9e97621847719ecc04536bc0 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sun, 26 Nov 2023 16:37:12 +0800 Subject: [PATCH] feat(ci): support manylinux build for cpu / cuda (#899) --- .github/workflows/ci.yml | 19 ++++++++++++++----- ci/prepare_build_environment.sh | 19 ++++++++++++++++++- crates/llama-cpp-bindings/build.rs | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5229eb11a92..45ebb92994b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,14 +63,23 @@ jobs: if: github.event_name != 'pull_request' needs: tests runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} strategy: matrix: - os: [macos-latest, ubuntu-latest] + binary: [aarch64-apple-darwin, x86_64-manylinux2014, x86_64-manylinux2014-cuda117] include: - os: macos-latest target: aarch64-apple-darwin + binary: aarch64-apple-darwin - os: ubuntu-latest target: x86_64-unknown-linux-gnu + binary: x86_64-manylinux2014 + container: quay.io/pypa/manylinux2014_x86_64 + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + binary: x86_64-manylinux2014-cuda117 + container: sameli/manylinux2014_x86_64_cuda_11.7 + build_args: --features cuda env: SCCACHE_GHA_ENABLED: true @@ -111,17 +120,17 @@ jobs: - run: bash ./ci/prepare_build_environment.sh - name: Bulid release binary - run: cargo build --release --target ${{ matrix.target }} --package tabby + run: cargo build ${{ matrix.build_args }} --release --target ${{ matrix.target }} --package tabby - name: Rename release binary - run: mv target/${{ matrix.target }}/release/tabby tabby_${{ matrix.target }} + run: mv target/${{ matrix.target }}/release/tabby tabby_${{ matrix.binary }} - name: Upload artifacts uses: actions/upload-artifact@v3 with: retention-days: 3 - name: tabby_${{ matrix.target }} - path: tabby_${{ matrix.target }} + name: tabby_${{ matrix.binary }} + path: tabby_${{ matrix.binary }} pre-release: if: github.event_name != 'pull_request' diff --git a/ci/prepare_build_environment.sh b/ci/prepare_build_environment.sh index cc67c5739d1..8fffabf73b7 100755 --- a/ci/prepare_build_environment.sh +++ b/ci/prepare_build_environment.sh @@ -4,6 +4,23 @@ if [[ "$OSTYPE" == "darwin"* ]]; then brew install protobuf fi +install_protobuf_centos() { + PB_REL="https://github.com/protocolbuffers/protobuf/releases" + curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip + unzip protoc-3.15.8-linux-x86_64.zip -d /usr + rm protoc-3.15.8-linux-x86_64.zip +} + if [[ "$OSTYPE" == "linux"* ]]; then - sudo apt-get -y install protobuf-compiler libopenblas-dev + if command -v apt-get ; then + sudo apt-get -y install protobuf-compiler libopenblas-dev + else + # Build from manylinux2014 container + yum -y install openblas-devel perl-IPC-Cmd unzip curl + + # Disable safe directory in docker + git config --system --add safe.directory "*" + + install_protobuf_centos + fi fi diff --git a/crates/llama-cpp-bindings/build.rs b/crates/llama-cpp-bindings/build.rs index 488df009664..c6219478071 100644 --- a/crates/llama-cpp-bindings/build.rs +++ b/crates/llama-cpp-bindings/build.rs @@ -25,6 +25,7 @@ fn main() { } if cfg!(feature = "cuda") { config.define("LLAMA_CUBLAS", "ON"); + config.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON"); println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64"); println!("cargo:rustc-link-lib=cudart"); println!("cargo:rustc-link-lib=culibos");