|
| 1 | +name: Native build |
| 2 | + |
| 3 | +# Cross-compiles the Rust shared-core wrapper (sdk-core/src/main/rust) for every supported |
| 4 | +# platform, smoke-tests the produced library, and uploads it as an artifact. The release pipeline |
| 5 | +# downloads these artifacts and overlays them into the single (uber) sdk-core jar. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - 'sdk-core/src/main/rust/**' |
| 11 | + - '.github/workflows/native.yaml' |
| 12 | + workflow_dispatch: |
| 13 | + workflow_call: |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: "Build native (${{ matrix.target }})" |
| 18 | + runs-on: ${{ matrix.runner }} |
| 19 | + timeout-minutes: 30 |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - target: x86_64-unknown-linux-gnu |
| 25 | + runner: ubuntu-latest |
| 26 | + cross: false |
| 27 | + - target: aarch64-unknown-linux-gnu |
| 28 | + runner: ubuntu-latest |
| 29 | + cross: true |
| 30 | + - target: x86_64-unknown-linux-musl |
| 31 | + runner: ubuntu-latest |
| 32 | + cross: true |
| 33 | + - target: aarch64-unknown-linux-musl |
| 34 | + runner: ubuntu-latest |
| 35 | + cross: true |
| 36 | + - target: x86_64-apple-darwin |
| 37 | + runner: macos-13 |
| 38 | + cross: false |
| 39 | + - target: aarch64-apple-darwin |
| 40 | + runner: macos-14 |
| 41 | + cross: false |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Install Rust toolchain |
| 46 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 47 | + with: |
| 48 | + target: ${{ matrix.target }} |
| 49 | + |
| 50 | + - name: Install cross |
| 51 | + if: ${{ matrix.cross }} |
| 52 | + run: cargo install cross --git https://github.com/cross-rs/cross --locked |
| 53 | + |
| 54 | + - name: Build cdylib |
| 55 | + working-directory: sdk-core/src/main/rust |
| 56 | + run: | |
| 57 | + if [ "${{ matrix.cross }}" = "true" ]; then |
| 58 | + cross build --release --target ${{ matrix.target }} |
| 59 | + else |
| 60 | + cargo build --release --target ${{ matrix.target }} |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Locate library |
| 64 | + id: lib |
| 65 | + working-directory: sdk-core/src/main/rust |
| 66 | + run: | |
| 67 | + dir="target/${{ matrix.target }}/release" |
| 68 | + file=$(ls "$dir"/librestate_sdk_core.so "$dir"/librestate_sdk_core.dylib 2>/dev/null | head -1) |
| 69 | + if [ -z "$file" ]; then echo "no library produced for ${{ matrix.target }}"; exit 1; fi |
| 70 | + echo "path=sdk-core/src/main/rust/$file" >> "$GITHUB_OUTPUT" |
| 71 | + echo "file=$file" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Smoke test (exported C symbols present) |
| 74 | + working-directory: sdk-core/src/main/rust |
| 75 | + run: | |
| 76 | + f="${{ steps.lib.outputs.file }}" |
| 77 | + # Linux uses `nm -D` (no symbol prefix); macOS uses `nm -gU` (leading underscore). |
| 78 | + if [ "$RUNNER_OS" = "macOS" ]; then list="nm -gU"; pre="_"; else list="nm -D"; pre=""; fi |
| 79 | + for sym in init vm_new vm_free free_buffer vm_sys_call vm_take_notification; do |
| 80 | + $list "$f" 2>/dev/null | grep -qE "[ ]${pre}${sym}$" || { echo "missing exported symbol: $sym"; exit 1; } |
| 81 | + done |
| 82 | + echo "All expected symbols present in $f" |
| 83 | +
|
| 84 | + - name: Upload native library |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: native-${{ matrix.target }} |
| 88 | + path: ${{ steps.lib.outputs.path }} |
| 89 | + if-no-files-found: error |
0 commit comments