From 419aadf10bc54c59d5712e96de0f9d987b410f5b Mon Sep 17 00:00:00 2001 From: usamoi Date: Wed, 5 Jun 2024 20:53:04 +0800 Subject: [PATCH] ci: add rust aarch64 target in release (#11) Signed-off-by: usamoi --- .github/workflows/release.yml | 13 ++++------ scripts/package.sh | 45 +++++++++++++++++++++++++++++++++++ sql/install/.gitkeep | 0 sql/upgrade/.gitkeep | 0 tools/schema.sh | 4 ++-- 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100755 scripts/package.sh create mode 100644 sql/install/.gitkeep create mode 100644 sql/upgrade/.gitkeep diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc8eee9..f4cd9a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,6 +60,7 @@ jobs: sudo apt-get install -y build-essential crossbuild-essential-arm64 sudo apt-get install -y qemu-user-static echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml + rustup target add aarch64-unknown-linux-gnu - name: Set up Sccache uses: mozilla-actions/sccache-action@v0.0.4 - name: Set up Cache @@ -71,12 +72,6 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }} - - name: Set up Clang-16 - run: | - sudo sh -c 'echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-16 main" >> /etc/apt/sources.list' - wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo apt-get update - sudo apt-get install -y clang-16 - name: Set up Pgrx run: | # pg_config @@ -92,8 +87,8 @@ jobs: echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV" - name: Build run: | - cargo build --lib --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu - ./tools/schema.sh --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/pg_bestmatch--$SEMVER.sql + cargo build --lib --features pg$VERSION --release --target $ARCH-unknown-linux-gnu + ./tools/schema.sh --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/pg_bestmatch--$SEMVER.sql - name: Package run: | export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') @@ -105,7 +100,7 @@ jobs: export TAG=${{ github.event.inputs.tag }} export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip - gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${SEMVER}_${PLATFORM}.deb + gh release upload --clobber $TAG ./build/postgresql-${VERSION}-pg-bestmatch_${SEMVER}_${PLATFORM}.deb - name: Post Set up Cache uses: actions/cache/save@v4 if: ${{ !steps.cache.outputs.cache-hit }} diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100755 index 0000000..057f566 --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -e + +printf "SEMVER = ${SEMVER}\n" +printf "VERSION = ${VERSION}\n" +printf "ARCH = ${ARCH}\n" +printf "PLATFORM = ${PLATFORM}\n" + +rm -rf ./build/dir_zip +rm -rf ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip +rm -rf ./build/dir_deb +rm -rf ./build/pg_bestmatch-pg${VERSION}_${SEMVER}_${PLATFORM}.deb + +mkdir -p ./build/dir_zip +cp -a ./sql/upgrade/. ./build/dir_zip/ +cp ./target/pg_bestmatch--$SEMVER.sql ./build/dir_zip/pg_bestmatch--$SEMVER.sql +sed -e "s/@CARGO_VERSION@/$SEMVER/g" < ./pg_bestmatch.control > ./build/dir_zip/pg_bestmatch.control +cp ./target/${ARCH}-unknown-linux-gnu/release/libpg_bestmatch.so ./build/dir_zip/pg_bestmatch.so +zip ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip -j ./build/dir_zip/* + +mkdir -p ./build/dir_deb +mkdir -p ./build/dir_deb/DEBIAN +mkdir -p ./build/dir_deb/usr/share/postgresql/$VERSION/extension/ +mkdir -p ./build/dir_deb/usr/lib/postgresql/$VERSION/lib/ +for file in $(ls ./build/dir_zip/*.sql | xargs -n 1 basename); do + cp ./build/dir_zip/$file ./build/dir_deb/usr/share/postgresql/$VERSION/extension/$file +done +for file in $(ls ./build/dir_zip/*.control | xargs -n 1 basename); do + cp ./build/dir_zip/$file ./build/dir_deb/usr/share/postgresql/$VERSION/extension/$file +done +for file in $(ls ./build/dir_zip/*.so | xargs -n 1 basename); do + cp ./build/dir_zip/$file ./build/dir_deb/usr/lib/postgresql/$VERSION/lib/$file +done +echo "Package: postgresql-${VERSION}-pg-bestmatch +Version: ${SEMVER} +Section: database +Priority: optional +Architecture: ${PLATFORM} +Maintainer: Tensorchord +Description: Generate BM25 sparse vector inside PostgreSQL +Homepage: https://github.com/tensorchord/pg_bestmatch.rs +License: apache2" \ +> ./build/dir_deb/DEBIAN/control +(cd ./build/dir_deb && md5sum usr/share/postgresql/$VERSION/extension/* usr/lib/postgresql/$VERSION/lib/*) > ./build/dir_deb/DEBIAN/md5sums +dpkg --build ./build/dir_deb/ ./build/postgresql-${VERSION}-pg-bestmatch_${SEMVER}_${PLATFORM}.deb diff --git a/sql/install/.gitkeep b/sql/install/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/sql/upgrade/.gitkeep b/sql/upgrade/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tools/schema.sh b/tools/schema.sh index b20acf7..70c3419 100755 --- a/tools/schema.sh +++ b/tools/schema.sh @@ -40,6 +40,6 @@ code=$(mktemp) chmod 700 $code CONTROL_FILEPATH="./pg_bestmatch.control" SO_FILEPATH="$DIR/libpg_bestmatch.so" $(dirname "$0")/schema-codegen.sh >> $code -PGRX_EMBED=$code cargo rustc --bin pgrx_embed_vectors "$@" -- --cfg pgrx_embed +PGRX_EMBED=$code cargo rustc --bin pgrx_embed_pg_bestmatch "$@" -- --cfg pgrx_embed -CARGO_PKG_VERSION="0.0.0" QEMU_LD_PREFIX=$QEMU_LD_PREFIX "${RUNNER[@]}" "$DIR/pgrx_embed_vectors" | expand -t 4 +CARGO_PKG_VERSION="0.0.0" QEMU_LD_PREFIX=$QEMU_LD_PREFIX "${RUNNER[@]}" "$DIR/pgrx_embed_pg_bestmatch" | expand -t 4