Skip to content

Commit

Permalink
create macos binaries for lantern_extras and lantern_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Oct 14, 2024
1 parent 2f7f42c commit 0b26962
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ 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
with:
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 }}
Expand Down
25 changes: 19 additions & 6 deletions ci/scripts/build-extras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 9 additions & 17 deletions ci/scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions ci/scripts/build-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]]
Expand Down
9 changes: 9 additions & 0 deletions ci/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b26962

Please sign in to comment.