Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Build Noosphere artifacts (Apple) #44

Build Noosphere artifacts (Apple)

Build Noosphere artifacts (Apple) #44

on:
workflow_call:
inputs:
for-test:
type: boolean
default: false
workflow_dispatch:
inputs:
for-test:
description: 'MacOS x86_64 support only'
type: boolean
default: false
name: 'Build Noosphere artifacts (Apple)'
jobs:
determine-build-matrix:
name: 'Determine build matrix'
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
env:
FOR_TEST: ${{ inputs.for-test }}
run: |
if [[ $FOR_TEST == true ]]; then
targets=("x86_64-apple-darwin")
else
targets=(
"aarch64-apple-ios"
"x86_64-apple-ios"
"aarch64-apple-ios-sim"
"x86_64-apple-darwin"
"aarch64-apple-darwin"
)
fi
echo -n 'matrix={"include":[' >> $GITHUB_OUTPUT
target_out=""
for target in "${targets[@]}"; do
target_json="{\"target\":\"$target\"}"
if [ -z "$target_out" ]; then
target_out="$target_json"
else
target_out="$target_out,$target_json"
fi
done
echo -n "$target_out ]}" >> $GITHUB_OUTPUT
# Build Noosphere out of the noosphere crate for Apple targets
noosphere-apple-build:
name: 'Build Noosphere libraries (Apple)'
needs: ['determine-build-matrix']
strategy:
fail-fast: true
matrix: ${{ fromJSON(needs.determine-build-matrix.outputs.matrix) }}
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.target }}
- name: 'Setup Rust'
run: |
curl -sSf https://sh.rustup.rs | sh -s -- -y
rustup target add ${{ matrix.target }}
- uses: ConorMacBride/install-package@v1
with:
brew: protobuf cmake
- name: 'Cargo Build'
run: cargo build --package noosphere --release --locked --target ${{ matrix.target }} --features rocksdb
- run: |
cd target/${{ matrix.target }}/release
- uses: actions/upload-artifact@v3
with:
name: lib_${{ matrix.target }}
path: target/${{ matrix.target }}/release/libnoosphere.a
# Generates the FFI C header for Noosphere and bundles it with a
# modulemap for Apple use cases
noosphere-header-generation:
name: 'Generate Noosphere C header'
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: 'Setup Rust'
run: |
curl -sSf https://sh.rustup.rs | sh -s -- -y
- uses: ConorMacBride/install-package@v1
with:
brew: protobuf cmake
- name: 'Generate the header'
run: |
./scripts/generate-headers.sh
- uses: actions/upload-artifact@v3
with:
name: include
path: target/headers/include
# Generate Apple "universal" libraries for Noosphere for supported targets
noosphere-apple-lipo:
name: 'Generate Noosphere universal libraries (Apple)'
needs: ['noosphere-apple-build']
strategy:
fail-fast: false
matrix:
include:
# iOS Simulator
- legacy_target: x86_64-apple-ios
future_target: aarch64-apple-ios-sim
platform: ios-simulator
# Mac OS
- legacy_target: x86_64-apple-darwin
future_target: aarch64-apple-darwin
platform: macos
runs-on: macos-12
steps:
- uses: actions/download-artifact@v3
if: ${{ !inputs.for-test }}
- name: 'Make a universal library'
if: ${{ !inputs.for-test }}
run: |
lipo -create \
./lib_${{ matrix.legacy_target }}/libnoosphere.a \
./lib_${{ matrix.future_target }}/libnoosphere.a \
-output ./libnoosphere.a
- uses: actions/upload-artifact@v3
if: ${{ !inputs.for-test }}
with:
name: lib_${{ matrix.platform }}-universal
path: libnoosphere.a
# Generates an Apple XCode Framework for Noosphere from all the built
# Apple libraries
noosphere-apple-xcframework:
name: 'Generate Noosphere XCFramework'
needs: ['noosphere-apple-lipo', 'noosphere-header-generation']
runs-on: macos-12
steps:
- uses: actions/download-artifact@v3
- name: 'Generate XCFramework'
env:
FOR_TEST: ${{ inputs.for-test }}
run: |
if [ "$FOR_TEST" = true ]; then
xcodebuild -create-xcframework \
-library ./lib_x86_64-apple-darwin/libnoosphere.a \
-headers ./include/ \
-output ./LibNoosphere.xcframework
else
xcodebuild -create-xcframework \
-library ./lib_macos-universal/libnoosphere.a \
-headers ./include/ \
-library ./lib_ios-simulator-universal/libnoosphere.a \
-headers ./include/ \
-library ./lib_aarch64-apple-ios/libnoosphere.a \
-headers ./include/ \
-output ./LibNoosphere.xcframework
fi
zip -r ./libnoosphere-apple-xcframework.zip ./LibNoosphere.xcframework
- uses: actions/upload-artifact@v3
with:
name: libnoosphere_apple_framework
path: ./libnoosphere-apple-xcframework.zip