|
| 1 | +name: Build and Release Yttrium Kotlin Utils |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + description: "Version to release (e.g. 0.0.1)" |
| 7 | + required: true |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + VERSION: ${{ github.event.inputs.version || '0.0.1' }} |
| 11 | + TARGET_BRANCH: ${{ github.ref_name }} |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | +jobs: |
| 15 | + build-kotlin-utils-artifacts: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + target: [aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android] |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - name: Install Rust toolchain |
| 23 | + uses: actions-rs/toolchain@v1 |
| 24 | + with: |
| 25 | + toolchain: stable |
| 26 | + target: ${{ matrix.target }} |
| 27 | + override: true |
| 28 | + components: rust-src |
| 29 | + - name: Set up Java |
| 30 | + uses: actions/setup-java@v3 |
| 31 | + with: |
| 32 | + distribution: "temurin" |
| 33 | + java-version: "17" |
| 34 | + - name: Set up Android SDK |
| 35 | + uses: android-actions/setup-android@v2 |
| 36 | + with: |
| 37 | + api-level: 35 |
| 38 | + build-tools: 35.0.0 |
| 39 | + ndk-version: 28.2.13676358 |
| 40 | + - name: Install cargo-ndk |
| 41 | + run: | |
| 42 | + cargo install cargo-ndk --locked |
| 43 | + - name: Build Rust library (utils feature set) |
| 44 | + run: | |
| 45 | + cargo ndk -t ${{ matrix.target }} build \ |
| 46 | + --profile=uniffi-release-kotlin \ |
| 47 | + --no-default-features \ |
| 48 | + --features=android,chain_abstraction_client,solana,stacks,sui,ton,eip155,uniffi/cli |
| 49 | + - name: Generate Kotlin utils bindings (once, on aarch64 only) |
| 50 | + if: ${{ matrix.target == 'aarch64-linux-android' }} |
| 51 | + run: | |
| 52 | + rm -rf yttrium/kotlin-utils-bindings |
| 53 | + cargo run \ |
| 54 | + --no-default-features \ |
| 55 | + --features=android,chain_abstraction_client,solana,stacks,sui,ton,eip155,uniffi/cli \ |
| 56 | + -p kotlin-ffi \ |
| 57 | + --bin uniffi-bindgen generate \ |
| 58 | + --library target/${{ matrix.target }}/uniffi-release-kotlin/libuniffi_yttrium.so \ |
| 59 | + --language kotlin \ |
| 60 | + --out-dir yttrium/kotlin-utils-bindings |
| 61 | + |
| 62 | + # Rename packages and imports for utils variant |
| 63 | + find yttrium/kotlin-utils-bindings -type f -name "*.kt" -exec perl -i -pe ' |
| 64 | + s/^package uniffi\.yttrium$/package uniffi.yttrium_utils/; |
| 65 | + s/^import uniffi\.yttrium\./import uniffi.yttrium_utils./g; |
| 66 | + s/^package uniffi\.uniffi_yttrium$/package uniffi.uniffi_yttrium_utils/; |
| 67 | + s/^import uniffi\.uniffi_yttrium\./import uniffi.uniffi_yttrium_utils./g; |
| 68 | + s/\buniffi\.yttrium\./uniffi.yttrium_utils./g; |
| 69 | + s/\buniffi\.uniffi_yttrium\./uniffi.uniffi_yttrium_utils./g; |
| 70 | + s/return "uniffi_yttrium"/return "uniffi_yttrium_utils"/g; |
| 71 | + ' {} \; |
| 72 | + - name: Strip binaries |
| 73 | + run: | |
| 74 | + LATEST_NDK=$(ls -1 $ANDROID_HOME/ndk/ | sort -V | tail -1) |
| 75 | + echo "Using NDK version: $LATEST_NDK" |
| 76 | + |
| 77 | + NDK_PATH="$ANDROID_HOME/ndk/$LATEST_NDK" |
| 78 | + if [ -f "$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip" ]; then |
| 79 | + echo "Found llvm-strip at: $NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip" |
| 80 | + $NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip target/${{ matrix.target }}/uniffi-release-kotlin/libuniffi_yttrium.so |
| 81 | + else |
| 82 | + echo "Warning: Could not find llvm-strip, skipping strip step" |
| 83 | + echo "Available NDK versions:" |
| 84 | + ls -la $ANDROID_HOME/ndk/ || echo "No NDK directory found" |
| 85 | + echo "Looking for llvm-strip in common locations:" |
| 86 | + find $ANDROID_HOME/ndk -name "llvm-strip" 2>/dev/null || echo "No llvm-strip found" |
| 87 | + fi |
| 88 | + - name: Prepare local artifacts folder |
| 89 | + run: | |
| 90 | + declare -A abi_map |
| 91 | + abi_map[aarch64-linux-android]="arm64-v8a" |
| 92 | + abi_map[armv7-linux-androideabi]="armeabi-v7a" |
| 93 | + abi_map[x86_64-linux-android]="x86_64" |
| 94 | +
|
| 95 | + abi_name=${abi_map[${{ matrix.target }}]} |
| 96 | +
|
| 97 | + if [ -z "$abi_name" ]; then |
| 98 | + echo "Unknown ABI for target ${{ matrix.target }}" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +
|
| 102 | + mkdir -p yttrium/libs/$abi_name |
| 103 | + cp target/${{ matrix.target }}/uniffi-release-kotlin/libuniffi_yttrium.so yttrium/libs/$abi_name/libuniffi_yttrium_utils.so |
| 104 | +
|
| 105 | + - name: Upload artifact (unique name per target) |
| 106 | + uses: actions/upload-artifact@v4 |
| 107 | + with: |
| 108 | + name: utils-artifacts-${{ matrix.target }} |
| 109 | + path: yttrium/ |
| 110 | + |
| 111 | + combine-utils-artifacts: |
| 112 | + needs: build-kotlin-utils-artifacts |
| 113 | + runs-on: ubuntu-latest |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v3 |
| 116 | + - name: Download aarch64 artifact |
| 117 | + uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + name: utils-artifacts-aarch64-linux-android |
| 120 | + path: combined/aarch64 |
| 121 | + - name: Download armv7 artifact |
| 122 | + uses: actions/download-artifact@v4 |
| 123 | + with: |
| 124 | + name: utils-artifacts-armv7-linux-androideabi |
| 125 | + path: combined/armv7 |
| 126 | + - name: Download x86_64 artifact |
| 127 | + uses: actions/download-artifact@v4 |
| 128 | + with: |
| 129 | + name: utils-artifacts-x86_64-linux-android |
| 130 | + path: combined/x86_64 |
| 131 | + - name: Merge utils artifacts |
| 132 | + run: | |
| 133 | + mkdir -p merged/yttrium/libs |
| 134 | +
|
| 135 | + cp -r combined/aarch64/libs/arm64-v8a merged/yttrium/libs/ |
| 136 | + cp -r combined/armv7/libs/armeabi-v7a merged/yttrium/libs/ |
| 137 | + cp -r combined/x86_64/libs/x86_64 merged/yttrium/libs/ |
| 138 | +
|
| 139 | + if [ -d combined/aarch64/kotlin-utils-bindings ]; then |
| 140 | + cp -r combined/aarch64/kotlin-utils-bindings merged/yttrium/ |
| 141 | + fi |
| 142 | + - name: Upload single combined artifact |
| 143 | + uses: actions/upload-artifact@v4 |
| 144 | + with: |
| 145 | + name: utils-artifacts |
| 146 | + path: merged/yttrium/ |
| 147 | + |
| 148 | + create-utils-release: |
| 149 | + needs: combine-utils-artifacts |
| 150 | + runs-on: ubuntu-latest |
| 151 | + steps: |
| 152 | + - name: Checkout repository |
| 153 | + uses: actions/checkout@v3 |
| 154 | + - name: Download single final artifact |
| 155 | + uses: actions/download-artifact@v4 |
| 156 | + with: |
| 157 | + name: utils-artifacts |
| 158 | + path: yttrium/ |
| 159 | + - name: Create utils artifacts zip |
| 160 | + run: | |
| 161 | + echo "Creating zip from yttrium directory..." |
| 162 | + ls -R yttrium/ |
| 163 | + zip -r kotlin-utils-artifacts.zip yttrium/ |
| 164 | + echo "Zip created, verifying..." |
| 165 | + ls -lh kotlin-utils-artifacts.zip |
| 166 | + unzip -t kotlin-utils-artifacts.zip |
| 167 | + echo "Zip verification successful" |
| 168 | + - name: Create Release |
| 169 | + id: create_release |
| 170 | + uses: actions/create-release@v1 |
| 171 | + env: |
| 172 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + with: |
| 174 | + tag_name: kotlin-utils-${{ env.VERSION }} |
| 175 | + release_name: "Yttrium Kotlin Utils ${{ env.VERSION }}" |
| 176 | + body: | |
| 177 | + Kotlin utils release version ${{ env.VERSION }} |
| 178 | +
|
| 179 | + **Branch:** ${{ env.TARGET_BRANCH }} |
| 180 | + draft: false |
| 181 | + prerelease: false |
| 182 | + - name: Upload Release Assets |
| 183 | + uses: actions/upload-release-asset@v1 |
| 184 | + env: |
| 185 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + with: |
| 187 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 188 | + asset_path: kotlin-utils-artifacts.zip |
| 189 | + asset_name: kotlin-utils-artifacts.zip |
| 190 | + asset_content_type: application/zip |
0 commit comments