diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index aaccca3a..7b77164b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -52,7 +52,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubicloud-standard-4-arm] + os: [ubuntu-22.04, ubicloud-standard-4-arm, macos-13] postgres: [11, 12, 13, 14, 15, 16] steps: - uses: actions/checkout@v4 @@ -60,12 +60,12 @@ jobs: submodules: "recursive" - name: Build id: build - run: sudo su -c "PG_VERSION=$PG_VERSION SETUP_ENV=1 USE_SOURCE=1 SETUP_POSTGRES=1 PACKAGE_EXTENSION=1 GITHUB_OUTPUT=$GITHUB_OUTPUT ./ci/scripts/build-extras.sh" + run: sudo sh -c "PG_VERSION=$PG_VERSION SETUP_ENV=1 USE_SOURCE=1 SETUP_POSTGRES=1 PACKAGE_EXTENSION=1 GITHUB_OUTPUT=$GITHUB_OUTPUT ./ci/scripts/build-extras.sh" env: PG_VERSION: ${{ matrix.postgres }} - name: Build Lantern CLI id: build_cli - run: sudo su -c "PACKAGE_CLI=1 GITHUB_OUTPUT=$GITHUB_OUTPUT ./ci/scripts/build-extras.sh" + run: sudo sh -c "PACKAGE_CLI=1 GITHUB_OUTPUT=$GITHUB_OUTPUT ./ci/scripts/build-extras.sh" if: ${{ matrix.postgres == 15 }} # run only once - name: Upload archive package artifacts if: ${{ github.event_name == 'workflow_dispatch' && inputs.create_release }} diff --git a/ci/scripts/build-extras.sh b/ci/scripts/build-extras.sh index 67470b53..34bc2e30 100755 --- a/ci/scripts/build-extras.sh +++ b/ci/scripts/build-extras.sh @@ -33,7 +33,7 @@ function package_cli() { OUT_DIR=/tmp/${BINARY_NAME} BUILD_DIR=${SOURCE_DIR}/target/release/ - CC=$(which clang) cargo build --package lantern_cli --release + CC=$(which clang) ORT_STRATEGY=system cargo build --package lantern_cli --release mkdir -p ${OUT_DIR} @@ -48,19 +48,19 @@ function package_cli() { } function install_extension() { - cargo pgrx install --pg-config /usr/bin/pg_config --package lantern_extras + ORT_STRATEGY=system cargo pgrx install --pg-config $(which pg_config) --package lantern_extras } function package_extension() { - cargo pgrx package --pg-config /usr/bin/pg_config --package lantern_extras + ORT_STRATEGY=system cargo pgrx package --pg-config $(which pg_config) --package lantern_extras source "$(dirname "$0")/../../lantern_hnsw/scripts/get_arch_and_platform.sh" EXT_VERSION=$(cargo metadata --format-version 1 | jq '.packages[] | select( .name == "lantern_extras") | .version' | tr -d '"') PACKAGE_NAME=lantern-extras-${EXT_VERSION}-postgres-${PG_VERSION}-${PLATFORM}-${ARCH} SOURCE_DIR=$(pwd) - LIB_BUILD_DIR="$(pwd)/target/release/lantern_extras-pg${PG_VERSION}/usr/lib/postgresql/${PG_VERSION}/lib" - SHARE_BUILD_DIR="$(pwd)/target/release/lantern_extras-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension" + LIB_BUILD_DIR="$(pwd)/$(dirname $(find target/release/lantern_extras-pg${PG_VERSION} -type f -name "*.so" -o -name "*.dylib"))" + SHARE_BUILD_DIR="$(pwd)/$(dirname $(find target/release/lantern_extras-pg${PG_VERSION} -type f -name "*.sql"))" OUT_DIR=/tmp/lantern-extras mkdir -p ${OUT_DIR}/${PACKAGE_NAME}/src @@ -97,7 +97,20 @@ function configure_and_start_postgres() { # Source unified utility functions source "$(dirname "$0")/utils.sh" -source "$(dirname "$0")/build-linux.sh" +# This sets $ARCH and $PLATFORM env variables +source "$(dirname "$0")/../../lantern_hnsw/scripts/get_arch_and_platform.sh" + +if [[ $PLATFORM == "mac" ]]; then + BUILD_SCRIPT="build-mac.sh" +elif [[ $PLATFORM == "linux" ]]; then + BUILD_SCRIPT="build-linux.sh" +else + echo "Invalid target use one of [mac, linux]" + exit 1 +fi + +# Source platform specific build script +source "$(dirname "$0")/${BUILD_SCRIPT}" if [ ! -z "$RUN_POSTGRES" ] then diff --git a/ci/scripts/build-linux.sh b/ci/scripts/build-linux.sh index a591fbda..9b984629 100755 --- a/ci/scripts/build-linux.sh +++ b/ci/scripts/build-linux.sh @@ -15,6 +15,15 @@ function setup_locale_and_install_packages() { locale-gen en_US.UTF-8 } +function setup_cargo_deps() { + if [ ! -d .cargo ]; then + mkdir .cargo + fi + echo "[target.$(rustc -vV | sed -n 's|host: ||p')]" >> .cargo/config + cargo install cargo-pgrx --version 0.11.3 + cargo pgrx init "--pg$PG_VERSION" /usr/bin/pg_config +} + function setup_postgres() { # Add postgresql apt repo echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list @@ -34,23 +43,6 @@ function setup_postgres() { echo "port = 5432" >> /etc/postgresql/$PG_VERSION/main/postgresql.conf } -function setup_rust() { - if [ ! -f /tmp/rustup.sh ]; then - curl -k -o /tmp/rustup.sh https://sh.rustup.rs - chmod +x /tmp/rustup.sh - /tmp/rustup.sh -y --default-toolchain=1.78.0 - fi - . "$HOME/.cargo/env" -} - -function setup_cargo_deps() { - if [ ! -d .cargo ]; then - mkdir .cargo - fi - echo "[target.$(rustc -vV | sed -n 's|host: ||p')]" >> .cargo/config - cargo install cargo-pgrx --version 0.11.3 - cargo pgrx init "--pg$PG_VERSION" /usr/bin/pg_config -} function install_platform_specific_dependencies() { # Currently lantern_extras binaries are only available for Linux x86_64 diff --git a/ci/scripts/build-mac.sh b/ci/scripts/build-mac.sh index 0c54fb56..e8a0c79b 100755 --- a/ci/scripts/build-mac.sh +++ b/ci/scripts/build-mac.sh @@ -10,6 +10,18 @@ function setup_locale_and_install_packages() { export CXX=/usr/bin/clang++ } +function setup_cargo_deps() { + if [ ! -d .cargo ]; then + mkdir .cargo + fi + + echo "[target.$(rustc -vV | sed -n 's|host: ||p')]" > .cargo/config + echo 'rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]' >> .cargo/config + + cargo install cargo-pgrx --version 0.11.3 + cargo pgrx init "--pg$PG_VERSION" $(which pg_config) +} + function setup_postgres() { cmd="brew install postgresql@${PG_VERSION} clang-format || true" # ignoring brew linking errors if [[ $USER == "root" ]] diff --git a/ci/scripts/utils.sh b/ci/scripts/utils.sh index ba9d237b..4183c281 100644 --- a/ci/scripts/utils.sh +++ b/ci/scripts/utils.sh @@ -12,6 +12,15 @@ function setup_environment() { export PG_CRON_COMMIT_SHA=7e91e72b1bebc5869bb900d9253cc9e92518b33f } +function setup_rust() { + if [ ! -f /tmp/rustup.sh ]; then + curl -k -o /tmp/rustup.sh https://sh.rustup.rs + chmod +x /tmp/rustup.sh + /tmp/rustup.sh -y --default-toolchain=1.78.0 + fi + . "$HOME/.cargo/env" +} + function clone_or_use_source() { if [ -z ${USE_SOURCE} ]; then # Clone from git