diff --git a/.github/workflows/bound-ci-kt.yml b/.github/workflows/bound-ci-kt.yml deleted file mode 100644 index 800169fa..00000000 --- a/.github/workflows/bound-ci-kt.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Kotlin CI - -on: - push: - branches: - - main - pull_request: - -jobs: - aarch64-apple-darwin: - runs-on: macos-latest - name: Load shared library on aarch64-apple-darwin target - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'adopt' - java-version: '11' - - name: Run tests - run: | - cd bound/kt - mvn '-Dtest=SystemTargetTest#can load shared library' test - - x86_64-apple-darwin: - runs-on: macos-12 - name: Load shared library on x86_64-apple-darwin target - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'adopt' - java-version: '11' - - name: Run tests - run: | - cd bound/kt - mvn '-Dtest=SystemTargetTest#can load shared library' test - - x86_64-unknown-linux-gnu: - runs-on: ubuntu-latest - name: Load shared library on x86_64-unknown-linux-gnu target - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'adopt' - java-version: '11' - - name: Run tests - run: | - cd bound/kt - mvn '-Dtest=SystemTargetTest#can load shared library' test - - x86_64-unknown-linux-musl: - runs-on: ubuntu-latest - container: - image: alpine:latest - name: Load shared library on x86_64-unknown-linux-musl target - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: | - apk update - apk add openjdk11 - apk add maven - apk add bash - - name: Set JAVA_HOME - run: | - export JAVA_HOME=/usr/lib/jvm/java-11-openjdk - export PATH=$JAVA_HOME/bin:$PATH - - name: Change directory to bound/kt and run tests - run: | - cd bound/kt - mvn '-Dtest=SystemTargetTest#can load shared library' test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6469e664..badd56b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,18 @@ name: CI on: + workflow_dispatch: + inputs: + version: + description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0" will result in "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA.' + required: false + default: "0.0.0-SNAPSHOT" + workflow_call: + inputs: + version: + description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0" will result in "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA.' + required: true + type: string push: branches: - main @@ -13,7 +25,7 @@ env: WEB5_SDK_LOG_LEVEL: debug jobs: - build: + lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -21,39 +33,223 @@ jobs: uses: cashapp/activate-hermit@v1 with: cache: true - - name: Setup - run: just setup - - name: Build - run: just build + - name: Lint + run: just lint + test: strategy: matrix: - os: [ ubuntu-latest, macos-latest ] # TODO add back windows-latest https://github.com/TBD54566975/web5-rs/issues/189 - rust: [ stable, nightly ] + os: [ubuntu-latest, macos-latest] # TODO add back windows-latest https://github.com/TBD54566975/web5-rs/issues/189 + rust: [stable, nightly] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 with: - submodules: true + submodules: true - name: Init Hermit uses: cashapp/activate-hermit@v1 with: cache: true - - name: Setup - run: just setup - name: Test run: just test - lint: + + build_aarch64_apple_darwin: + runs-on: macos-latest + name: Build aarch64-apple-darwin target + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup toolchain install stable + - name: Run Build Script + run: | + cd bindings/web5_uniffi/libtargets/aarch64_apple_darwin + ./build + - name: Upload .dylib + uses: actions/upload-artifact@v4.0.0 + with: + name: aarch64-apple-darwin-dylib + path: bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib + + build_x86_64_apple_darwin: + runs-on: macos-12 + name: Build x86_64-apple-darwin target + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup toolchain install stable + - name: Run Build Script + run: | + cd bindings/web5_uniffi/libtargets/x86_64_apple_darwin + ./build + - name: Upload .dylib + uses: actions/upload-artifact@v4.0.0 + with: + name: x86_64-apple-darwin-dylib + path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib + + build_x86_64_unknown_linux_gnu: + runs-on: ubuntu-latest + name: Build x86_64-unknown-linux-gnu target + steps: + - uses: actions/checkout@v2 + - name: Run Build Script + run: | + cd bindings/web5_uniffi/libtargets/x86_64_unknown_linux_gnu + ./build + - name: Upload .so + uses: actions/upload-artifact@v4.0.0 + with: + name: x86_64-unknown-linux-gnu-so + path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so + + build_x86_64_unknown_linux_musl: + runs-on: ubuntu-latest + name: Build x86_64-unknown-linux-musl target + steps: + - uses: actions/checkout@v2 + - name: Run Build Script + run: | + cd bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl + ./build + - name: Upload .so + uses: actions/upload-artifact@v4.0.0 + with: + name: x86_64-unknown-linux-musl-so + path: bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so + + kotlin-build-test-deploy-snapshot: + needs: + - build_aarch64_apple_darwin + - build_x86_64_apple_darwin + - build_x86_64_unknown_linux_gnu + - build_x86_64_unknown_linux_musl runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + submodules: true + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: "adopt" + java-version: "11" + + # Cache Maven repo + - uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Resolve Snapshot Version + id: resolve_version + run: | + # Version resolution: use provided + if [ -n "${{ github.event.inputs.version }}" ]; then + if [[ "${{ github.event.inputs.version }}" != *-SNAPSHOT ]]; then + resolvedVersion="${{ github.event.inputs.version }}-SNAPSHOT" + else + resolvedVersion="${{ github.event.inputs.version }}" + fi + # Otherwise, construct a version for deployment in form X.Y.Z-commit-$shortSHA-SNAPSHOT + else + longSHA=$(git rev-parse --verify HEAD) + shortSHA=$(echo "${longSHA:0:7}") + resolvedVersion="commit-$shortSHA-SNAPSHOT" + echo "Requesting deployment as version: $resolvedVersion" + fi + + echo "Resolved SNAPSHOT Version: $resolvedVersion" + echo "resolved_version=$resolvedVersion" >> $GITHUB_OUTPUT + + # Package up the native binaries + #TODO Centralize this block as we re-use it via copy/paste right now + - name: Download MacOS aarch64 Native Library + uses: actions/download-artifact@v4.0.0 + with: + name: aarch64-apple-darwin-dylib + path: bound/kt/src/main/resources/ + - name: Download MacOS x86_64 Native Library + uses: actions/download-artifact@v4.0.0 + with: + name: x86_64-apple-darwin-dylib + path: bound/kt/src/main/resources/ + - name: Download Linux x86_64 GNU Native Library + uses: actions/download-artifact@v4.0.0 + with: + name: x86_64-unknown-linux-gnu-so + path: bound/kt/src/main/resources/ + - name: Download Linux x86_64 MUSL Native Library + uses: actions/download-artifact@v4.0.0 + with: + name: x86_64-unknown-linux-musl-so + path: bound/kt/src/main/resources/ + + - name: Deploy Snapshot / Verify + run: | + + # cd into the Kotlin project + cd bound/kt/ + + # Set newly resolved version in POM config + mvn \ + versions:set \ + --batch-mode \ + -DnewVersion=${{ steps.resolve_version.outputs.resolved_version }} + + # Only attempt to publish artifact if we have credentials + if [ -n "${{ secrets.ARTIFACTORY_PASSWORD }}" ]; then + # Maven deploy lifecycle will build, run tests, verify, sign, and deploy + mvn deploy --batch-mode --settings .maven_settings.xml -P sign-artifacts + else + # Otherwise, Maven verify lifecycle will build, run tests, and verify + mvn verify --batch-mode + fi + + env: + ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} + ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} + SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }} + SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }} + + - name: Upload Kotlin Test Vector Results + uses: actions/upload-artifact@v4.0.0 + with: + name: kotlin-test-results + path: bound/kt/target/surefire-reports/*.xml + + rust-test-vectors: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true - name: Init Hermit uses: cashapp/activate-hermit@v1 with: cache: true - name: Setup run: just setup - - name: Formatting - run: cargo fmt --check - - name: Lint - run: just lint + - name: Install Nextest + run: cargo install cargo-nextest + - name: Create nextest.toml + run: | + echo '[profile.ci.junit]' > nextest.toml + echo 'path = "junit.xml"' >> nextest.toml + echo 'store-success-output = true' >> nextest.toml + echo 'store-failure-output = true' >> nextest.toml + - name: Run Rust Tests + run: | + mkdir -p test-results + cargo nextest run --profile ci --config-file ./nextest.toml + - name: Modify testsuite name in XML for test runner consumption + run: | + sed -i '' 's/ + + + github + tbd-releases + ${env.TBD_RELEASE_GITHUB_PERSONAL_ACCESS_TOKEN} + + + tbd-oss-releases + ${env.ARTIFACTORY_USERNAME} + ${env.ARTIFACTORY_PASSWORD} + + + tbd-oss-snapshots + ${env.ARTIFACTORY_USERNAME} + ${env.ARTIFACTORY_PASSWORD} + + + ossrh-snapshots + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + ossrh-releases + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + diff --git a/bound/kt/pom.xml b/bound/kt/pom.xml index 52e70727..be2d5be5 100644 --- a/bound/kt/pom.xml +++ b/bound/kt/pom.xml @@ -1,73 +1,524 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + 4.0.0 - web5.sdk.core - web5-core-kt - 1.0-SNAPSHOT + + xyz.block + web5 + 0.0.0-main-SNAPSHOT + Web5 SDK for the JVM + https://developer.tbd.website + Web5 SDK for the JVM + 2024 + + + + scm:git:git://github.com/TBD54566975/web5-rs.git + + scm:git:https://github.com/TBD54566975/web5-rs.git + https://github.com/TBD54566975/web5-rs + HEAD + + + + + + TBD54566975 + Block, Inc. + releases@tbd.email + + + + + + github + https://github.com/TBD54566975/web5-rs/issues + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + - 1.9.22 + + UTF-8 + 11 - 1.8 - 1.8 + true + + github + + + + + 1.9.22 + 0.0.6 + + + 2.17.0 + 5.12.0 + 1.8.1 + + + 5.10.1 + + + + + + + + + + com.fasterxml.jackson.core + jackson-annotations + ${version.com.fasterxml.jackson} + + + com.fasterxml.jackson.core + jackson-core + ${version.com.fasterxml.jackson} + + + com.fasterxml.jackson.core + jackson-databind + ${version.com.fasterxml.jackson} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-cbor + ${version.com.fasterxml.jackson} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + ${version.com.fasterxml.jackson} + + + com.fasterxml.jackson.module + jackson-module-kotlin + ${version.com.fasterxml.jackson} + + + + net.java.dev.jna + jna + ${version.net.java.dev.jna} + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${version.kotlin} + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + ${version.org.jetbrains.kotlinx.kotlinx.coroutines.core} + + + + + org.junit.jupiter + junit-jupiter-api + ${version.org.junit.jupiter} + test + + + org.junit.jupiter + junit-jupiter-engine + ${version.org.junit.jupiter} + test + + + + + + + + + - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.module + jackson-module-kotlin net.java.dev.jna jna - 5.12.0 org.jetbrains.kotlinx kotlinx-coroutines-core - 1.8.0 - - - com.fasterxml.jackson.core - jackson-databind - 2.17.0 - - - com.fasterxml.jackson.core - jackson-core - 2.17.0 - - - com.fasterxml.jackson.core - jackson-annotations - 2.17.0 - com.fasterxml.jackson.module - jackson-module-kotlin - 2.17.0 + org.jetbrains.kotlin + kotlin-stdlib-jdk8 org.junit.jupiter junit-jupiter-api - 5.10.2 - test + src/main/kotlin src/test/kotlin + + + + io.github.martinvisser + kover-maven-plugin + ${version.io.github.martinvisser} + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + runtime + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + maven-surefire-plugin + 3.2.5 + + + *Test + *Tests + + false + + + + maven-jar-plugin + 3.0.2 + + + + true + + + + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + true + + + + org.simplify4u.plugins + sign-maven-plugin + 1.1.0 + + + + sign + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.0 + + + attach-sources + + jar + + + + + + maven-release-plugin + 3.0.1 + + true + true + v@{project.version} + [TBD Release Manager 🚀] + @{prefix} Setting version to: @{releaseLabel} + @{prefix} Setting next development version after: @{releaseLabel} + + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + com.github.ozsie + detekt-maven-plugin + 1.23.5 + + + verify + + check + + + config/detekt.yml + + + + + + io.gitlab.arturbosch.detekt + detekt-formatting + 1.23.5 + + + com.github.TBD54566975 + tbd-detekt-rules + 0.0.2 + + + + + io.github.martinvisser + kover-maven-plugin + ${version.io.github.martinvisser} + + + + + + 10 + LINE + COVERED_PERCENTAGE + + + 10 + BRANCH + COVERED_PERCENTAGE + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.2.0 + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${version.kotlin} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + ${kotlin.jvm.target} + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.maven.plugins + maven-assembly-plugin + + + org.apache.maven.plugins + maven-release-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-deploy-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + io.github.martinvisser + kover-maven-plugin + + + + org.jetbrains.dokka + dokka-maven-plugin + 1.9.20 + + + package + + javadocJar + + + + org.jetbrains.kotlin kotlin-maven-plugin - ${kotlin.version} compile @@ -133,4 +584,105 @@ + + + + sign-artifacts + + + + org.simplify4u.plugins + sign-maven-plugin + + + + + + + ossrh + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh-releases + https://s01.oss.sonatype.org/ + true + + + + + + + ossrh-snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots + + + + ossrh-releases + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + + false + tbd-oss-releases + TBD OSS Releases Repository + https://blockxyz.jfrog.io/artifactory/tbd-oss-releases-maven2 + default + + + false + tbd-oss-snapshots + TBD OSS Snapshots Repository + https://blockxyz.jfrog.io/artifactory/tbd-oss-snapshots-maven2 + default + + + + + + tbd-oss-thirdparty + tbd-oss-thirdparty + + true + + + false + + https://blockxyz.jfrog.io/artifactory/tbd-oss-thirdparty-maven2/ + + + tbd-oss-snapshots + tbd-oss-snapshots + + false + + + true + + https://blockxyz.jfrog.io/artifactory/tbd-oss-snapshots-maven2/ + + + + + + tbd-oss-thirdparty + tbd-oss-thirdparty + + true + + + false + + https://blockxyz.jfrog.io/artifactory/tbd-oss-thirdparty-maven2/ + + + diff --git a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt b/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt index 095f0360..f8fd6424 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/crypto/keys/InMemoryKeyManager.kt @@ -1,17 +1,12 @@ package web5.sdk.crypto.keys import web5.sdk.crypto.signers.Signer -import web5.sdk.rust.SystemTarget import web5.sdk.rust.InMemoryKeyManager as RustCoreInMemoryKeyManager /** * A class for managing cryptographic keys in-memory. */ class InMemoryKeyManager : KeyManager { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - private val rustCoreInMemoryKeyManager = RustCoreInMemoryKeyManager() /** diff --git a/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Ed25519Signer.kt b/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Ed25519Signer.kt index ca353ac9..48f99639 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Ed25519Signer.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/crypto/signers/Ed25519Signer.kt @@ -1,15 +1,9 @@ package web5.sdk.crypto.signers import web5.sdk.crypto.keys.Jwk -import web5.sdk.rust.SystemTarget - import web5.sdk.rust.Ed25519Signer as RustCoreEd25519Signer class Ed25519Signer : Signer { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - private val rustCoreSigner: RustCoreEd25519Signer constructor(privateKey: Jwk) { diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt index 09928ffc..178d52e5 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt @@ -2,8 +2,6 @@ package web5.sdk.dids import web5.sdk.crypto.signers.Signer import web5.sdk.crypto.keys.KeyManager -import web5.sdk.rust.SystemTarget - import web5.sdk.rust.BearerDid as RustCoreBearerDid /** @@ -14,10 +12,6 @@ import web5.sdk.rust.BearerDid as RustCoreBearerDid * @property document The DID document associated with this instance. */ class BearerDid { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - val did: Did val document: Document val keyManager: KeyManager diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/Document.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/Document.kt index 77c51546..abf3e20a 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/Document.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/Document.kt @@ -1,6 +1,5 @@ package web5.sdk.dids - import web5.sdk.rust.DocumentData as RustCoreDocumentData /** diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt index bc28c1eb..245d15e9 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/PortableDid.kt @@ -1,14 +1,9 @@ package web5.sdk.dids import web5.sdk.crypto.keys.Jwk -import web5.sdk.rust.SystemTarget import web5.sdk.rust.PortableDid as RustCorePortableDid class PortableDid { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - val didUri: String val document: Document val privateKeys: List diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/dht/DidDht.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/dht/DidDht.kt index c89e371d..dc9c4675 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/dht/DidDht.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/dht/DidDht.kt @@ -5,8 +5,6 @@ import web5.sdk.crypto.signers.Signer import web5.sdk.dids.Did import web5.sdk.dids.Document import web5.sdk.dids.ResolutionResult -import web5.sdk.rust.SystemTarget - import web5.sdk.rust.didDhtResolve as rustCoreDidDhtResolve import web5.sdk.rust.DidDht as RustCoreDidDht import web5.sdk.rust.Signer as RustCoreSigner @@ -18,10 +16,6 @@ import web5.sdk.rust.Signer as RustCoreSigner * @property document The DID document associated with this instance. */ class DidDht { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - val did: Did val document: Document diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/jwk/DidJwk.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/jwk/DidJwk.kt index 8cf95e57..3bdc034f 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/jwk/DidJwk.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/jwk/DidJwk.kt @@ -4,8 +4,6 @@ import web5.sdk.crypto.keys.Jwk import web5.sdk.dids.Did import web5.sdk.dids.Document import web5.sdk.dids.ResolutionResult -import web5.sdk.rust.SystemTarget - import web5.sdk.rust.didJwkResolve as rustCoreDidJwkResolve import web5.sdk.rust.DidJwk as RustCoreDidJwk @@ -16,10 +14,6 @@ import web5.sdk.rust.DidJwk as RustCoreDidJwk * @property document The DID document associated with this instance. */ class DidJwk { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - val did: Did val document: Document diff --git a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt index 6ec25ab1..d848c194 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt @@ -5,8 +5,6 @@ import web5.sdk.crypto.keys.Jwk import web5.sdk.dids.Did import web5.sdk.dids.Document import web5.sdk.dids.ResolutionResult -import web5.sdk.rust.SystemTarget - import web5.sdk.rust.didWebResolve as rustCoreDidWebResolve import web5.sdk.rust.DidWeb as RustCoreDidWeb @@ -17,10 +15,6 @@ import web5.sdk.rust.DidWeb as RustCoreDidWeb * @property document The DID document associated with this instance. */ class DidWeb { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - val did: Did val document: Document diff --git a/bound/kt/src/main/kotlin/web5/sdk/rust/SystemTarget.kt b/bound/kt/src/main/kotlin/web5/sdk/rust/SystemTarget.kt index fa28fdec..a26bcd74 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/rust/SystemTarget.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/rust/SystemTarget.kt @@ -2,67 +2,56 @@ package web5.sdk.rust import java.io.File -object SystemTarget { - @Volatile - private var isSet = false - private var gitCommitHash = "" - - fun set() { - val logLevel = System.getenv("WEB5_SDK_LOG_LEVEL")?.lowercase() - - val commitFile = File("target/git-commit-id.txt") - if (commitFile.exists()) { - gitCommitHash = commitFile.readText().trim() - } else { - println("Git commit hash not found.") - } - - fun log(message: String) { - if (logLevel == "debug") { - println("web5 sdk SystemArchitecture $gitCommitHash: $message") - } - } +internal val logLevel = System.getenv("WEB5_SDK_LOG_LEVEL")?.lowercase() +internal val gitCommitHash = run { + val commitFile = File("target/git-commit-id.txt") + if (commitFile.exists()) { + commitFile.readText().trim() + } else { + println("Git commit hash not found.") + "" + } +} - if (!isSet) { - synchronized(this) { - if (!isSet) { - val arch = System.getProperty("os.arch")?.lowercase() ?: throw Exception("Unable to get OS arch") - val name = System.getProperty("os.name")?.lowercase() ?: throw Exception("Unable to get OS name") +internal fun log(message: String) { + if (logLevel == "debug") { + println("web5 sdk SystemArchitecture $gitCommitHash: $message") + } +} - log("System architecture: $arch") - log("Operating system name: $name") +internal fun detectSystemTarget(): String { + val arch = System.getProperty("os.arch")?.lowercase() ?: throw Exception("Unable to get OS arch") + val name = System.getProperty("os.name")?.lowercase() ?: throw Exception("Unable to get OS name") - when { - name.contains("mac") && arch.contains("aarch64") -> - System.setProperty("uniffi.component.web5.libraryOverride", "web5_uniffi_aarch64_apple_darwin") + log("System architecture: $arch") + log("Operating system name: $name") - name.contains("mac") && arch.contains("x86_64") -> - System.setProperty("uniffi.component.web5.libraryOverride", "web5_uniffi_x86_64_apple_darwin") + when { + name.contains("mac") && arch.contains("aarch64") -> + return "web5_uniffi_aarch64_apple_darwin" - name.contains("linux") && arch.contains("amd64") -> { - val osRelease = File("/etc/os-release") - if (osRelease.exists()) { - val osReleaseContent = osRelease.readText().lowercase() - log("OS release content: $osReleaseContent") - when { - osReleaseContent.contains("ubuntu") -> - System.setProperty("uniffi.component.web5.libraryOverride", "web5_uniffi_x86_64_unknown_linux_gnu") + name.contains("mac") && arch.contains("x86_64") -> + return "web5_uniffi_x86_64_apple_darwin" - osReleaseContent.contains("alpine") -> - System.setProperty("uniffi.component.web5.libraryOverride", "web5_uniffi_x86_64_unknown_linux_musl") + name.contains("linux") && arch.contains("amd64") -> { + val osRelease = File("/etc/os-release") + if (osRelease.exists()) { + val osReleaseContent = osRelease.readText().lowercase() + log("OS release content: $osReleaseContent") + return when { + osReleaseContent.contains("ubuntu") -> + "web5_uniffi_x86_64_unknown_linux_gnu" - else -> throw Exception("Unsupported OS arch $osReleaseContent") - } - } else { - throw Exception("Linux /etc/os-release not found") - } - } + osReleaseContent.contains("alpine") -> + "web5_uniffi_x86_64_unknown_linux_musl" - else -> throw Exception("Unsupported OS arch $arch $name") - } - isSet = true + else -> throw Exception("Unsupported OS arch $osReleaseContent") } + } else { + throw Exception("Linux /etc/os-release not found") } } + + else -> throw Exception("Unsupported OS arch $arch $name") } } \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt b/bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt index 9ab044e0..ed39f91d 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt @@ -367,7 +367,7 @@ private fun findLibraryName(componentName: String): String { private inline fun loadIndirect( componentName: String ): Lib { - return Native.load(findLibraryName(componentName), Lib::class.java) + return Native.load(detectSystemTarget(), Lib::class.java) } // Define FFI callback types diff --git a/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt b/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt index 52d66835..1236585b 100644 --- a/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt +++ b/bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt @@ -2,7 +2,6 @@ package web5.sdk.vc.pex import com.fasterxml.jackson.annotation.JsonProperty import web5.sdk.Json -import web5.sdk.rust.SystemTarget import web5.sdk.rust.PresentationDefinition as RustCorePresentationDefinition data class PresentationDefinition( @@ -12,10 +11,6 @@ data class PresentationDefinition( @JsonProperty("input_descriptors") val inputDescriptors: List ) { - init { - SystemTarget.set() // ensure the sys arch is set for first-time loading - } - internal val rustCorePresentationDefinition = RustCorePresentationDefinition( Json.stringify(this) ) diff --git a/bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib b/bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib deleted file mode 100755 index 10d84835..00000000 Binary files a/bound/kt/src/main/resources/libweb5_uniffi_aarch64_apple_darwin.dylib and /dev/null differ diff --git a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib b/bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib deleted file mode 100755 index 5db2e256..00000000 Binary files a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_apple_darwin.dylib and /dev/null differ diff --git a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so b/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so deleted file mode 100755 index cc80cdec..00000000 Binary files a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_gnu.so and /dev/null differ diff --git a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so b/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so deleted file mode 100755 index ea9210b0..00000000 Binary files a/bound/kt/src/main/resources/libweb5_uniffi_x86_64_unknown_linux_musl.so and /dev/null differ diff --git a/bound/kt/src/test/kotlin/web5/sdk/rust/SystemTargetTest.kt b/bound/kt/src/test/kotlin/web5/sdk/rust/SystemTargetTest.kt index 5aece0f4..67d1e28e 100644 --- a/bound/kt/src/test/kotlin/web5/sdk/rust/SystemTargetTest.kt +++ b/bound/kt/src/test/kotlin/web5/sdk/rust/SystemTargetTest.kt @@ -6,8 +6,7 @@ class SystemTargetTest { @Test fun `can load shared library`() { System.setProperty("WEB5_SDK_LOG_LEVEL", "debug") - SystemTarget.set() UniffiLib.INSTANCE - println("Successfully loaded shared library for ${System.getProperty("uniffi.component.web5.libraryOverride")}") + println("Successfully loaded shared library for ${detectSystemTarget()}") } } \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index b51ea8b0..00000000 --- a/jitpack.yml +++ /dev/null @@ -1,7 +0,0 @@ -# jitpack.yml - -jdk: - - openjdk11 - -install: - - cd bound/kt && mvn install -DskipTests=true