diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml new file mode 100644 index 000000000..0a2b5cbb9 --- /dev/null +++ b/.github/actions/setup-build/action.yml @@ -0,0 +1,39 @@ +name: Setup Build +description: > + Checkout repositories and build dependencies + +runs: + using: composite + steps: + - name: Checkout tools + uses: actions/checkout@v4 + with: + path: 'aws-kotlin-repo-tools' + repository: 'awslabs/aws-kotlin-repo-tools' + sparse-checkout: | + .github + + - name: Checkout aws-crt-kotlin + uses: ./aws-kotlin-repo-tools/.github/actions/checkout-head + with: + # checkout aws-crt-kotlin as a sibling which will automatically make it an included build + path: 'aws-crt-kotlin' + repository: 'awslabs/aws-crt-kotlin' + + # Cache the Kotlin/Native toolchain based on the input Kotlin version from version catalog + # see https://kotlinlang.org/docs/native-improving-compilation-time.html + - name: Cache Kotlin Native toolchain + uses: actions/cache@v4 + with: + path: | + ~/.konan + key: ${{ runner.os }}-konan-${{ hashFiles('gradle/libs.versions.toml') }} + restore-keys: | + ${{ runner.os }}-konan- + + - name: Configure JDK + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: 17 + cache: 'gradle' \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..45b7b9cac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,192 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + workflow_dispatch: + +# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed +concurrency: + group: ci-pr-${{ github.ref }} + cancel-in-progress: true + +env: + RUN: ${{ github.run_id }}-${{ github.run_number }} + GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false" + +jobs: + jvm: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # we build with a specific JDK version but source/target compatibility should ensure the jar is usable by + # the target versions we want to support + java-version: + - 8 + - 11 + - 17 + - 21 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Build and Test on JVM + working-directory: ./smithy-kotlin + shell: bash + run: | + ./gradlew -Paws.kotlin.native=false -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace + + # macos-14 build and test for targets: jvm, macoArm64, iosSimulatorArm64, watchosSimulatorArm65, tvosSimulatorArm64 + # macos-13 build and test for targets: jvm, macoX64, iosX64, tvosX64, watchosX64 + macos: + strategy: + fail-fast: false + matrix: + os: [macos-14, macos-13] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Build and Test on Apple platforms + working-directory: ./smithy-kotlin + shell: bash + run: | + # FIXME K2. Re-enable warnings as errors after this warning is removed: https://youtrack.jetbrains.com/issue/KT-68532 + # echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties + ./gradlew apiCheck + ./gradlew -Paws.sdk.kotlin.crt.disableCrossCompile=true build + + - name: Save Test Reports + if: failure() + uses: actions/upload-artifact@v3 + with: + name: test-reports-${{ matrix.os }} + path: '**/build/reports' + + # build and test for targets: jvm, linuxX64 + # cross compile for: linuxX64, linuxArm64 + # TODO - add mingw as cross compile target + linux: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Configure CRT Docker Images + run: | + ./aws-crt-kotlin/docker-images/build-all.sh + + - name: Build and Test on Linux with Cross-Compile + working-directory: ./smithy-kotlin + shell: bash + run: | + # FIXME K2. Re-enable warnings as errors after this warning is removed: https://youtrack.jetbrains.com/issue/KT-68532 + # echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties + ./gradlew apiCheck + ./gradlew build + + - name: Save Test Reports + if: failure() + uses: actions/upload-artifact@v3 + with: + name: test-reports-${{ matrix.os }} + path: '**/build/reports' + + # windows JVM + windows: + runs-on: windows-2022 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Build and Test on Windows JVM + working-directory: ./smithy-kotlin + run: | + ./gradlew apiCheck + ./gradlew -P"aws.sdk.kotlin.crt.disableCrossCompile"=true build + + - name: Save Test Reports + if: failure() + uses: actions/upload-artifact@v4 + with: + name: test-reports-windows + path: '**/build/reports' + + protocol-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Test + working-directory: ./smithy-kotlin + shell: bash + run: | + ./gradlew -Paws.kotlin.native=false publishToMavenLocal + ./gradlew -Paws.kotlin.native=false testAllProtocols + + downstream: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + path: 'smithy-kotlin' + + - name: Setup build + uses: ./smithy-kotlin/.github/actions/setup-build + + - name: Checkout aws-sdk-kotlin + uses: ./aws-kotlin-repo-tools/.github/actions/checkout-head + with: + # smithy-kotlin is checked out as a sibling dir which will automatically make it an included build + path: 'aws-sdk-kotlin' + repository: 'awslabs/aws-sdk-kotlin' + + - name: Build and Test aws-sdk-kotlin downstream + working-directory: ./smithy-kotlin + run: | + # TODO - JVM only + cd $GITHUB_WORKSPACE/smithy-kotlin + ./gradlew --parallel -Paws.kotlin.native=false publishToMavenLocal + SMITHY_KOTLIN_RUNTIME_VERSION=$(grep sdkVersion= gradle.properties | cut -d = -f 2) + SMITHY_KOTLIN_CODEGEN_VERSION=$(grep codegenVersion= gradle.properties | cut -d = -f 2) + cd $GITHUB_WORKSPACE/aws-sdk-kotlin + # replace smithy-kotlin-runtime-version and smithy-kotlin-codegen-version to be + # whatever we are testing such that the protocol test projects don't fail with a + # version that doesn't exist locally or in maven central. Otherwise the generated + # protocol test projects will use whatever the SDK thinks the version of + # smithy-kotlin should be + sed -i "s/smithy-kotlin-runtime-version = .*$/smithy-kotlin-runtime-version = \"$SMITHY_KOTLIN_RUNTIME_VERSION\"/" gradle/libs.versions.toml + sed -i "s/smithy-kotlin-codegen-version = .*$/smithy-kotlin-codegen-version = \"$SMITHY_KOTLIN_CODEGEN_VERSION\"/" gradle/libs.versions.toml + ./gradlew --parallel -Paws.kotlin.native=false publishToMavenLocal + ./gradlew -Paws.kotlin.native=false test jvmTest + ./gradlew -Paws.kotlin.native=false testAllProtocols \ No newline at end of file diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml deleted file mode 100644 index 9b0dc1c88..000000000 --- a/.github/workflows/continuous-integration.yml +++ /dev/null @@ -1,135 +0,0 @@ -name: CI - -on: - push: - branches: [ main ] - pull_request: - workflow_dispatch: - -# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed -concurrency: - group: ci-pr-${{ github.ref }} - cancel-in-progress: true - -env: - RUN: ${{ github.run_id }}-${{ github.run_number }} - GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false" - -jobs: - jvm: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - # we build with a specific JDK version but source/target compatibility should ensure the jar is usable by - # the target versions we want to support - java-version: - - 8 - - 11 - - 17 - - 21 - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - name: Configure JDK - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 17 - cache: 'gradle' - - name: Test - shell: bash - run: | - ./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace - - all-platforms: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - name: Configure JDK - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 17 - cache: 'gradle' - - name: Test - shell: bash - run: | - # FIXME K2. Re-enable warnings as errors after this warning is removed: https://youtrack.jetbrains.com/issue/KT-68532 - # echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties - ./gradlew apiCheck - ./gradlew test jvmTest - - name: Save Test Reports - if: failure() - uses: actions/upload-artifact@v3 - with: - name: test-reports-${{ matrix.os }} - path: '**/build/reports' - - protocol-tests: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - name: Configure JDK - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 17 - cache: 'gradle' - - name: Test - shell: bash - run: | - ./gradlew publishToMavenLocal - ./gradlew testAllProtocols - - downstream: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - with: - path: 'smithy-kotlin' - - name: Checkout tools - uses: actions/checkout@v4 - with: - path: 'aws-kotlin-repo-tools' - repository: 'awslabs/aws-kotlin-repo-tools' - ref: '0.2.3' - sparse-checkout: | - .github - - name: Checkout aws-sdk-kotlin - uses: ./aws-kotlin-repo-tools/.github/actions/checkout-head - with: - # smithy-kotlin is checked out as a sibling dir which will automatically make it an included build - path: 'aws-sdk-kotlin' - repository: 'awslabs/aws-sdk-kotlin' - - name: Configure JDK - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: 17 - cache: 'gradle' - - name: Build and Test aws-sdk-kotlin downstream - run: | - # TODO - JVM only - cd $GITHUB_WORKSPACE/smithy-kotlin - ./gradlew --parallel publishToMavenLocal - SMITHY_KOTLIN_RUNTIME_VERSION=$(grep sdkVersion= gradle.properties | cut -d = -f 2) - SMITHY_KOTLIN_CODEGEN_VERSION=$(grep codegenVersion= gradle.properties | cut -d = -f 2) - cd $GITHUB_WORKSPACE/aws-sdk-kotlin - # replace smithy-kotlin-runtime-version and smithy-kotlin-codegen-version to be - # whatever we are testing such that the protocol test projects don't fail with a - # version that doesn't exist locally or in maven central. Otherwise the generated - # protocol test projects will use whatever the SDK thinks the version of - # smithy-kotlin should be - sed -i "s/smithy-kotlin-runtime-version = .*$/smithy-kotlin-runtime-version = \"$SMITHY_KOTLIN_RUNTIME_VERSION\"/" gradle/libs.versions.toml - sed -i "s/smithy-kotlin-codegen-version = .*$/smithy-kotlin-codegen-version = \"$SMITHY_KOTLIN_CODEGEN_VERSION\"/" gradle/libs.versions.toml - ./gradlew --parallel publishToMavenLocal - ./gradlew test jvmTest - ./gradlew testAllProtocols \ No newline at end of file diff --git a/.gitignore b/.gitignore index 225fe6070..a776ae3ff 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ gradle-app.setting # MacOS .DS_Store + +*.cinteropLibraries.json diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index eb5170e4c..f52b1a56c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin-version = "2.0.21" dokka-version = "1.9.10" -aws-kotlin-repo-tools-version = "0.4.13" +aws-kotlin-repo-tools-version = "0.4.15-kn" # libs coroutines-version = "1.9.0" @@ -91,6 +91,7 @@ docker-transport-zerodep = { module = "com.github.docker-java:docker-java-transp ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor-version" } ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor-version" } ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor-version" } +ktor-server-core = { module = "io.ktor:ktor-server-core", version.ref = "ktor-version" } ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor-version" } ktor-server-jetty-jakarta = { module = "io.ktor:ktor-server-jetty-jakarta", version.ref = "ktor-version" } ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor-version" } diff --git a/runtime/auth/aws-signing-crt/build.gradle.kts b/runtime/auth/aws-signing-crt/build.gradle.kts index 4c6728276..5dddb3f45 100644 --- a/runtime/auth/aws-signing-crt/build.gradle.kts +++ b/runtime/auth/aws-signing-crt/build.gradle.kts @@ -8,14 +8,14 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.auth.awssigning.crt" kotlin { sourceSets { - jvmMain { + jvmAndNativeMain { dependencies { api(project(":runtime:auth:aws-signing-common")) implementation(project(":runtime:crt-util")) } } - jvmTest { + jvmAndNativeTest { dependencies { implementation(project(":runtime:auth:aws-signing-tests")) } diff --git a/runtime/auth/aws-signing-crt/jvm/src/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsSigner.kt b/runtime/auth/aws-signing-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsSigner.kt similarity index 100% rename from runtime/auth/aws-signing-crt/jvm/src/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsSigner.kt rename to runtime/auth/aws-signing-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsSigner.kt diff --git a/runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedByteReadChannelTest.kt b/runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedByteReadChannelTest.kt similarity index 100% rename from runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedByteReadChannelTest.kt rename to runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedByteReadChannelTest.kt diff --git a/runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedSourceTest.kt b/runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedSourceTest.kt similarity index 100% rename from runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedSourceTest.kt rename to runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtAwsChunkedSourceTest.kt diff --git a/runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtBasicSigningTest.kt b/runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtBasicSigningTest.kt similarity index 100% rename from runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtBasicSigningTest.kt rename to runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtBasicSigningTest.kt diff --git a/runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt b/runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt similarity index 100% rename from runtime/auth/aws-signing-crt/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt rename to runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt diff --git a/runtime/auth/aws-signing-default/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultAwsChunkedSourceTest.kt b/runtime/auth/aws-signing-default/common/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultAwsChunkedSourceTest.kt similarity index 100% rename from runtime/auth/aws-signing-default/jvm/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultAwsChunkedSourceTest.kt rename to runtime/auth/aws-signing-default/common/test/aws/smithy/kotlin/runtime/auth/awssigning/DefaultAwsChunkedSourceTest.kt diff --git a/runtime/auth/aws-signing-tests/jvm/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/AwsChunkedSourceTestBase.kt b/runtime/auth/aws-signing-tests/common/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/AwsChunkedSourceTestBase.kt similarity index 100% rename from runtime/auth/aws-signing-tests/jvm/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/AwsChunkedSourceTestBase.kt rename to runtime/auth/aws-signing-tests/common/src/aws/smithy/kotlin/runtime/auth/awssigning/tests/AwsChunkedSourceTestBase.kt diff --git a/runtime/auth/http-auth-aws/build.gradle.kts b/runtime/auth/http-auth-aws/build.gradle.kts index dfcc0c7da..e6c823652 100644 --- a/runtime/auth/http-auth-aws/build.gradle.kts +++ b/runtime/auth/http-auth-aws/build.gradle.kts @@ -26,7 +26,7 @@ kotlin { } } - jvmTest { + jvmAndNativeTest { dependencies { implementation(project(":runtime:auth:aws-signing-crt")) } diff --git a/runtime/auth/http-auth-aws/jvm/test/AwsHttpSignerTestBaseJvm.kt b/runtime/auth/http-auth-aws/jvmAndNative/test/AwsHttpSignerTestBaseJvmAndNative.kt similarity index 100% rename from runtime/auth/http-auth-aws/jvm/test/AwsHttpSignerTestBaseJvm.kt rename to runtime/auth/http-auth-aws/jvmAndNative/test/AwsHttpSignerTestBaseJvmAndNative.kt diff --git a/runtime/build.gradle.kts b/runtime/build.gradle.kts index d02316058..0d1f151e3 100644 --- a/runtime/build.gradle.kts +++ b/runtime/build.gradle.kts @@ -14,6 +14,9 @@ plugins { val sdkVersion: String by project +// Apply KMP configuration from build plugin +configureKmpTargets() + // capture locally - scope issue with custom KMP plugin val libraries = libs @@ -60,7 +63,7 @@ subprojects { kotlin.sourceSets.all { // Allow subprojects to use internal APIs // See https://kotlinlang.org/docs/reference/opt-in-requirements.html#opting-in-to-using-api - listOf("kotlin.RequiresOptIn").forEach { languageSettings.optIn(it) } + listOf("kotlin.RequiresOptIn", "kotlinx.cinterop.ExperimentalForeignApi").forEach { languageSettings.optIn(it) } } dependencies { diff --git a/runtime/crt-util/build.gradle.kts b/runtime/crt-util/build.gradle.kts index ddc57d11a..f14fb5c43 100644 --- a/runtime/crt-util/build.gradle.kts +++ b/runtime/crt-util/build.gradle.kts @@ -11,14 +11,22 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.crt" kotlin { sourceSets { - jvmMain { + commonMain { + dependencies { + api(project(":runtime:runtime-core")) + api(libs.crt.kotlin) + } + } + + jvmAndNativeMain { dependencies { api(project(":runtime:runtime-core")) api(libs.crt.kotlin) api(project(":runtime:protocol:http")) } } - jvmTest { + + jvmAndNativeTest { dependencies { implementation(libs.kotlinx.coroutines.test) } diff --git a/runtime/crt-util/common/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt b/runtime/crt-util/common/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt new file mode 100644 index 000000000..e08f9f0d1 --- /dev/null +++ b/runtime/crt-util/common/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt @@ -0,0 +1,14 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package aws.smithy.kotlin.runtime.crt + +import aws.sdk.kotlin.crt.io.MutableBuffer +import aws.smithy.kotlin.runtime.io.SdkBuffer + +/** + * write as much of [outgoing] to [dest] as possible + */ +internal expect fun transferRequestBody(outgoing: SdkBuffer, dest: MutableBuffer): Int diff --git a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamJvm.kt b/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamJvm.kt new file mode 100644 index 000000000..7703ef589 --- /dev/null +++ b/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamJvm.kt @@ -0,0 +1,11 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package aws.smithy.kotlin.runtime.crt + +import aws.sdk.kotlin.crt.io.MutableBuffer +import aws.smithy.kotlin.runtime.io.SdkBuffer + +internal actual fun transferRequestBody(outgoing: SdkBuffer, dest: MutableBuffer) = outgoing.read(dest.buffer) diff --git a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/Http.kt b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/Http.kt similarity index 100% rename from runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/Http.kt rename to runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/Http.kt diff --git a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt similarity index 96% rename from runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt rename to runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt index 4a3e60980..040ba8545 100644 --- a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt +++ b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStream.kt @@ -18,11 +18,6 @@ import kotlin.time.Duration.Companion.milliseconds private val POLLING_DELAY = 100.milliseconds -/** - * write as much of [outgoing] to [dest] as possible - */ -internal fun transferRequestBody(outgoing: SdkBuffer, dest: MutableBuffer) = outgoing.read(dest.buffer) - /** * Implement's [HttpRequestBodyStream] which proxies an SDK request body channel [SdkByteReadChannel] */ diff --git a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt similarity index 100% rename from runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt rename to runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt diff --git a/runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStream.kt b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStream.kt similarity index 100% rename from runtime/crt-util/jvm/src/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStream.kt rename to runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStream.kt diff --git a/runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/HttpTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/HttpTest.kt similarity index 100% rename from runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/HttpTest.kt rename to runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/HttpTest.kt diff --git a/runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt similarity index 100% rename from runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt rename to runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt diff --git a/runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt similarity index 100% rename from runtime/crt-util/jvm/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt rename to runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt diff --git a/runtime/crt-util/native/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamNative.kt b/runtime/crt-util/native/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamNative.kt new file mode 100644 index 000000000..09eb88dfd --- /dev/null +++ b/runtime/crt-util/native/src/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamNative.kt @@ -0,0 +1,10 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.smithy.kotlin.runtime.crt + +import aws.sdk.kotlin.crt.io.MutableBuffer +import aws.smithy.kotlin.runtime.io.SdkBuffer + +internal actual fun transferRequestBody(outgoing: SdkBuffer, dest: MutableBuffer): Int = TODO("Not yet implemented") diff --git a/runtime/observability/telemetry-api/jvm/src/aws/smithy/kotlin/runtime/telemetry/context/TelemetryContextElementJVM.kt b/runtime/observability/telemetry-api/jvm/src/aws/smithy/kotlin/runtime/telemetry/context/TelemetryContextElementJVM.kt index d6680f0d6..e8548ad31 100644 --- a/runtime/observability/telemetry-api/jvm/src/aws/smithy/kotlin/runtime/telemetry/context/TelemetryContextElementJVM.kt +++ b/runtime/observability/telemetry-api/jvm/src/aws/smithy/kotlin/runtime/telemetry/context/TelemetryContextElementJVM.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.ThreadContextElement import kotlin.coroutines.AbstractCoroutineContextElement import kotlin.coroutines.CoroutineContext +// FIXME Move to jvmAndNative when https://github.com/Kotlin/kotlinx.coroutines/issues/3326 is implemented @InternalApi public actual class TelemetryContextElement public actual constructor( public actual val context: Context, diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/build.gradle.kts b/runtime/protocol/http-client-engines/http-client-engine-crt/build.gradle.kts index d2f411578..b3a3f5507 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/build.gradle.kts +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/build.gradle.kts @@ -11,18 +11,18 @@ apply(plugin = "org.jetbrains.kotlinx.atomicfu") kotlin { sourceSets { - jvmMain { + jvmAndNativeMain { dependencies { api(project(":runtime:runtime-core")) api(project(":runtime:protocol:http-client")) implementation(project(":runtime:crt-util")) implementation(project(":runtime:observability:telemetry-api")) - implementation(libs.kotlinx.coroutines.core) + api(libs.crt.kotlin) } } - jvmTest { + jvmAndNativeTest { dependencies { implementation(project(":runtime:testing")) implementation(project(":runtime:protocol:http-test")) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngineConfig.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngineConfig.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngineConfig.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngineConfig.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt similarity index 97% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt index 7ad57fa1a..96efc44f7 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt @@ -25,6 +25,7 @@ import kotlinx.coroutines.yield import kotlin.test.Test import kotlin.time.Duration.Companion.seconds +// FIXME This test implements [TestWithLocalServer] which is JVM-only. class AsyncStressTest : TestWithLocalServer() { override val server = embeddedServer(CIO, serverPort) { diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestConversionTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestConversionTest.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestConversionTest.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestConversionTest.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt similarity index 100% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt similarity index 97% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt index 9bbc35c4c..005d577f7 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandlerTest.kt @@ -21,15 +21,17 @@ import kotlinx.coroutines.yield import kotlin.test.* class SdkStreamResponseHandlerTest { - private class MockHttpStream(override val responseStatusCode: Int) : HttpStream { var closed: Boolean = false override fun activate() {} + override suspend fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean) { + TODO("Not yet implemented") + } + override fun close() { closed = true } override fun incrementWindow(size: Int) {} - override fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean) {} } private class MockHttpClientConnection : HttpClientConnection { diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt similarity index 97% rename from runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt rename to runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt index a7637b675..d0e2e2cf9 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt @@ -22,7 +22,7 @@ class SendChunkedBodyTest { closed = true } override fun incrementWindow(size: Int) {} - override fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean) { + override suspend fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean) { numChunksWritten += 1 } } diff --git a/runtime/protocol/http-client-engines/http-client-engine-okhttp/build.gradle.kts b/runtime/protocol/http-client-engines/http-client-engine-okhttp/build.gradle.kts index 3e5d13938..0e12749c0 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-okhttp/build.gradle.kts +++ b/runtime/protocol/http-client-engines/http-client-engine-okhttp/build.gradle.kts @@ -9,7 +9,7 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.http.engine.okhttp" kotlin { sourceSets { - commonMain { + jvmMain { dependencies { implementation(project(":runtime:runtime-core")) api(project(":runtime:protocol:http-client")) diff --git a/runtime/protocol/http-client-engines/http-client-engine-okhttp4/build.gradle.kts b/runtime/protocol/http-client-engines/http-client-engine-okhttp4/build.gradle.kts index 26145b406..f6b3f1266 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-okhttp4/build.gradle.kts +++ b/runtime/protocol/http-client-engines/http-client-engine-okhttp4/build.gradle.kts @@ -9,7 +9,7 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.http.engine.okhttp4" kotlin { sourceSets { - commonMain { + jvmMain { dependencies { api(project(":runtime:protocol:http-client")) implementation(project(":runtime:protocol:http-client-engines:http-client-engine-okhttp")) diff --git a/runtime/protocol/http-client-engines/test-suite/build.gradle.kts b/runtime/protocol/http-client-engines/test-suite/build.gradle.kts index ece9d6e10..065872fe7 100644 --- a/runtime/protocol/http-client-engines/test-suite/build.gradle.kts +++ b/runtime/protocol/http-client-engines/test-suite/build.gradle.kts @@ -38,6 +38,7 @@ kotlin { jvmAndNativeMain { dependencies { + implementation(libs.ktor.server.core) implementation(libs.kotlinx.coroutines.test) } } diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestJVM.kt b/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestJVM.kt index fa091c1f0..6f0d9182d 100644 --- a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestJVM.kt +++ b/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestJVM.kt @@ -11,6 +11,7 @@ import aws.smithy.kotlin.runtime.http.engine.okhttp4.OkHttp4Engine import aws.smithy.kotlin.runtime.net.url.Url internal actual fun engineFactories(): List = + // FIXME Move DefaultHttpEngine and CrtHttpEngine to `jvmAndNative` listOf( TestEngineFactory("DefaultHttpEngine", ::DefaultHttpEngine), TestEngineFactory("CrtHttpEngine") { CrtHttpEngine(it) }, diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/TestServers.kt b/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/TestServers.kt index 1bc9d6e9e..24c001d5b 100644 --- a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/TestServers.kt +++ b/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/util/TestServers.kt @@ -12,7 +12,6 @@ import aws.smithy.kotlin.runtime.http.test.suite.tlsTests import aws.smithy.kotlin.runtime.http.test.suite.uploadTests import io.ktor.server.application.* import io.ktor.server.engine.* -import io.ktor.server.jetty.* import io.ktor.server.jetty.jakarta.Jetty import io.ktor.server.jetty.jakarta.JettyApplicationEngineBase import redirectTests diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt similarity index 88% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt index fad3e7fec..b3b482fa2 100644 --- a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt +++ b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Concurrency.kt @@ -8,6 +8,7 @@ package aws.smithy.kotlin.runtime.http.test.suite import io.ktor.server.application.* import io.ktor.server.response.* import io.ktor.server.routing.* +import io.ktor.utils.io.writeFully import kotlinx.coroutines.delay import kotlin.time.Duration.Companion.milliseconds @@ -24,10 +25,10 @@ internal fun Application.concurrentTests() { route("slow") { get { val chunk = ByteArray(256) { it.toByte() } - call.respondOutputStream { + call.respondBytesWriter { repeat(10) { delay(200.milliseconds) - write(chunk) + writeFully(chunk) } } } diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Connections.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Connections.kt similarity index 100% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Connections.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Connections.kt diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt similarity index 84% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt index dd495edf2..7cd8ba93e 100644 --- a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt +++ b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt @@ -6,6 +6,9 @@ package aws.smithy.kotlin.runtime.http.test.suite import aws.smithy.kotlin.runtime.hashing.sha256 +import aws.smithy.kotlin.runtime.io.GzipSdkSource +import aws.smithy.kotlin.runtime.io.readToByteArray +import aws.smithy.kotlin.runtime.io.source import aws.smithy.kotlin.runtime.text.encoding.encodeToHex import io.ktor.http.* import io.ktor.server.application.* @@ -13,8 +16,6 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.utils.io.* import kotlinx.coroutines.delay -import java.io.ByteArrayOutputStream -import java.util.zip.GZIPOutputStream import kotlin.random.Random internal const val DOWNLOAD_SIZE = 16L * 1024 * 1024 // 16MB @@ -55,15 +56,7 @@ internal fun Application.downloadTests() { get("/gzipped") { val uncompressed = ByteArray(1024) { it.toByte() } - val compressed = ByteArrayOutputStream().use { baStream -> - GZIPOutputStream(baStream).use { gzStream -> - gzStream.write(uncompressed) - gzStream.flush() - } - baStream.flush() - baStream.toByteArray() - } - + val compressed = GzipSdkSource(uncompressed.source()).readToByteArray() call.response.header("Content-Encoding", "gzip") call.respondBytes(compressed) } diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Header.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Header.kt similarity index 100% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Header.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Header.kt diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Redirects.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Redirects.kt similarity index 100% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Redirects.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Redirects.kt diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Tls.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Tls.kt similarity index 100% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Tls.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Tls.kt diff --git a/runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Uploads.kt b/runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Uploads.kt similarity index 100% rename from runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Uploads.kt rename to runtime/protocol/http-client-engines/test-suite/jvmAndNative/src/aws/smithy/kotlin/runtime/http/test/suite/Uploads.kt diff --git a/runtime/protocol/http-client-engines/test-suite/native/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestNative.kt b/runtime/protocol/http-client-engines/test-suite/native/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestNative.kt index bfb3ff18f..05f82f63d 100644 --- a/runtime/protocol/http-client-engines/test-suite/native/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestNative.kt +++ b/runtime/protocol/http-client-engines/test-suite/native/src/aws/smithy/kotlin/runtime/http/test/util/AbstractEngineTestNative.kt @@ -7,7 +7,7 @@ package aws.smithy.kotlin.runtime.http.test.util import aws.smithy.kotlin.runtime.net.url.Url -// FIXME add engines to test +// FIXME Move CRT and Default engine tests to `jvmAndNative` internal actual fun engineFactories(): List = listOf() diff --git a/runtime/protocol/http-client/native/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestNative.kt b/runtime/protocol/http-client/native/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestNative.kt index 74cbd525c..7d55f1834 100644 --- a/runtime/protocol/http-client/native/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestNative.kt +++ b/runtime/protocol/http-client/native/test/aws/smithy/kotlin/runtime/http/interceptors/RequestCompressionInterceptorTestNative.kt @@ -5,5 +5,5 @@ package aws.smithy.kotlin.runtime.http.interceptors internal actual fun decompressGzipBytes(bytes: ByteArray): ByteArray { - TODO("Not yet implemented") + TODO("Not yet implemented. Can we write a pure Kotlin implementation?") } diff --git a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipTestUtils.kt b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipTestUtils.kt index 109844814..511fe59f4 100644 --- a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipTestUtils.kt +++ b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/io/GzipTestUtils.kt @@ -5,6 +5,6 @@ package aws.smithy.kotlin.runtime.io /** - * Decompresses a byte array compressed using the gzip format + * Decompresses a [ByteArray] compressed using the gzip format */ internal expect fun decompressGzipBytes(bytes: ByteArray): ByteArray diff --git a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/io/SdkByteReadChannelJVM.kt b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/io/SdkByteReadChannelJVM.kt index 5afef0174..2986b998a 100644 --- a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/io/SdkByteReadChannelJVM.kt +++ b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/io/SdkByteReadChannelJVM.kt @@ -6,7 +6,6 @@ package aws.smithy.kotlin.runtime.io import kotlinx.coroutines.runBlocking import java.io.InputStream -import java.util.* /** * Create a blocking [InputStream] that blocks everytime the channel suspends at [SdkByteReadChannel.read] diff --git a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/time/InstantJVM.kt b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/time/InstantJVM.kt index b90a57de8..e1a17cd8c 100644 --- a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/time/InstantJVM.kt +++ b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/time/InstantJVM.kt @@ -26,6 +26,7 @@ import kotlin.time.toKotlinDuration import java.time.Duration as jtDuration import java.time.Instant as jtInstant +// FIXME Consider making this multiplatform (`common`) using kotlinx.datetime public actual class Instant(internal val value: jtInstant) : Comparable { public actual val epochSeconds: Long get() = value.epochSecond diff --git a/runtime/runtime-core/jvm/test/aws/smithy/kotlin/runtime/io/GzipTestUtilsJVM.kt b/runtime/runtime-core/jvm/test/aws/smithy/kotlin/runtime/io/GzipTestUtilsJVM.kt index 1d79af810..1d879aa92 100644 --- a/runtime/runtime-core/jvm/test/aws/smithy/kotlin/runtime/io/GzipTestUtilsJVM.kt +++ b/runtime/runtime-core/jvm/test/aws/smithy/kotlin/runtime/io/GzipTestUtilsJVM.kt @@ -7,7 +7,7 @@ package aws.smithy.kotlin.runtime.io import java.util.zip.GZIPInputStream /** - * Decompresses a byte array compressed using the gzip format + * Decompresses a [ByteArray] compressed using the gzip format */ internal actual fun decompressGzipBytes(bytes: ByteArray): ByteArray = GZIPInputStream(bytes.inputStream()).use { it.readBytes() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/time/InstantNative.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/time/InstantNative.kt index 00bc92f2f..56e4b8d3b 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/time/InstantNative.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/time/InstantNative.kt @@ -7,6 +7,7 @@ package aws.smithy.kotlin.runtime.time import kotlin.time.Duration +// FIXME Consider making this multiplatform (`common`) using kotlinx.datetime public actual class Instant : Comparable { actual override fun compareTo(other: Instant): Int { TODO("Not yet implemented") diff --git a/settings.gradle.kts b/settings.gradle.kts index 414df686a..ac7f398bc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,6 +26,39 @@ dependencyResolutionManagement { } } +// Set up a sibling directory aws-crt-kotlin as a composite build, if it exists. +// Allows overrides via local.properties: +// compositeProjects=~/repos/aws-crt-kotlin,/tmp/some/other/thing,../../another/project +val compositeProjectList = try { + val localProperties = java.util.Properties().also { + it.load(File(rootProject.projectDir, "local.properties").inputStream()) + } + val compositeProjects = localProperties.getProperty("compositeProjects") ?: "../aws-crt-kotlin" + + val compositeProjectPaths = compositeProjects.split(",") + .map { it.replaceFirst("^~".toRegex(), System.getProperty("user.home")) } // expand ~ to user's home directory + .filter { it.isNotBlank() } + .map { file(it) } + + compositeProjectPaths.also { + if (it.isNotEmpty()) { + println("Adding composite build projects from local.properties: ${compositeProjectPaths.joinToString { it.name }}") + } + } +} catch (e: Throwable) { + logger.error("Failed to load composite project paths from local.properties") + listOf(file("../aws-crt-kotlin")) +} + +compositeProjectList.forEach { + if (it.exists()) { + println("Including build '$it'") + includeBuild(it) + } else { + println("Ignoring invalid build directory '$it'") + } +} + rootProject.name = "smithy-kotlin" include(":dokka-smithy")