diff --git a/.github/workflows/build-cli.yml b/.github/workflows/build-cli.yml index 76e8d317..fa0d1a02 100644 --- a/.github/workflows/build-cli.yml +++ b/.github/workflows/build-cli.yml @@ -12,8 +12,10 @@ jobs: name: Build aarch64-apple-darwin target steps: - uses: actions/checkout@v2 - - name: Install Rust - run: rustup toolchain install stable + - name: Install Rust 1.74.0 + run: rustup toolchain install 1.74.0 + - name: Set Rust 1.74.0 as default + run: rustup default 1.74.0 - name: Run Build Script run: | cd crates/web5_cli/build/aarch64_apple_darwin @@ -29,8 +31,10 @@ jobs: name: Build x86_64-apple-darwin target steps: - uses: actions/checkout@v2 - - name: Install Rust - run: rustup toolchain install stable + - name: Install Rust 1.74.0 + run: rustup toolchain install 1.74.0 + - name: Set Rust 1.74.0 as default + run: rustup default 1.74.0 - name: Run Build Script run: | cd crates/web5_cli/build/x86_64_apple_darwin diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a56d1cc..3d907ccc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,59 +4,26 @@ 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.' + description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA. Must end in "-SNAPSHOT".' required: false default: "0.0.0-SNAPSHOT" + push: + branches: + - main + pull_request: 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.' + description: 'Version of Kotlin binary to publish to TBD Artifactory. For example "1.0.0-SNAPSHOT". If not supplied, will default to "commit-$shortSHA-SNAPSHOT" where $shortSHA is the shortform commit SHA. Must end in "-SNAPSHOT".' required: true type: string - push: - branches: - - main - pull_request: env: CARGO_TERM_COLOR: always - # Make sure CI fails on all warnings, including Clippy lints RUSTFLAGS: "-Dwarnings" WEB5_SDK_LOG_LEVEL: debug jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Init Hermit - uses: cashapp/activate-hermit@v1 - with: - cache: true - - name: Lint - run: just lint - - msrv: - strategy: - matrix: - os: [ubuntu-latest] - rust: [stable] - runs-on: ${{ matrix.os }} - 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: Install MSRV - run: cargo install cargo-msrv - - name: MSRV - run: cargo msrv --path crates/web5/ verify - test: permissions: id-token: write @@ -193,7 +160,7 @@ jobs: - name: Build the library run: | cargo build --target x86_64-pc-windows-msvc --release --package web5_uniffi - mkdir -p bound/kt/src/main/resources/ + mkdir -p bound/kt/src/main/resources cp target/x86_64-pc-windows-msvc/release/web5_uniffi.dll bound/kt/src/main/resources/web5_uniffi_x86_64_pc_windows_msvc.dll - name: Upload .dll uses: actions/upload-artifact@v4.0.0 @@ -201,76 +168,39 @@ jobs: name: x86_64-pc-windows-msvc-dll path: bound/kt/src/main/resources/web5_uniffi_x86_64_pc_windows_msvc.dll - kotlin-acceptance-testing: - permissions: - id-token: write - needs: - - build_aarch64_apple_darwin - - build_x86_64_apple_darwin - - build_x86_64_unknown_linux_gnu - - build_x86_64_unknown_linux_musl - - build_x86_64_pc_windows_msvc - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, macos-12, windows-latest] + lint: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Init Hermit + uses: cashapp/activate-hermit@v1 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- - # 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.1.7 - with: - name: aarch64-apple-darwin-dylib - path: bound/kt/src/main/resources/ - - name: Download MacOS x86_64 Native Library - uses: actions/download-artifact@v4.1.7 - 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.1.7 - 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.1.7 - with: - name: x86_64-unknown-linux-musl-so - path: bound/kt/src/main/resources/ - - name: Download Windows x86_64 MSVC Native Library - uses: actions/download-artifact@v4.1.7 - with: - name: x86_64-pc-windows-msvc-dll - path: bound/kt/src/main/resources/ - - name: Run Maven Tests - run: | - cd bound/kt/ - mvn test --batch-mode - - name: Upload test coverage to Codecov - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 #v4.5.0 + cache: true + - name: Setup + run: just setup + - name: Lint + run: just lint + + rust-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Init Hermit + uses: cashapp/activate-hermit@v1 with: - use_oidc: true - working-directory: bound/kt - files: target/kover/test.ic + cache: true + - name: Setup + run: just setup + - name: Test + run: just test - kotlin-deploy-snapshot: + kotlin-build-test-deploy-snapshot: needs: - - kotlin-acceptance-testing + - build_aarch64_apple_darwin + - build_x86_64_apple_darwin + - build_x86_64_unknown_linux_gnu + - build_x86_64_unknown_linux_musl + - build_x86_64_pc_windows_msvc runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -366,22 +296,69 @@ jobs: SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }} SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }} - - name: Upload Kotlin Test Vector Results + - name: Upload Kotlin Test Results uses: actions/upload-artifact@v4.0.0 with: name: kotlin-test-results path: bound/kt/target/surefire-reports/*.xml + - name: Upload web5 w/ Dependencies JAR + uses: actions/upload-artifact@v4.0.0 + with: + name: web5-with-dependencies-jar + path: bound/kt/target/*-with-dependencies.jar + + kotlin-acceptance-test: + needs: kotlin-build-test-deploy-snapshot + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, macos-12, windows-latest ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: "adopt" + java-version: "11" + - name: Download web5 w/ Dependencies JAR + uses: actions/download-artifact@v4.1.7 + with: + name: web5-with-dependencies-jar + path: tests/jvm + - name: Run Acceptance Tests (Non-Windows) + if: matrix.os != 'windows-latest' + shell: bash + run: | + cd tests/jvm + mv *-with-dependencies.jar web5-with-dependencies.jar + javac Web5AcceptanceTest.java -cp web5-with-dependencies.jar + java -classpath web5-with-dependencies.jar:. Web5AcceptanceTest + - name: Run Acceptance Tests (Windows) + if: matrix.os == 'windows-latest' + shell: cmd + run: | + cd tests/jvm + ren *-with-dependencies.jar web5-with-dependencies.jar + javac Web5AcceptanceTest.java -cp web5-with-dependencies.jar + java -classpath web5-with-dependencies.jar;. Web5AcceptanceTest + rust-test-vectors: runs-on: macos-latest steps: - uses: actions/checkout@v4 with: submodules: true - - name: Install Rust 1.75.0 - run: rustup toolchain install 1.75.0 - - name: Set Rust 1.75.0 as default - run: rustup default 1.75.0 + - name: Init Hermit + uses: cashapp/activate-hermit@v1 + with: + cache: true + - name: Setup + run: just setup + - name: Install latest stable Rust + run: rustup install stable && rustup default stable - name: Install Nextest run: cargo install cargo-nextest - name: Create nextest.toml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b5845762..e8ab42bc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,13 +1,28 @@ -name: Build release artifacts +name: Release on: - release: - types: [created] + workflow_dispatch: + inputs: + version: + description: 'Version of web5 to release and publish to TBD Artifactory and Maven Central. For example "1.0.0" or "1.3.7-beta-2". Required. Must not end in "-SNAPSHOT".' + required: true + +env: + WEB5_SDK_LOG_LEVEL: debug jobs: - build_cli_aarch64-apple-darwin: + + run-ci: + # This will run CI and also publish the Kotlin release to the TBD Artifactory repo manager + name: Run CI + uses: TBD54566975/web5-rs/.github/workflows/ci.yml@main + secrets: inherit + with: + version: ${{ github.event.inputs.version }} + + build-cli-aarch64-apple-darwin: runs-on: macos-latest - name: aarch64-apple-darwin + name: Build CLI (aarch64-apple-darwin) steps: - uses: actions/checkout@v2 - name: Install Rust @@ -16,15 +31,15 @@ jobs: run: | cargo build --target aarch64-apple-darwin --release --package web5_cli cp -v target/aarch64-apple-darwin/release/web5_cli web5_cli-aarch64-apple-darwin - - name: upload release asset - uses: AButler/upload-release-assets@v3.0 + - name: Upload compiled binary + uses: actions/upload-artifact@v4.0.0 with: - files: web5_cli-aarch64-apple-darwin - repo-token: ${{ secrets.GITHUB_TOKEN }} + name: web5_cli-aarch64-apple-darwin + path: web5_cli-aarch64-apple-darwin - build_cli_x86_64_apple_darwin: + build-cli-x86_64_apple_darwin: runs-on: macos-12 - name: x86_64-apple-darwin + name: Build CLI (x86_64-apple-darwin) steps: - uses: actions/checkout@v2 - name: Install Rust @@ -33,30 +48,30 @@ jobs: run: | cargo build --target x86_64-apple-darwin --release --package web5_cli cp -v target/x86_64-apple-darwin/release/web5_cli web5_cli-x86_64-apple-darwin - - name: upload release asset - uses: AButler/upload-release-assets@v3.0 + - name: Upload compiled binary + uses: actions/upload-artifact@v4.0.0 with: - files: web5_cli-x86_64-apple-darwin - repo-token: ${{ secrets.GITHUB_TOKEN }} + name: web5_cli-x86_64-apple-darwin + path: web5_cli-x86_64-apple-darwin - build_cli_x86_64_unknown_linux_gnu: + build-cli-x86_64_unknown_linux_gnu: runs-on: ubuntu-latest - name: x86_64-unknown-linux-gnu + name: Build CLI (x86_64-unknown-linux-gnu) steps: - uses: actions/checkout@v2 - name: cargo build run: | cargo build --target x86_64-unknown-linux-gnu --release --package web5_cli cp -v target/x86_64-unknown-linux-gnu/release/web5_cli web5_cli-x86_64-unknown-linux-gnu - - name: upload release asset - uses: AButler/upload-release-assets@v3.0 + - name: Upload compiled binary + uses: actions/upload-artifact@v4.0.0 with: - files: web5_cli-x86_64-unknown-linux-gnu - repo-token: ${{ secrets.GITHUB_TOKEN }} + name: web5_cli-x86_64-unknown-linux-gnu + path: web5_cli-x86_64-unknown-linux-gnu - build_cli_x86_64_unknown_linux_musl: + build-cli-x86_64_unknown_linux_musl: runs-on: ubuntu-latest - name: x86_64-unknown-linux-musl + name: Build CLI (x86_64-unknown-linux-musl) steps: - uses: actions/checkout@v2 - name: Run Build Script @@ -65,11 +80,240 @@ jobs: ./build popd cp target/x86_64-unknown-linux-musl/release/web5_cli web5_cli-x86_64-unknown-linux-musl - - name: upload release asset - uses: AButler/upload-release-assets@v3.0 + - name: Upload compiled binary + uses: actions/upload-artifact@v4.0.0 + with: + name: web5_cli-x86_64-unknown-linux-musl + path: web5_cli-x86_64-unknown-linux-musl + + git-tag: + runs-on: ubuntu-latest + needs: + - run-ci + - build-cli-aarch64-apple-darwin + - build-cli-x86_64_apple_darwin + - build-cli-x86_64_unknown_linux_gnu + - build-cli-x86_64_unknown_linux_musl + outputs: + RELEASE_TAG: ${{ steps.set-version-and-tag.outputs.RELEASE_TAG }} + RELEASE_VERSION: ${{ steps.set-version-and-tag.outputs.RELEASE_VERSION }} + + name: Create Git Tag + steps: + - id: checkout + uses: actions/checkout@v4 + with: + submodules: true + token: ${{ secrets.TBD_RELEASE_GITHUB_PERSONAL_ACCESS_TOKEN }} + + # Used in writing commits in the release process + - id: set-git-config + name: Set Git Config + run: | + git config user.name "tbd-releases" + git config user.email "releases@tbd.email" + + # Cache Maven repo + - id: cache + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - id: set-version-and-tag + name: Set version of Kotlin and commit + run: | + set -exuo pipefail + + # cd into the Kotlin project + cd bound/kt/ + + # Get the required provided version + version=${{ github.event.inputs.version }} + # Precondition check; do not allow this to proceed if a version ending in "-SNAPSHOT" was specified + if [[ $version =~ -SNAPSHOT$ ]]; then + echo "Error: The version for release must not end with \"-SNAPSHOT\": $version" + exit 1 + fi + + # Get the existing version from the POM and set it to the nextVersion, keeping the POM effectively versionless + nextVersion=$(grep -oPm1 "(?<=)[^<]+" pom.xml) + if [[ -z $nextVersion ]]; then + echo "Error: Could not find a version in the pom.xml" + exit 1 + fi + + echo "Version to be released: $version" + echo "Setting next development version back to original in pom.xml: $nextVersion" + + # Set newly resolved version in POM config + mvn \ + versions:set \ + --batch-mode \ + -DnewVersion=$version + + # Commit + git add -Av + git commit -m "[TBD Release Manager 🚀] Setting version to: $version" + tagName=v$version + git tag -a $tagName -m "Tag version: $tagName" # We tag with a prefix of "v" + + # Make the version and tag name available to subsequent jobs as an output param + echo "RELEASE_TAG=$tagName" >> "$GITHUB_OUTPUT" + echo "RELEASE_VERSION=$version" >> "$GITHUB_OUTPUT" + cat $GITHUB_OUTPUT + + # Set the next development version and commit and push + mvn \ + versions:set \ + --batch-mode \ + -DnewVersion=$nextVersion + git add -Av + git commit -m "[TBD Release Manager 🚀] Setting next development version after $version to: $nextVersion" + git push origin "${GITHUB_REF#refs/heads/}" + git push origin $tagName + + kotlin-release-to-tbd-artifactory-and-maven-central: + name: Release Kotlin to Maven Central + needs: git-tag + runs-on: ubuntu-latest + steps: + + # Check out the tag we created above + - uses: actions/checkout@v4 + with: + submodules: true + ref: ${{ needs.git-tag.outputs.RELEASE_TAG }} # Check out the tag we created above + + # Set up JDK + - 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- + + # 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.1.7 + with: + name: aarch64-apple-darwin-dylib + path: bound/kt/src/main/resources/ + - name: Download MacOS x86_64 Native Library + uses: actions/download-artifact@v4.1.7 + 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.1.7 + 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.1.7 with: - files: web5_cli-x86_64-unknown-linux-musl - repo-token: ${{ secrets.GITHUB_TOKEN }} + name: x86_64-unknown-linux-musl-so + path: bound/kt/src/main/resources/ + - name: Download Windows x86_64 MSVC Native Library + uses: actions/download-artifact@v4.1.7 + with: + name: x86_64-pc-windows-msvc-dll + path: bound/kt/src/main/resources/ + + - name: Deploy Release Version of Kotlin Project to Maven Central + run: | + # cd into the Kotlin project + cd bound/kt/ + + # Publish to Sonatype + # Precondition check: Only attempt to publish artifact if we have credentials + if [ -n "${{ secrets.SONATYPE_PASSWORD }}" ]; then + # Maven deploy lifecycle will build, run tests, verify, sign, and deploy + mvn deploy --batch-mode \ + --settings .maven_settings.xml \ + -P ossrh,sign-artifacts + else + echo "Error: No credentials" + exit 1 + fi + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }} + SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }} + + - name: Create GitHub Release + uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4 final release + id: release + with: + tag_name: "v${{ github.event.inputs.version }}" + release_name: "v${{ github.event.inputs.version }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Download MacOS x86_64 Native Library + uses: actions/download-artifact@v4.1.7 + 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.1.7 + 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.1.7 + with: + name: x86_64-unknown-linux-musl-so + path: bound/kt/src/main/resources/ + - name: Download Windows x86_64 MSVC Native Library + uses: actions/download-artifact@v4.1.7 + with: + name: x86_64-pc-windows-msvc-dll + path: bound/kt/src/main/resources/ + + - name: Download web5_cli-aarch64-apple-darwin + uses: actions/download-artifact@v4.1.7 + with: + name: web5_cli-aarch64-apple-darwin + path: "." + - name: Download web5_cli-x86_64-apple-darwin + uses: actions/download-artifact@v4.1.7 + with: + name: web5_cli-x86_64-apple-darwin + path: "." + - name: Download web5_cli-x86_64-unknown-linux-gnu + uses: actions/download-artifact@v4.1.7 + with: + name: web5_cli-x86_64-unknown-linux-gnu + path: "." + - name: Download web5_cli-x86_64-unknown-linux-musl + uses: actions/download-artifact@v4.1.7 + with: + name: web5_cli-x86_64-unknown-linux-musl + path: "." + - name: Upload release assets + run: | + set -ex + for asset in web5_cli-aarch64-apple-darwin web5_cli-x86_64-apple-darwin web5_cli-x86_64-unknown-linux-gnu web5_cli-x86_64-unknown-linux-musl; do + curl -L -f -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + "https://uploads.github.com/repos/TBD54566975/web5-rs/releases/${{ steps.release.outputs.id }}/assets?name=${asset}" \ + --data-binary "@${asset}" + done kotlin-docs: permissions: @@ -92,7 +336,9 @@ jobs: ${{ runner.os }}-maven- - run: mvn dokka:dokka working-directory: bound/kt - - run: mkdir _site && mv bound/kt/target/dokka _site/kt + - run: mkdir -p _site/kt/${GITHUB_REF_NAME} && mv bound/kt/target/dokka/* _site/kt/${GITHUB_REF_NAME} + env: + GITHUB_REF_NAME: ${{ github.ref_name }} - name: Setup Pages uses: actions/configure-pages@v5 - name: Upload artifact diff --git a/bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl/Dockerfile b/bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl/Dockerfile index 3c8708e5..51552785 100644 --- a/bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl/Dockerfile +++ b/bindings/web5_uniffi/libtargets/x86_64_unknown_linux_musl/Dockerfile @@ -4,7 +4,6 @@ FROM --platform=linux/amd64 alpine:latest RUN apk add --no-cache \ build-base \ musl-dev \ - openssl-dev \ linux-headers \ rustup \ libgcc \ @@ -13,21 +12,12 @@ RUN apk add --no-cache \ git \ perl \ make \ - bash \ - openssl-libs-static + bash # Install rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --no-modify-path --default-toolchain 1.74.0 ENV PATH="/root/.cargo/bin:${PATH}" -# Set environment variables to ensure vendored OpenSSL is used -ENV OPENSSL_STATIC=1 -ENV OPENSSL_LIB_DIR=/usr/lib -ENV OPENSSL_INCLUDE_DIR=/usr/include -ENV PKG_CONFIG_ALLOW_CROSS=1 -ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig -ENV LIBRARY_PATH="/usr/lib:/usr/local/lib" - # Copy the source code to the container WORKDIR /usr/src/myapp COPY Cargo.toml ./ @@ -44,7 +34,7 @@ RUN cargo build --release --package web5_uniffi # Compile as a dynamic lib (.so) from our static lib (.a) while keeping dependencies self-contained RUN gcc -shared -o target/release/libweb5_uniffi.so -Wl,--whole-archive \ target/release/libweb5_uniffi.a -Wl,--no-whole-archive -static-libgcc \ - -L/usr/lib -lssl -lcrypto -Wl,-Bdynamic -fPIC + -Wl,-Bdynamic -fPIC # Set the entrypoint, so that we can `docker cp` the build output CMD tail -f /dev/null diff --git a/bound/kt/pom.xml.versionsBackup b/bound/kt/pom.xml.versionsBackup new file mode 100644 index 00000000..9dc03a2d --- /dev/null +++ b/bound/kt/pom.xml.versionsBackup @@ -0,0 +1,674 @@ + + + + 4.0.0 + + + 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 + + + + + + + UTF-8 + + 11 + true + + github + + + + + 1.9.22 + 0.0.6 + + + 2.17.0 + 5.12.0 + 1.8.1 + + + 5.10.1 + 4.12.0 + 9.39.3 + + + + + + + + + + + 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 + + + com.squareup.okhttp3 + mockwebserver + ${version.com.squareup.okhttp3.mockwebserver} + test + + + com.nimbusds + nimbus-jose-jwt + ${version.com.nimbusds.nimbus-jose-jwt} + test + + + + + + + + + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + net.java.dev.jna + jna + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + + + org.junit.jupiter + junit-jupiter-api + + + com.squareup.okhttp3 + mockwebserver + + + com.nimbusds + nimbus-jose-jwt + + + + + + 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 + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + ${kotlin.jvm.target} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + + + + + + + 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/crates/web5/Cargo.toml b/crates/web5/Cargo.toml index 149acd63..4ba39048 100644 --- a/crates/web5/Cargo.toml +++ b/crates/web5/Cargo.toml @@ -21,7 +21,6 @@ k256 = { version = "0.13.3", features = ["ecdsa", "jwk"] } tokio = "1.38.0" rand = { workspace = true } regex = "1.10.4" -reqwest = { version = "0.12.4", features = ["json", "blocking"] } serde = { workspace = true } serde_json = { workspace = true } sha2 = "0.10.8" @@ -33,6 +32,10 @@ x25519-dalek = { version = "2.0.1", features = ["getrandom", "static_secrets"] } zbase32 = "0.1.2" lazy_static = "1.5.0" flate2 = "1.0.33" +rustls = { version = "0.23.13", default-features = false, features = ["std", "tls12"] } +rustls-native-certs = "0.8.0" +# TODO temporary +reqwest = { version = "0.12.4", features = ["json", "blocking"] } [dev-dependencies] mockito = "1.5.0" diff --git a/crates/web5/src/credentials/create.rs b/crates/web5/src/credentials/create.rs index 785d1adc..784de976 100644 --- a/crates/web5/src/credentials/create.rs +++ b/crates/web5/src/credentials/create.rs @@ -558,7 +558,7 @@ mod tests { #[test] fn test_schema_resolve_network_issue() { - let url = "invalid url".to_string(); // here + let url = "http://local".to_string(); // here let result = create_vc( issuer(), diff --git a/crates/web5/src/http.rs b/crates/web5/src/http.rs index 020365a9..0b812c8e 100644 --- a/crates/web5/src/http.rs +++ b/crates/web5/src/http.rs @@ -136,3 +136,224 @@ impl HttpClient for ForeignEmptyHttpClient { Err(Web5Error::Http("http client not set".to_string())) } } + +// use crate::errors::{Result, Web5Error}; +// use rustls::pki_types::ServerName; +// use rustls::{ClientConfig, ClientConnection, RootCertStore, StreamOwned}; +// use rustls_native_certs::load_native_certs; +// use serde::de::DeserializeOwned; +// use std::collections::HashMap; +// use std::io::{Read, Write}; +// use std::net::TcpStream; +// use std::sync::Arc; +// use url::Url; + +// pub struct HttpResponse { +// pub status_code: u16, +// #[allow(dead_code)] +// pub headers: HashMap, +// pub body: Vec, +// } + +// struct Destination { +// pub host: String, +// pub path: String, +// pub port: u16, +// pub schema: String, +// } + +// fn parse_destination(url: &str) -> Result { +// let parsed_url = +// Url::parse(url).map_err(|err| Web5Error::Http(format!("failed to parse url {}", err)))?; + +// let host = parsed_url +// .host_str() +// .ok_or_else(|| Web5Error::Http(format!("url must have a host: {}", url)))?; + +// let path = if parsed_url.path().is_empty() { +// "/".to_string() +// } else { +// parsed_url.path().to_string() +// }; + +// let port = parsed_url +// .port_or_known_default() +// .ok_or_else(|| Web5Error::Http("unable to determine port".to_string()))?; + +// let schema = parsed_url.scheme().to_string(); + +// Ok(Destination { +// host: host.to_string(), +// path, +// port, +// schema, +// }) +// } + +// fn transmit(destination: &Destination, request: &[u8]) -> Result> { +// let mut buffer = Vec::new(); + +// if destination.schema == "https" { +// // HTTPS connection + +// // Create a RootCertStore and load the root certificates from rustls_native_certs +// let mut root_store = RootCertStore::empty(); +// for cert in load_native_certs().unwrap() { +// root_store.add(cert).unwrap(); +// } + +// // Build the ClientConfig using the root certificates and disabling client auth +// let config = ClientConfig::builder() +// .with_root_certificates(root_store) +// .with_no_client_auth(); + +// let rc_config = Arc::new(config); // Arc allows sharing the config + +// // Make the TCP connection to the server +// let stream = TcpStream::connect((&destination.host[..], destination.port)) +// .map_err(|err| Web5Error::Network(format!("failed to connect to host: {}", err)))?; + +// // Convert the server name to the expected type for TLS validation +// let server_name = ServerName::try_from(destination.host.clone()) +// .map_err(|_| Web5Error::Http("invalid DNS name".to_string()))?; + +// // Create the TLS connection +// let client = ClientConnection::new(rc_config, server_name) +// .map_err(|err| Web5Error::Network(err.to_string()))?; +// let mut tls_stream = StreamOwned::new(client, stream); + +// // Write the request over the TLS stream +// tls_stream +// .write_all(request) +// .map_err(|err| Web5Error::Network(err.to_string()))?; + +// // Read the response into the buffer +// tls_stream +// .read_to_end(&mut buffer) +// .map_err(|err| Web5Error::Network(err.to_string()))?; +// } else { +// // HTTP connection +// let mut stream = TcpStream::connect((&destination.host[..], destination.port)) +// .map_err(|err| Web5Error::Network(format!("failed to connect to host: {}", err)))?; + +// stream +// .write_all(request) +// .map_err(|err| Web5Error::Network(err.to_string()))?; + +// stream +// .read_to_end(&mut buffer) +// .map_err(|err| Web5Error::Network(err.to_string()))?; +// } + +// Ok(buffer) +// } + +// fn parse_response(response_bytes: &[u8]) -> Result { +// // Find the position of the first \r\n\r\n, which separates headers and body +// let header_end = response_bytes +// .windows(4) +// .position(|window| window == b"\r\n\r\n") +// .ok_or_else(|| Web5Error::Http("invalid HTTP response format".to_string()))?; + +// // Extract the headers section (before the \r\n\r\n) +// let header_part = &response_bytes[..header_end]; + +// // Convert the header part to a string (since headers are ASCII/UTF-8 compliant) +// let header_str = String::from_utf8_lossy(header_part); + +// // Parse the status line (first line in the headers) +// let mut header_lines = header_str.lines(); +// let status_line = header_lines +// .next() +// .ok_or_else(|| Web5Error::Http("missing status line".to_string()))?; + +// let status_parts: Vec<&str> = status_line.split_whitespace().collect(); +// if status_parts.len() < 3 { +// return Err(Web5Error::Http("invalid status line format".to_string())); +// } + +// let status_code = status_parts[1] +// .parse::() +// .map_err(|_| Web5Error::Http("invalid status code".to_string()))?; + +// // Parse headers into a HashMap +// let mut headers = HashMap::new(); +// for line in header_lines { +// if let Some((key, value)) = line.split_once(": ") { +// headers.insert(key.to_string(), value.to_string()); +// } +// } + +// // The body is the part after the \r\n\r\n separator +// let body = response_bytes[header_end + 4..].to_vec(); + +// Ok(HttpResponse { +// status_code, +// headers, +// body, +// }) +// } + +// pub fn get_json(url: &str) -> Result { +// let destination = parse_destination(url)?; +// let request = format!( +// "GET {} HTTP/1.1\r\n\ +// Host: {}\r\n\ +// Connection: close\r\n\ +// Accept: application/json\r\n\r\n", +// destination.path, destination.host +// ); +// let response_bytes = transmit(&destination, request.as_bytes())?; +// let response = parse_response(&response_bytes)?; + +// if !(200..300).contains(&response.status_code) { +// return Err(Web5Error::Http(format!( +// "non-successful response code {}", +// response.status_code +// ))); +// } + +// let json_value = serde_json::from_slice::(&response.body) +// .map_err(|err| Web5Error::Http(format!("unable to parse json response body {}", err)))?; + +// Ok(json_value) +// } + +// pub fn get(url: &str) -> Result { +// let destination = parse_destination(url)?; + +// let request = format!( +// "GET {} HTTP/1.1\r\n\ +// Host: {}\r\n\ +// Connection: close\r\n\ +// Accept: application/octet-stream\r\n\r\n", +// destination.path, destination.host +// ); + +// let response_bytes = transmit(&destination, request.as_bytes())?; + +// parse_response(&response_bytes) +// } + +// pub fn put(url: &str, body: &[u8]) -> Result { +// let destination = parse_destination(url)?; + +// let request = format!( +// "PUT {} HTTP/1.1\r\n\ +// Host: {}\r\n\ +// Connection: close\r\n\ +// Content-Length: {}\r\n\ +// Content-Type: application/octet-stream\r\n\r\n", +// destination.path, +// destination.host, +// body.len() +// ); + +// // Concatenate the request headers and the body to form the full request +// let mut request_with_body = request.into_bytes(); +// request_with_body.extend_from_slice(body); + +// let response_bytes = transmit(&destination, &request_with_body)?; + +// parse_response(&response_bytes) +// } diff --git a/crates/web5_cli/build/x86_64_unknown_linux_musl/Dockerfile b/crates/web5_cli/build/x86_64_unknown_linux_musl/Dockerfile index d08797c6..55ffaff3 100644 --- a/crates/web5_cli/build/x86_64_unknown_linux_musl/Dockerfile +++ b/crates/web5_cli/build/x86_64_unknown_linux_musl/Dockerfile @@ -4,7 +4,6 @@ FROM --platform=linux/amd64 alpine:latest RUN apk add --no-cache \ build-base \ musl-dev \ - openssl-dev \ linux-headers \ rustup \ libgcc \ @@ -13,21 +12,12 @@ RUN apk add --no-cache \ git \ perl \ make \ - bash \ - openssl-libs-static + bash # Install rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --no-modify-path --default-toolchain 1.74.0 ENV PATH="/root/.cargo/bin:${PATH}" -# Set environment variables to ensure vendored OpenSSL is used -ENV OPENSSL_STATIC=1 -ENV OPENSSL_LIB_DIR=/usr/lib -ENV OPENSSL_INCLUDE_DIR=/usr/include -ENV PKG_CONFIG_ALLOW_CROSS=1 -ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig -ENV LIBRARY_PATH="/usr/lib:/usr/local/lib" - # Copy the source code to the container WORKDIR /usr/src/myapp COPY Cargo.toml ./ diff --git a/tests/jvm/Web5AcceptanceTest.java b/tests/jvm/Web5AcceptanceTest.java new file mode 100644 index 00000000..f58c347b --- /dev/null +++ b/tests/jvm/Web5AcceptanceTest.java @@ -0,0 +1,18 @@ +import web5.sdk.rust.UniffiLib; + +/** + * A simple main class to act as an acceptance smoke test for the Kotlin + * web5 binary. + * + * See README.md in this folder for usage and purpose. + */ +public class Web5AcceptanceTest { + + public static void main(String... args) { + System.setProperty("WEB5_SDK_LOG_LEVEL", "debug"); + UniffiLib.Companion.getINSTANCE$web5(); + System.out.println( + "Successfully loaded shared library for " + + System.getProperty("uniffi.component.web5.libraryOverride")); + } +}