Skip to content

Commit

Permalink
Build byte code files in CI, remove from git tree (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe authored Aug 13, 2024
1 parent 8350fc2 commit 0f5bc22
Show file tree
Hide file tree
Showing 28 changed files with 841 additions and 252 deletions.
75 changes: 0 additions & 75 deletions .github/workflows/bound-ci-kt.yml

This file was deleted.

196 changes: 176 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
name: CI

on:
workflow_dispatch:
inputs:
version:
description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0" will result in "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA.'
required: false
default: "0.0.0-SNAPSHOT"
workflow_call:
inputs:
version:
description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0" will result in "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA.'
required: true
type: string
push:
branches:
- main
Expand All @@ -10,49 +22,193 @@ env:
CARGO_TERM_COLOR: always
# Make sure CI fails on all warnings, including Clippy lints
RUSTFLAGS: "-Dwarnings"
WEB5_SDK_LOG_LEVEL: debug

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Build
run: just build
- name: Lint
run: just lint

test:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ] # TODO add back windows-latest https://github.com/TBD54566975/web5-rs/issues/189
rust: [ stable, nightly ]
os: [ubuntu-latest, macos-latest] # TODO add back windows-latest https://github.com/TBD54566975/web5-rs/issues/189
rust: [stable, nightly]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: true
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Test
run: just test
lint:

build_aarch64_apple_darwin:
runs-on: macos-latest
name: Build aarch64-apple-darwin target
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup toolchain install stable
- name: Run Build Script
run: |
cd bindings/web5_uniffi/libtargets/aarch64_apple_darwin
./build
- name: Upload .dylib
uses: actions/upload-artifact@v4.0.0
with:
name: aarch64-apple-darwin-dylib
path: bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib

build_x86_64_apple_darwin:
runs-on: macos-12
name: Build x86_64-apple-darwin target
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup toolchain install stable
- name: Run Build Script
run: |
cd bindings/web5_uniffi/libtargets/x86_64_apple_darwin
./build
- name: Upload .dylib
uses: actions/upload-artifact@v4.0.0
with:
name: x86_64-apple-darwin-dylib
path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib

build_x86_64_unknown_linux_gnu:
runs-on: ubuntu-latest
name: Build x86_64-unknown-linux-gnu target
steps:
- uses: actions/checkout@v2
- name: Run Build Script
run: |
cd bindings/web5_uniffi/libtargets/x86_64_unknown_linux_gnu
./build
- name: Upload .so
uses: actions/upload-artifact@v4.0.0
with:
name: x86_64-unknown-linux-gnu-so
path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so

build_x86_64_unknown_linux_musl:
runs-on: ubuntu-latest
name: Build x86_64-unknown-linux-musl target
steps:
- uses: actions/checkout@v2
- name: Run Build Script
run: |
cd bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl
./build
- name: Upload .so
uses: actions/upload-artifact@v4.0.0
with:
name: x86_64-unknown-linux-musl-so
path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so

kotlin-build-test-deploy-snapshot:
needs:
- build_aarch64_apple_darwin
- build_x86_64_apple_darwin
- build_x86_64_unknown_linux_gnu
- build_x86_64_unknown_linux_musl
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Init Hermit
uses: cashapp/activate-hermit@v1
with:
cache: true
- name: Setup
run: just setup
- name: Formatting
run: cargo fmt --check
- name: Lint
run: just lint
submodules: true
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "adopt"
java-version: "11"

