Skip to content

Commit a9ac62d

Browse files
committed
ci: cross-platform release
1 parent 942183c commit a9ac62d

3 files changed

Lines changed: 72 additions & 16 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,83 @@ jobs:
1919
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
2020
- run: cargo build --verbose
2121
- run: cargo test --verbose
22-
2322
release:
2423
if: startsWith(github.ref, 'refs/tags/v')
25-
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
include:
27+
- os: ubuntu-latest
28+
suffix: linux-x86_64
29+
target: x86_64-unknown-linux-gnu
30+
ext: so
31+
- os: macos-14
32+
suffix: macos-arm64
33+
target: aarch64-apple-darwin
34+
ext: dylib
35+
- os: macos-14
36+
suffix: ios-arm64
37+
target: aarch64-apple-ios
38+
ext: a
39+
- os: ubuntu-latest
40+
suffix: android-arm64
41+
target: aarch64-linux-android
42+
ext: so
43+
runs-on: ${{ matrix.os }}
2644
needs: build_and_test
2745
steps:
2846
- uses: actions/checkout@v4
2947
- run: rustup update stable && rustup default stable
48+
- run: rustup target add ${{ matrix.target }}
49+
- name: Configure NDK tool-chain
50+
if: matrix.target == 'aarch64-linux-android'
51+
shell: bash
52+
run: |
53+
NDK="$(ls -d "$ANDROID_HOME"/ndk/* | sort -V | tail -n1)"
54+
echo "Using NDK at $NDK"
55+
echo "NDK=$NDK" >> "$GITHUB_ENV"
56+
echo "LLVM_BIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_ENV"
57+
echo "$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin" >> "$GITHUB_PATH"
58+
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang" >> "$GITHUB_ENV"
3059
- name: Extract version from tag
3160
id: extract
3261
run: echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
33-
- run: cargo build --release
62+
- run: cargo build --release --target ${{ matrix.target }}
3463
- name: Archive and rename binary
64+
shell: bash
3565
run: |
36-
VERSION=${{ steps.extract.outputs.version }}
37-
PLATFORM=linux-x86_64
38-
mkdir -p target/dist
39-
cp target/release/libscal3.so target/dist/libscal3-$VERSION-$PLATFORM.so
40-
- run: cargo publish --locked
66+
VERSION=${{ steps.version.outputs.VERSION }}
67+
SUFFIX=${{ matrix.suffix }}
68+
EXT=${{ matrix.ext }}
69+
mkdir -p dist
70+
SRC="target/${{ matrix.target }}/release/libscal3.${EXT}"
71+
cp "$SRC" "dist/libscal3-${VERSION}-${SUFFIX}.${EXT}"
72+
- uses: actions/upload-artifact@v4
73+
with:
74+
name: bin-${{ matrix.suffix }}
75+
path: dist/*
76+
publish:
77+
if: startsWith(github.ref, 'refs/tags/v')
78+
needs: release
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v4
82+
- uses: actions/download-artifact@v4
83+
with: { name: bin-linux-x86_64, path: dist/ }
84+
- uses: actions/download-artifact@v4
85+
with: { name: bin-macos-arm64, path: dist/ }
86+
- uses: actions/download-artifact@v4
87+
with: { name: bin-ios-arm64, path: dist/ }
88+
- uses: actions/download-artifact@v4
89+
with: { name: bin-android-arm64, path: dist/ }
90+
- name: Publish crate
91+
run: cargo publish --locked
4192
env:
4293
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
43-
- name: Create GitHub Release with uploaded binary
94+
- name: Create GitHub Release with all binaries
4495
run: |
45-
VERSION=${{ steps.extract.outputs.version }}
46-
PLATFORM=linux-x86_64
47-
gh release create "${{ steps.extract.outputs.version }}" target/dist/libscal3-$VERSION-$PLATFORM.so \
48-
--title "Release ${{ steps.extract.outputs.version }}" \
96+
VERSION=${GITHUB_REF##*/}
97+
gh release create "$VERSION" dist/* \
98+
--title "Release $VERSION" \
4999
--verify-tag
50100
env:
51101
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "scal3"
33
description = "Verify that systems operate under your sole control (prototype, patent pending)"
44
license = "CC-BY-NC-4.0"
5-
version = "0.3.0"
5+
version = "0.3.1"
66
edition = "2021"
77
repository = "https://github.com/cleverbase/scal3"
88
authors = ["Sander Dijkhuis <sander.dijkhuis@cleverbase.com>"]

demo.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ import org.bouncycastle.jce.interfaces.{ECPrivateKey, ECPublicKey}
1313
import org.bouncycastle.jce.provider.BouncyCastleProvider
1414
import org.bouncycastle.jce.spec.ECPublicKeySpec
1515

16+
import java.nio.file.Paths
1617
import java.security.{KeyFactory, KeyPairGenerator, MessageDigest, SecureRandom, Security, Signature}
1718
import javax.crypto.{KeyAgreement, KeyGenerator, Mac, SecretKey}
1819
import scala.util.Try
1920

20-
val libraryPath = "target/release/libscal3.so"
21+
val libraryPath =
22+
val os = System.getProperty("os.name").toLowerCase
23+
val extension = if os.contains("mac") then ".dylib" else ".so"
24+
s"target/release/libscal3$extension"
2125

2226
object authentication:
2327
private object impl:
2428
private trait AuthenticationLibrary extends Library:
2529
def scal3_process(ip: Array[Byte], il: Int, op: PointerByReference, ol: IntByReference): Unit
2630
def scal3_free(ptr: Pointer, len: Int): Unit
2731

28-
private val library: AuthenticationLibrary = Native.load(libraryPath, classOf[AuthenticationLibrary])
32+
private val library: AuthenticationLibrary =
33+
val path = Paths.get(libraryPath).toFile.getAbsolutePath
34+
Native.load(path, classOf[AuthenticationLibrary])
2935

3036
given AdtEncodingStrategy = AdtEncodingStrategy.flat(typeMemberName = "type")
3137

0 commit comments

Comments
 (0)