Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm followup: fix release workflows #1146

Merged
merged 4 commits into from
Oct 17, 2024
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
18 changes: 2 additions & 16 deletions .github/workflows/release-kotlin-bindings.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Release Kotlin Bindings

on:
workflow_dispatch:

jobs:
build-linux:
runs-on: warp-ubuntu-latest-x64-16x
Expand All @@ -26,64 +24,53 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Update rust toolchains, add target
run: |
rustup update
rustup target add ${{ matrix.target }}
- name: Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
bindings_ffi
# Install latest cross to mitigate unwind linking issue on android builds.
# See https://github.com/cross-rs/cross/issues/1222
- name: Install cross
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Build target
env:
CROSS_NO_WARNINGS: "0"
run: |
cross build --release --target ${{ matrix.target }} --manifest-path bindings_ffi/Cargo.toml --target-dir bindings_ffi/target
cross build --release --target ${{ matrix.target }} --manifest-path bindings_ffi/Cargo.toml
- name: Prepare JNI libs
run: |
mkdir -p bindings_ffi/jniLibs/${{ matrix.output_target }}/ && \
cp bindings_ffi/target/${{ matrix.target }}/release/libxmtpv3.so bindings_ffi/jniLibs/${{ matrix.output_target }}/libuniffi_xmtpv3.so
cp target/${{ matrix.target }}/release/libxmtpv3.so bindings_ffi/jniLibs/${{ matrix.output_target }}/libuniffi_xmtpv3.so
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.output_target }}
path: bindings_ffi/jniLibs/${{ matrix.output_target }}/libuniffi_xmtpv3.so
retention-days: 1

package-kotlin:
needs: [build-linux]
runs-on: warp-ubuntu-latest-x64-16x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: bindings_ffi/jniLibs

- name: Build archive
working-directory: bindings_ffi
run: |
zip -r LibXMTPKotlinFFI.zip jniLibs
- name: Get short SHA
id: slug
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"

- name: Create release
id: create_release
uses: actions/create-release@v1
Expand All @@ -94,7 +81,6 @@ jobs:
release_name: Kotlin-Bindings-${{ steps.slug.outputs.sha7 }}
draft: false
prerelease: true

- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/release-swift-bindings.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Release Swift Bindings

on:
workflow_dispatch:

jobs:
build-macos:
runs-on: warp-macos-13-arm64-6x
Expand All @@ -18,83 +16,69 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Update rust toolchains, add target
run: |
rustup update
rustup target add ${{ matrix.target }}
- name: Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
bindings_ffi
# Install latest cross to mitigate unwind linking issue on android builds.
# See https://github.com/cross-rs/cross/issues/1222
- name: Install cross
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Build target
env:
CROSS_NO_WARNINGS: "0"
run: |
cross build --release --target ${{ matrix.target }} --manifest-path bindings_ffi/Cargo.toml --target-dir bindings_ffi/target
cross build --release --target ${{ matrix.target }} --manifest-path bindings_ffi/Cargo.toml
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: bindings_ffi/target/${{ matrix.target }}/release/libxmtpv3.a
path: target/${{ matrix.target }}/release/libxmtpv3.a
retention-days: 1

swift:
runs-on: warp-macos-13-arm64-6x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Update rust toolchains, add target
run: |
rustup update
rustup target add x86_64-apple-darwin
- name: Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
.
bindings_ffi
- name: Install swift
run: brew install swiftformat

- name: Generate bindings
working-directory: bindings_ffi
run: |
make swift
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: swift
path: bindings_ffi/build/swift/
retention-days: 1

package-swift:
needs: [build-macos, swift]
runs-on: warp-macos-13-arm64-6x
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: bindings_ffi/build

- name: Build archive
working-directory: bindings_ffi
run: |
Expand All @@ -103,17 +87,14 @@ jobs:
make framework
cp ../LICENSE ./LICENSE
zip -r LibXMTPSwiftFFI.zip Sources LibXMTPSwiftFFI.xcframework LICENSE
- name: Calculate checksum
id: checksum
working-directory: bindings_ffi
run: |
echo "::set-output name=checksum::$(shasum -a 256 LibXMTPSwiftFFI.zip | awk '{ print $1 }')"
- name: Get short SHA
id: slug
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"

- name: Create release
id: create_release
uses: actions/create-release@v1
Expand All @@ -125,7 +106,6 @@ jobs:
body: "Checksum of LibXMTPSwiftFFI.zip: ${{ steps.checksum.outputs.checksum }}"
draft: false
prerelease: true

- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
Expand Down
23 changes: 13 additions & 10 deletions bindings_ffi/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PROJECT_NAME = xmtpv3
WORKSPACE_MANIFEST=$(shell cargo locate-project --workspace --message-format=plain)
WORKSPACE_PATH=$(shell dirname $(WORKSPACE_MANIFEST))
TARGET_DIR=$(WORKSPACE_PATH)/target

# Simulator config
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios-sim
Expand Down Expand Up @@ -42,19 +45,19 @@ libxmtp-version:
echo "Version: $(GIT_COMMIT_HASH)\nBranch: $(GIT_BRANCH)\nDate: $(GIT_COMMIT_DATE)" > libxmtp-version.txt

$(ARCHS_IOS): %: build-sqlcipher
cross build --target $@ --target-dir ./target --release --no-default-features
cross build --target $@ --target-dir $(TARGET_DIR) --release --no-default-features
mkdir -p build/$@
mv target/$@/release/$(LIB) build/$@/$(LIB)
mv $(TARGET_DIR)/$@/release/$(LIB) build/$@/$(LIB)

$(ARCHS_MAC): %: build-sqlcipher
cross build --target $@ --target-dir ./target --release --no-default-features
cross build --target $@ --target-dir $(TARGET_DIR) --release --no-default-features
mkdir -p build/$@
mv target/$@/release/$(LIB) build/$@/$(LIB)
mv $(TARGET_DIR)/$@/release/$(LIB) build/$@/$(LIB)

aarch64-apple-ios: build-sqlcipher
cross build --target $@ --target-dir ./target --release
cross build --target $@ --target-dir $(TARGET_DIR) --release
mkdir -p build/$@
mv target/$@/release/$(LIB) build/$@/$(LIB)
mv $(TARGET_DIR)/$@/release/$(LIB) build/$@/$(LIB)

$(LIB): $(ARCHS_IOS) $(ARCHS_MAC) aarch64-apple-ios

Expand All @@ -78,10 +81,10 @@ framework: lipo

# build uniffi bindings for swift
swift: libxmtp-version
cargo build --release
cargo build --release -p xmtpv3
rm -rf build/swift
target/release/ffi-uniffi-bindgen generate \
--lib-file target/release/$(LIB) \
$(TARGET_DIR)/release/ffi-uniffi-bindgen generate \
--lib-file $(TARGET_DIR)/release/$(LIB) \
src/$(PROJECT_NAME).udl \
--out-dir build/swift \
--language swift
Expand All @@ -91,6 +94,6 @@ swift: libxmtp-version
mv build/swift/$(PROJECT_NAME)FFI.modulemap build/swift/include/module.modulemap
cp libxmtp-version.txt build/swift/

swiftlocal: libxmtpv3.a swift framework
swiftlocal: libxmtpv3.a swift framework

.PHONY: $(ARCHS_IOS) $(ARCHS_MAC) framework all aarch64-apple-ios install-jar echo-jar download-toolchains swift lipo download-sqlcipher build-sqlcipher
32 changes: 21 additions & 11 deletions bindings_ffi/cross_build.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
#!/bin/bash

RED='\033[0;31m'
NC='\033[0m' # No Color