# Cache Maven repo
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Resolve Snapshot Version
id: resolve_version
run: |
# Version resolution: use provided
if [ -n "${{ github.event.inputs.version }}" ]; then
if [[ "${{ github.event.inputs.version }}" != *-SNAPSHOT ]]; then
resolvedVersion="${{ github.event.inputs.version }}-SNAPSHOT"
else
resolvedVersion="${{ github.event.inputs.version }}"
fi
# Otherwise, construct a version for deployment in form X.Y.Z-commit-$shortSHA-SNAPSHOT
else
longSHA=$(git rev-parse --verify HEAD)
shortSHA=$(echo "${longSHA:0:7}")
resolvedVersion="commit-$shortSHA-SNAPSHOT"
echo "Requesting deployment as version: $resolvedVersion"
fi
echo "Resolved SNAPSHOT Version: $resolvedVersion"
echo "resolved_version=$resolvedVersion" >> $GITHUB_OUTPUT
# Package up the native binaries
#TODO Centralize this block as we re-use it via copy/paste right now
- name: Download MacOS aarch64 Native Library
uses: actions/download-artifact@v4.0.0
with:
name: aarch64-apple-darwin-dylib
path: bound/kt/src/main/resources/
- name: Download MacOS x86_64 Native Library
uses: actions/download-artifact@v4.0.0
with:
name: x86_64-apple-darwin-dylib
path: bound/kt/src/main/resources/
- name: Download Linux x86_64 GNU Native Library
uses: actions/download-artifact@v4.0.0
with:
name: x86_64-unknown-linux-gnu-so
path: bound/kt/src/main/resources/
- name: Download Linux x86_64 MUSL Native Library
uses: actions/download-artifact@v4.0.0
with:
name: x86_64-unknown-linux-musl-so
path: bound/kt/src/main/resources/

- name: Deploy Snapshot / Verify
run: |
# cd into the Kotlin project
cd bound/kt/
# Set newly resolved version in POM config
mvn \
versions:set \
--batch-mode \
-DnewVersion=${{ steps.resolve_version.outputs.resolved_version }}
# Only attempt to publish artifact if we have credentials
if [ -n "${{ secrets.ARTIFACTORY_PASSWORD }}" ]; then
# Maven deploy lifecycle will build, run tests, verify, sign, and deploy
mvn deploy --batch-mode --settings .maven_settings.xml -P sign-artifacts
else
# Otherwise, Maven verify lifecycle will build, run tests, and verify
mvn verify --batch-mode
fi
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }}
SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Cargo.lock

.hermit/
.idea/

# Do not put native binaries in source control
bound/kt/src/main/resources/*.dylib
bound/kt/src/main/resources/*.so
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# The format is described: https://github.blog/2017-07-06-introducing-code-owners/

# These owners will be the default owners for everything in the repo.
* @KendallWeihe @nitro-neal @kirahsapong @shamilovtim @diehuxx @decentralgabe @frankhinek
* @KendallWeihe @nitro-neal @kirahsapong @shamilovtim @diehuxx @decentralgabe @frankhinek @leordev @ALRubinger


# -----------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bind-kotlin: setup
generate --library bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib \
--language kotlin \
--out-dir target/bindgen-kotlin
sed -i '' 's/findLibraryName(componentName)/detectSystemTarget()/' target/bindgen-kotlin/web5/sdk/rust/web5.kt
cp target/bindgen-kotlin/web5/sdk/rust/web5.kt bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt

test-bound: setup
Expand Down
1 change: 1 addition & 0 deletions bindings/web5_uniffi/libtargets/aarch64_apple_darwin/build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rustup target add aarch64-apple-darwin
(
cd $REPO_DIR;
cargo build --target aarch64-apple-darwin --release --package web5_uniffi;
mkdir -p bound/kt/src/main/resources;
cp target/aarch64-apple-darwin/release/libweb5_uniffi.dylib \
bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib
)
1 change: 1 addition & 0 deletions bindings/web5_uniffi/libtargets/x86_64_apple_darwin/build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rustup target add x86_64-apple-darwin
cargo build --target x86_64-apple-darwin --release \
--package web5_uniffi \
--features x86_64_apple_darwin;
mkdir -p bound/kt/src/main/resources;
cp target/x86_64-apple-darwin/release/libweb5_uniffi.dylib \
bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR

docker run -d --name $CONTAINER_NAME $IMAGE_NAME

mkdir -p $REPO_DIR/bound/kt/src/main/resources;

docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/libweb5_uniffi.so \
$REPO_DIR/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ docker build -f $(pwd)/Dockerfile -t $IMAGE_NAME $REPO_DIR

docker run -d --name $CONTAINER_NAME $IMAGE_NAME

mkdir -p $REPO_DIR/bound/kt/src/main/resources;

docker cp $CONTAINER_NAME:/usr/src/myapp/target/release/libweb5_uniffi.so \
$REPO_DIR/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so

Expand Down
Loading

0 comments on commit 0f5bc22

Please sign in to comment.