From a9ac62d7e050655bf13d03a3ec1ddf9b74c32146 Mon Sep 17 00:00:00 2001 From: Sander Dijkhuis Date: Sun, 29 Jun 2025 20:41:22 +0200 Subject: [PATCH] ci: cross-platform release --- .github/workflows/ci.yaml | 76 ++++++++++++++++++++++++++++++++------- Cargo.toml | 2 +- demo.scala | 10 ++++-- 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2ecfa36..eea06da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,33 +19,83 @@ jobs: - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - run: cargo build --verbose - run: cargo test --verbose - release: if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest + strategy: + matrix: + include: + - os: ubuntu-latest + suffix: linux-x86_64 + target: x86_64-unknown-linux-gnu + ext: so + - os: macos-14 + suffix: macos-arm64 + target: aarch64-apple-darwin + ext: dylib + - os: macos-14 + suffix: ios-arm64 + target: aarch64-apple-ios + ext: a + - os: ubuntu-latest + suffix: android-arm64 + target: aarch64-linux-android + ext: so + runs-on: ${{ matrix.os }} needs: build_and_test steps: - uses: actions/checkout@v4 - run: rustup update stable && rustup default stable + - run: rustup target add ${{ matrix.target }} + - name: Configure NDK tool-chain + if: matrix.target == 'aarch64-linux-android' + shell: bash + run: | + NDK="$(ls -d "$ANDROID_HOME"/ndk/* | sort -V | tail -n1)" + echo "Using NDK at $NDK" + echo "NDK=$NDK" >> "$GITHUB_ENV" + echo "LLVM_BIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_ENV" + echo "$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_PATH" + echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang" >> "$GITHUB_ENV" - name: Extract version from tag id: extract run: echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" - - run: cargo build --release + - run: cargo build --release --target ${{ matrix.target }} - name: Archive and rename binary + shell: bash run: | - VERSION=${{ steps.extract.outputs.version }} - PLATFORM=linux-x86_64 - mkdir -p target/dist - cp target/release/libscal3.so target/dist/libscal3-$VERSION-$PLATFORM.so - - run: cargo publish --locked + VERSION=${{ steps.version.outputs.VERSION }} + SUFFIX=${{ matrix.suffix }} + EXT=${{ matrix.ext }} + mkdir -p dist + SRC="target/${{ matrix.target }}/release/libscal3.${EXT}" + cp "$SRC" "dist/libscal3-${VERSION}-${SUFFIX}.${EXT}" + - uses: actions/upload-artifact@v4 + with: + name: bin-${{ matrix.suffix }} + path: dist/* + publish: + if: startsWith(github.ref, 'refs/tags/v') + needs: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: { name: bin-linux-x86_64, path: dist/ } + - uses: actions/download-artifact@v4 + with: { name: bin-macos-arm64, path: dist/ } + - uses: actions/download-artifact@v4 + with: { name: bin-ios-arm64, path: dist/ } + - uses: actions/download-artifact@v4 + with: { name: bin-android-arm64, path: dist/ } + - name: Publish crate + run: cargo publish --locked env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Create GitHub Release with uploaded binary + - name: Create GitHub Release with all binaries run: | - VERSION=${{ steps.extract.outputs.version }} - PLATFORM=linux-x86_64 - gh release create "${{ steps.extract.outputs.version }}" target/dist/libscal3-$VERSION-$PLATFORM.so \ - --title "Release ${{ steps.extract.outputs.version }}" \ + VERSION=${GITHUB_REF##*/} + gh release create "$VERSION" dist/* \ + --title "Release $VERSION" \ --verify-tag env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index ba68aa6..56900d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "scal3" description = "Verify that systems operate under your sole control (prototype, patent pending)" license = "CC-BY-NC-4.0" -version = "0.3.0" +version = "0.3.1" edition = "2021" repository = "https://github.com/cleverbase/scal3" authors = ["Sander Dijkhuis "] diff --git a/demo.scala b/demo.scala index 590d8ee..20fdb85 100644 --- a/demo.scala +++ b/demo.scala @@ -13,11 +13,15 @@ import org.bouncycastle.jce.interfaces.{ECPrivateKey, ECPublicKey} import org.bouncycastle.jce.provider.BouncyCastleProvider import org.bouncycastle.jce.spec.ECPublicKeySpec +import java.nio.file.Paths import java.security.{KeyFactory, KeyPairGenerator, MessageDigest, SecureRandom, Security, Signature} import javax.crypto.{KeyAgreement, KeyGenerator, Mac, SecretKey} import scala.util.Try -val libraryPath = "target/release/libscal3.so" +val libraryPath = + val os = System.getProperty("os.name").toLowerCase + val extension = if os.contains("mac") then ".dylib" else ".so" + s"target/release/libscal3$extension" object authentication: private object impl: @@ -25,7 +29,9 @@ object authentication: def scal3_process(ip: Array[Byte], il: Int, op: PointerByReference, ol: IntByReference): Unit def scal3_free(ptr: Pointer, len: Int): Unit - private val library: AuthenticationLibrary = Native.load(libraryPath, classOf[AuthenticationLibrary]) + private val library: AuthenticationLibrary = + val path = Paths.get(libraryPath).toFile.getAbsolutePath + Native.load(path, classOf[AuthenticationLibrary]) given AdtEncodingStrategy = AdtEncodingStrategy.flat(typeMemberName = "type")