|
| 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 | + rustflags: "" |
| 28 | + - target: aarch64-unknown-linux-gnu |
| 29 | + runner: ubuntu-latest |
| 30 | + cross: true |
| 31 | + rustflags: "" |
| 32 | + # musl is statically linked by default, which can't produce a cdylib (.so); disabling |
| 33 | + # crt-static makes the target dynamically linkable so the shared library can be built. |
| 34 | + - target: x86_64-unknown-linux-musl |
| 35 | + runner: ubuntu-latest |
| 36 | + cross: true |
| 37 | + rustflags: "-C target-feature=-crt-static" |
| 38 | + - target: aarch64-unknown-linux-musl |
| 39 | + runner: ubuntu-latest |
| 40 | + cross: true |
| 41 | + rustflags: "-C target-feature=-crt-static" |
| 42 | + # macOS runners are expensive; comment out the darwin targets to disable them. |
| 43 | + # x86_64 darwin disabled for now — re-enable if Intel Mac support is needed. |
| 44 | + # - target: x86_64-apple-darwin |
| 45 | + # runner: macos-13 |
| 46 | + # cross: false |
| 47 | + # rustflags: "" |
| 48 | + - target: aarch64-apple-darwin |
| 49 | + runner: macos-14 |
| 50 | + cross: false |
| 51 | + rustflags: "" |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v6 |
| 54 | + |
| 55 | + - name: Install Rust toolchain |
| 56 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 57 | + with: |
| 58 | + target: ${{ matrix.target }} |
| 59 | + cache-workspaces: sdk-core/src/main/rust |
| 60 | + # Segment the cache per target. Otherwise all Linux targets share one cache, and the |
| 61 | + # native x86_64 job (host glibc 2.39) populates target/release/build with host-compiled |
| 62 | + # build-script/proc-macro binaries that the `cross` jobs then restore and try to run |
| 63 | + # inside the older cross container (glibc ~2.31) -> "GLIBC_2.39 not found", build fails. |
| 64 | + cache-key: ${{ matrix.target }} |
| 65 | + |
| 66 | + - name: Install cross |
| 67 | + if: ${{ matrix.cross }} |
| 68 | + run: cargo install cross --git https://github.com/cross-rs/cross --locked |
| 69 | + |
| 70 | + - name: Build cdylib |
| 71 | + working-directory: sdk-core/src/main/rust |
| 72 | + env: |
| 73 | + # `cross` forwards RUSTFLAGS into the build container. |
| 74 | + RUSTFLAGS: ${{ matrix.rustflags }} |
| 75 | + run: | |
| 76 | + if [ "${{ matrix.cross }}" = "true" ]; then |
| 77 | + cross build --release --target ${{ matrix.target }} |
| 78 | + else |
| 79 | + cargo build --release --target ${{ matrix.target }} |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Locate library |
| 83 | + id: lib |
| 84 | + working-directory: sdk-core/src/main/rust |
| 85 | + run: | |
| 86 | + dir="target/${{ matrix.target }}/release" |
| 87 | + file=$(ls "$dir"/librestate_sdk_core.so "$dir"/librestate_sdk_core.dylib 2>/dev/null | head -1) |
| 88 | + if [ -z "$file" ]; then echo "no library produced for ${{ matrix.target }}"; exit 1; fi |
| 89 | + echo "path=sdk-core/src/main/rust/$file" >> "$GITHUB_OUTPUT" |
| 90 | + echo "file=$file" >> "$GITHUB_OUTPUT" |
| 91 | +
|
| 92 | + - name: Smoke test (exported C symbols present) |
| 93 | + working-directory: sdk-core/src/main/rust |
| 94 | + run: | |
| 95 | + f="${{ steps.lib.outputs.file }}" |
| 96 | + # Linux uses `nm -D` (no symbol prefix); macOS uses `nm -gU` (leading underscore). |
| 97 | + if [ "$RUNNER_OS" = "macOS" ]; then list="nm -gU"; pre="_"; else list="nm -D"; pre=""; fi |
| 98 | + for sym in init vm_new vm_free free_buffer vm_sys_call vm_take_notification; do |
| 99 | + $list "$f" 2>/dev/null | grep -qE "[ ]${pre}${sym}$" || { echo "missing exported symbol: $sym"; exit 1; } |
| 100 | + done |
| 101 | + echo "All expected symbols present in $f" |
| 102 | +
|
| 103 | + - name: Upload native library |
| 104 | + uses: actions/upload-artifact@v7 |
| 105 | + with: |
| 106 | + name: native-${{ matrix.target }} |
| 107 | + path: ${{ steps.lib.outputs.path }} |
| 108 | + if-no-files-found: error |
0 commit comments