Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Build and Release

on:
push:
branches: [ "main", "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "main", "master" ]

jobs:
build-rust:
name: Build Rust Library (${{ matrix.os }} - ${{ matrix.arch }})
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
arch: universal
target_dir: darwin
- os: ubuntu-latest
arch: x86_64
target_dir: linux-amd64
- os: ubuntu-24.04-arm
arch: aarch64
target_dir: linux-arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.os == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

- name: Build Rust (macOS Universal)
if: matrix.os == 'macos-latest'
run: |
cd embed_anything_binding
cargo build --release --target aarch64-apple-darwin
cargo build --release --target x86_64-apple-darwin
mkdir -p ../pkg/embedder/lib/darwin
lipo -create \
target/aarch64-apple-darwin/release/libembed_anything_binding.a \
target/x86_64-apple-darwin/release/libembed_anything_binding.a \
-output ../pkg/embedder/lib/darwin/libembed_anything_binding.a
# Copy ONNX Runtime shared library (try to find dylibs from both targets)
find target -name "libonnxruntime.dylib*" -type f -exec cp {} ../pkg/embedder/lib/darwin/ \;

- name: Build Rust (Linux)
if: matrix.os != 'macos-latest'
run: |
cd embed_anything_binding
cargo build --release
mkdir -p ../pkg/embedder/lib/${{ matrix.target_dir }}
cp target/release/libembed_anything_binding.a ../pkg/embedder/lib/${{ matrix.target_dir }}/
# Copy ONNX Runtime shared library
find target -name "libonnxruntime.so*" -type f -exec cp {} ../pkg/embedder/lib/${{ matrix.target_dir }}/ \;

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: lib-${{ matrix.target_dir }}
path: pkg/embedder/lib/${{ matrix.target_dir }}/

test-go:
name: Test Go (${{ matrix.os }})
needs: build-rust
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
target_dir: darwin
- os: ubuntu-latest
target_dir: linux-amd64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Download Rust Artifact
uses: actions/download-artifact@v4
with:
name: lib-${{ matrix.target_dir }}
path: pkg/embedder/lib/${{ matrix.target_dir }}

- name: Run Go Tests
env:
LD_LIBRARY_PATH: ${{ github.workspace }}/pkg/embedder/lib/${{ matrix.target_dir }}
DYLD_LIBRARY_PATH: ${{ github.workspace }}/pkg/embedder/lib/${{ matrix.target_dir }}
run: |
# Ensure link paths are correct for testing
# The CGO flags in the code already point to the correct relative paths
go test -v ./pkg/embedder/...

release:
name: Create Release
needs: build-rust
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Prepare Release Assets
run: |
mkdir assets
# macOS
mv artifacts/lib-darwin/libembed_anything_binding.a assets/libembed_anything_binding-darwin-universal.a
# Linux AMD64
mv artifacts/lib-linux-amd64/libembed_anything_binding.a assets/libembed_anything_binding-linux-x86_64.a
# Linux ARM64
mv artifacts/lib-linux-arm64/libembed_anything_binding.a assets/libembed_anything_binding-linux-aarch64.a

# Create tarballs for each
cd assets
for f in *.a; do
tar -czvf "${f%.a}.tar.gz" "$f"
done

- name: Release
uses: softprops/action-gh-release@v2
with:
files: assets/*.tar.gz
2 changes: 2 additions & 0 deletions scripts/compile_rust_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ cargo build --release

# Copy the static library
cp target/release/libembed_anything_binding.a "$TARGET_DIR/"
# Copy ONNX Runtime shared library
find target -name "libonnxruntime.so*" -type f -exec cp {} "$TARGET_DIR/" \;

echo "✅ Library compiled and copied to $TARGET_DIR"
3 changes: 3 additions & 0 deletions scripts/compile_rust_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ if command -v lipo >/dev/null 2>&1; then
target/aarch64-apple-darwin/release/libembed_anything_binding.a \
target/x86_64-apple-darwin/release/libembed_anything_binding.a \
-output "$TARGET_DIR/libembed_anything_binding.a"

# Copy ONNX Runtime shared library
find target -name "libonnxruntime.dylib*" -type f -exec cp {} "$TARGET_DIR/" \;
echo "✅ Universal library created at $TARGET_DIR/libembed_anything_binding.a"
lipo -info "$TARGET_DIR/libembed_anything_binding.a"
else
Expand Down
37 changes: 24 additions & 13 deletions scripts/download_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ case $OS in
Darwin)
GOOS="darwin"
PLATFORM="darwin"
ASSET_NAME="libembed_anything_binding-darwin-universal.a" # Example
ASSET_NAME="libembed_anything_binding-darwin-universal.tar.gz"
;;
Linux)
GOOS="linux"
case $ARCH in
x86_64)
PLATFORM="linux-amd64"
ASSET_NAME="libembed_anything_binding-linux-x86_64.a"
ASSET_NAME="libembed_anything_binding-linux-x86_64.tar.gz"
;;
aarch64|arm64)
PLATFORM="linux-arm64"
ASSET_NAME="libembed_anything_binding-linux-aarch64.a"
ASSET_NAME="libembed_anything_binding-linux-aarch64.tar.gz"
;;
*)
echo "Unsupported architecture: $ARCH"
Expand All @@ -52,18 +52,29 @@ mkdir -p "$TARGET_DIR"
echo "🔍 Detected platform: $PLATFORM"
echo "📦 This would download $ASSET_NAME from $REPO"

# Note: This is a template. The user should update the download logic
# once they have a release pipeline.

# Example download logic:
# DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$ASSET_NAME"
# curl -L -o "$TARGET_DIR/libembed_anything_binding.a" "$DOWNLOAD_URL"

# For now, we will just check if the library exists locally,
# and if not, suggest running the compile script.

# Check if library exists. If not, try to download or suggest compilation.
if [ ! -f "$TARGET_DIR/libembed_anything_binding.a" ]; then
echo "⚠️ Library not found in $TARGET_DIR"

# Try to download if version is set (not just template)
if [ "$VERSION" != "template" ]; then
echo "🌐 Attempting to download pre-compiled binary ($ASSET_NAME)..."
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$ASSET_NAME"

# Temporary file for the tarball
TEMP_TAR=$(mktemp)

if command -v curl >/dev/null 2>&1; then
if curl -L -f -o "$TEMP_TAR" "$DOWNLOAD_URL"; then
tar -xzf "$TEMP_TAR" -C "$TARGET_DIR" --strip-components=0
echo "✅ Downloaded and extracted library."
rm "$TEMP_TAR"
exit 0
fi
fi
rm "$TEMP_TAR"
fi

if [ "$OS" = "Darwin" ]; then
echo "💡 You can compile it locally by running: ./scripts/compile_rust_mac.sh"
else
Expand Down
Loading