main() {
set -ex
# Dev+Debug is better for debugging Rust crashes, but generates much larger libraries (100's of MB)
# PROFILE="dev"
# BINARY_PROFILE="debug"
PROFILE="release"
BINARY_PROFILE="release"

WORKSPACE_MANIFEST="$(cargo locate-project --workspace --message-format=plain)"
WORKSPACE_PATH="$(dirname $WORKSPACE_MANIFEST)"
TARGET_DIR="$WORKSPACE_PATH/target"
BINDINGS_MANIFEST="$WORKSPACE_PATH/bindings_ffi/Cargo.toml"
# Go to the workspace root so that the workspace config can be found by cross
cd ..
cd $WORKSPACE_PATH
if ! cross &>/dev/null; then
echo -e "${RED} `cargo-cross` not detected. install cargo-cross to continue${NC}";
exit
fi
# Uncomment to build for all targets. aarch64-linux-android is the default target for an emulator on Android Studio on an M1 mac.
cross build --manifest-path ./bindings_ffi/Cargo.toml --target x86_64-linux-android --target-dir ./bindings_ffi/target --profile $PROFILE && \
cross build --manifest-path ./bindings_ffi/Cargo.toml --target i686-linux-android --target-dir ./bindings_ffi/target --profile $PROFILE && \
cross build --manifest-path ./bindings_ffi/Cargo.toml --target armv7-linux-androideabi --target-dir ./bindings_ffi/target --profile $PROFILE && \
cross build --manifest-path ./bindings_ffi/Cargo.toml --target aarch64-linux-android --target-dir ./bindings_ffi/target --profile $PROFILE
cross build --manifest-path $BINDINGS_MANIFEST --target x86_64-linux-android --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target i686-linux-android --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target armv7-linux-androideabi --target-dir $TARGET_DIR --profile $PROFILE && \
cross build --manifest-path $BINDINGS_MANIFEST --target aarch64-linux-android --target-dir $TARGET_DIR --profile $PROFILE

# Move everything to jniLibs folder and rename
LIBRARY_NAME="libxmtpv3"
TARGET_NAME="libuniffi_xmtpv3"
cd bindings_ffi
cd $(dirname $BINDINGS_MANIFEST) # cd bindings_ffi
rm -rf jniLibs/
mkdir -p jniLibs/armeabi-v7a/ && \
cp target/armv7-linux-androideabi/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/armeabi-v7a/$TARGET_NAME.so && \
cp $WORKSPACE_PATH/target/armv7-linux-androideabi/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/armeabi-v7a/$TARGET_NAME.so && \
mkdir -p jniLibs/x86/ && \
cp target/i686-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86/$TARGET_NAME.so && \
cp $WORKSPACE_PATH/target/i686-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86/$TARGET_NAME.so && \
mkdir -p jniLibs/x86_64/ && \
cp target/x86_64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86_64/$TARGET_NAME.so && \
cp $WORKSPACE_PATH/target/x86_64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/x86_64/$TARGET_NAME.so && \
mkdir -p jniLibs/arm64-v8a/ && \
cp target/aarch64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/arm64-v8a/$TARGET_NAME.so
cp $WORKSPACE_PATH/target/aarch64-linux-android/$BINARY_PROFILE/$LIBRARY_NAME.so jniLibs/arm64-v8a/$TARGET_NAME.so
}

time main
39 changes: 28 additions & 11 deletions bindings_ffi/gen_kotlin.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
CRATE_NAME="bindings_ffi"
PROJECT_NAME="xmtpv3"

cargo build --release
pushd .. > /dev/null
rm -f $CRATE_NAME/src/uniffi/$PROJECT_NAME/$PROJECT_NAME.kt
bindings_ffi/target/release/ffi-uniffi-bindgen generate \
--lib-file bindings_ffi/target/release/libxmtpv3.dylib \
$CRATE_NAME/src/$PROJECT_NAME.udl \
RED='\033[0;31m'
NC='\033[0m' # No Color

WORKSPACE_MANIFEST="$(cargo locate-project --workspace --message-format=plain)"
WORKSPACE_PATH="$(dirname $WORKSPACE_MANIFEST)"
BINDINGS_MANIFEST="$WORKSPACE_PATH/bindings_ffi/Cargo.toml"
BINDINGS_PATH="$(dirname $BINDINGS_MANIFEST)"
TARGET_DIR="$WORKSPACE_PATH/target"
XMTP_ANDROID="${1:-../xmtp_android}"

if [ ! -d $XMTP_ANDROID ]; then
echo "${RED}xmtp-android directory not detected${NC}"
echo "${RED}Ensure \`github.com/xmtp/xmtp_android\` is cloned as a sibling directory or passed as the first argument to this script.${NC}"
exit
fi
echo "Android Directory: $XMTP_ANDROID"

cd $WORKSPACE_PATH
cargo build --release --manifest-path $BINDINGS_MANIFEST
rm -f $BINDINGS_PATH/src/uniffi/$PROJECT_NAME/$PROJECT_NAME.kt
$TARGET_DIR/release/ffi-uniffi-bindgen generate \
--lib-file $TARGET_DIR/release/libxmtpv3.dylib \
$BINDINGS_PATH/src/$PROJECT_NAME.udl \
--language kotlin
popd > /dev/null
cd $BINDINGS_PATH
make libxmtp-version
cp libxmtp-version.txt src/uniffi/$PROJECT_NAME/

# Assumes libxmtp is in a peer directory of xmtp-android
cp src/uniffi/xmtpv3/xmtpv3.kt ../../xmtp-android/library/src/main/java/xmtpv3.kt
cp src/uniffi/xmtpv3/libxmtp-version.txt ../../xmtp-android/library/src/main/java/libxmtp-version.txt
cd $WORKSPACE_PATH

cp $BINDINGS_PATH/src/uniffi/xmtpv3/xmtpv3.kt $XMTP_ANDROID/library/src/main/java/xmtpv3.kt
cp $BINDINGS_PATH/src/uniffi/xmtpv3/libxmtp-version.txt $XMTP_ANDROID/library/src/main/java/libxmtp-version.txt
Loading