From a29b8ca6b8630bdce560589a239428c928eb9021 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 09:05:09 -0500 Subject: [PATCH 01/33] Checksum bindings --- .github/scripts/run-container-test.py | 152 ++++++++++++++++++ bom/build.gradle.kts | 3 - gradle/libs.versions.toml | 1 + .../awssigning/crt/CrtSigningSuiteTest.kt | 10 +- .../runtime/crt/ReadChannelBodyStreamTest.kt | 6 + .../runtime/crt/SdkSourceBodyStreamTest.kt | 4 + .../http/engine/crt/AsyncStressTest.kt | 4 - .../http/engine/crt/SendChunkedBodyTest.kt | 8 +- runtime/protocol/http-test/build.gradle.kts | 8 + .../runtime/httptest/TestWithLocalServer.kt | 42 +++-- runtime/runtime-core/build.gradle.kts | 6 + .../kotlin/runtime/hashing/Crc32Test.kt | 7 +- .../kotlin/runtime/hashing/Crc32Native.kt | 18 ++- .../kotlin/runtime/hashing/Md5Native.kt | 16 +- .../kotlin/runtime/hashing/Sha1Native.kt | 15 +- .../kotlin/runtime/hashing/Sha256Native.kt | 8 +- 16 files changed, 239 insertions(+), 69 deletions(-) create mode 100755 .github/scripts/run-container-test.py rename runtime/protocol/http-test/{jvm => jvmAndNative}/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt (57%) diff --git a/.github/scripts/run-container-test.py b/.github/scripts/run-container-test.py new file mode 100755 index 0000000000..56d9be34d3 --- /dev/null +++ b/.github/scripts/run-container-test.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +""" +Run precompiled Kotlin/Native test binaries in a Docker container for a specific Linux distribution and architecture. + +This requires Docker multiarch support, see https://docs.docker.com/build/building/multi-platform/ and https://github.com/multiarch/qemu-user-static +In GitHub we use a provided action for this: https://github.com/docker/setup-qemu-action + +Locally you would need to run one of: + +`docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes` + +OR + +`docker run --privileged --rm tonistiigi/binfmt --install all` +""" + +import argparse +import os +import subprocess +import shlex +import shutil + +VERBOSE = False + +DISTRO_TO_IMAGE_NAME = { + "ubuntu-22.04": "public.ecr.aws/lts/ubuntu:22.04_stable", + "al2023": "public.ecr.aws/amazonlinux/amazonlinux:2023", + "al2": "public.ecr.aws/amazonlinux/amazonlinux:2" +} + +DOCKER_PLATFORM_BY_ARCH = { + "x64": "linux/amd64", + "arm64": "linux/arm64" +} + + +def vprint(message): + global VERBOSE + if VERBOSE: + print(message) + + +def running_in_github_action(): + """ + Test if currently running in a GitHub action or running locally + :return: True if running in GH, False otherwise + """ + return "GITHUB_WORKFLOW" in os.environ + + +def shell(command, cwd=None, check=True, capture_output=False): + """ + Run a command + :param command: command to run + :param cwd: the current working directory to change to before executing the command + :param check: flag indicating if the status code should be checked. When true an exception will be + thrown if the command exits with a non-zero exit status. + :returns: the subprocess CompletedProcess output + """ + vprint(f"running `{command}`") + return subprocess.run(command, shell=True, check=check, cwd=cwd, capture_output=capture_output) + + +def oci_executable(): + """ + Attempt to find the OCI container executor used to build and run docker containers + """ + oci_exe = os.environ.get('OCI_EXE') + if oci_exe is not None: + return oci_exe + + executors = ['finch', 'podman', 'docker'] + + for exe in executors: + if shutil.which(exe) is not None: + return exe + + print("cannot find container executor") + exit(1) + + +def run_docker_test(opts): + """ + Run a docker test for a precompiled Kotlin/Native binary + + :param opts: the parsed command line options + """ + platform = DOCKER_PLATFORM_BY_ARCH[opts.arch] + oci_exe = oci_executable() + + test_bin_dir = os.path.abspath(opts.test_bin_dir) + image_name = DISTRO_TO_IMAGE_NAME[opts.distro] + path_to_exe = f'./linux{opts.arch.capitalize()}/debugTest/test.kexe' + + cmd = [ + oci_exe, + 'run', + '--rm', + f'-v{test_bin_dir}:/test', + ] + if not opts.no_system_certs: + cmd.append(f'-v/etc/ssl:/etc/ssl') + + cmd.extend( + [ + '-w/test', + '-e DEBIAN_FRONTEND=noninteractive', + '--platform', + platform, + image_name, + path_to_exe, + ] + ) + + cmd = shlex.join(cmd) + print(cmd) + shell(cmd) + + +def create_cli(): + parser = argparse.ArgumentParser( + prog="run-container-test", + description="Run cross platform test binaries in a container", + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + + parser.add_argument("-v", "--verbose", help="enable verbose output", action="store_true") + + parser.add_argument("--distro", required=True, choices=DISTRO_TO_IMAGE_NAME.keys(), help="the distribution name to run the task on") + parser.add_argument("--arch", required=True, choices=DOCKER_PLATFORM_BY_ARCH.keys(), help="the architecture to use") + parser.add_argument("--test-bin-dir", required=True, help="the path to the test binary directory root") + parser.add_argument("--no-system-certs", action='store_true', help="disable mounting system certificates into the container") + + return parser + + +def main(): + cli = create_cli() + opts = cli.parse_args() + if opts.verbose: + global VERBOSE + VERBOSE = True + + run_docker_test(opts) + + +if __name__ == '__main__': + main() diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index c0e23752f3..c65fcb3762 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -7,8 +7,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import java.util.* plugins { `maven-publish` @@ -52,7 +50,6 @@ fun createBomConstraintsAndVersionCatalog() { fun Project.artifactId(target: KotlinTarget): String = when (target) { is KotlinMetadataTarget -> name - is KotlinJsTarget -> "$name-js" else -> "$name-${target.targetName.lowercase()}" } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f52b1a56cb..fb67d759ca 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -96,6 +96,7 @@ ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor- 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" } ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor-version" } +ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor-version" } kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml-version" } jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup-version" } diff --git a/runtime/auth/aws-signing-crt/jvmAndNative/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 index 1b7ed92a07..f180b9e28b 100644 --- a/runtime/auth/aws-signing-crt/jvmAndNative/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 @@ -10,9 +10,9 @@ import aws.smithy.kotlin.runtime.auth.awssigning.tests.SigningSuiteTestBase class CrtSigningSuiteTest : SigningSuiteTestBase() { override val signer: AwsSigner = CrtAwsSigner - override val disabledTests = super.disabledTests + setOf( - // FIXME - Signature mismatch possibly related to https://github.com/awslabs/aws-crt-java/pull/419. Needs - // investigation. - "get-utf8", - ) +// override val disabledTests = super.disabledTests + setOf( +// FIXME - Signature mismatch possibly related to https://github.com/awslabs/aws-crt-java/pull/419. Needs +// investigation. +// "get-utf8", +// ) } diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt index eb0acf777e..a865dfe439 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import kotlinx.coroutines.yield +import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -26,6 +27,7 @@ class ReadChannelBodyStreamTest { return MutableBuffer.of(dest) to dest } + @Ignore @Test fun testClose() = runTest { val chan = SdkByteChannel() @@ -42,6 +44,7 @@ class ReadChannelBodyStreamTest { assertTrue(stream.sendRequestBody(sendBuffer)) } + @Ignore @Test fun testCancellation() = runTest { val chan = SdkByteChannel() @@ -56,6 +59,7 @@ class ReadChannelBodyStreamTest { } } + @Ignore @Test fun testReadFully() = runTest { val data = byteArrayOf(1, 2, 3, 4, 5) @@ -71,6 +75,7 @@ class ReadChannelBodyStreamTest { } } + @Ignore @Test fun testPartialRead() = runTest { val chan = SdkByteReadChannel("123456".encodeToByteArray()) @@ -89,6 +94,7 @@ class ReadChannelBodyStreamTest { assertEquals("456", sent2.decodeToString()) } + @Ignore @Test fun testLargeTransfer() = runTest { val chan = SdkByteChannel() diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt index 4c8ee5c3ba..6026914906 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt @@ -10,6 +10,7 @@ import aws.smithy.kotlin.runtime.io.SdkBuffer import aws.smithy.kotlin.runtime.io.SdkSource import aws.smithy.kotlin.runtime.io.source import kotlinx.coroutines.test.runTest +import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -21,6 +22,7 @@ class SdkSourceBodyStreamTest { return MutableBuffer.of(dest) to dest } + @Ignore @Test fun testReadFully() = runTest { val data = byteArrayOf(1, 2, 3, 4, 5) @@ -35,6 +37,7 @@ class SdkSourceBodyStreamTest { } } + @Ignore @Test fun testPartialRead() = runTest { val source = "123456".encodeToByteArray().source() @@ -52,6 +55,7 @@ class SdkSourceBodyStreamTest { assertEquals("456", sent2.decodeToString()) } + @Ignore @Test fun testLargeTransfer() = runTest { val data = "foobar" diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 index 96efc44f7a..406a488089 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 @@ -13,7 +13,6 @@ import aws.smithy.kotlin.runtime.http.request.url import aws.smithy.kotlin.runtime.httptest.TestWithLocalServer import aws.smithy.kotlin.runtime.net.Host import aws.smithy.kotlin.runtime.net.Scheme -import aws.smithy.kotlin.runtime.testing.IgnoreWindows import io.ktor.server.cio.* import io.ktor.server.engine.* import io.ktor.server.response.* @@ -25,9 +24,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) { routing { get("/largeResponse") { @@ -39,7 +36,6 @@ class AsyncStressTest : TestWithLocalServer() { } } - @IgnoreWindows("FIXME - times out after upgrade to kotlinx.coroutines 1.6.0") @Test fun testStreamNotConsumed() = runBlocking { // test that filling the stream window and not consuming the body stream still cleans up resources diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 index d0e2e2cf94..88366c41f0 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 @@ -33,7 +33,7 @@ class SendChunkedBodyTest { val chunkedBytes = """ 100;chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(256)}\r\n\r\n - """.trimIndent().toByteArray() + """.trimIndent().encodeToByteArray() val source = chunkedBytes.source() @@ -52,7 +52,7 @@ class SendChunkedBodyTest { val chunkedBytes = """ ${chunkSize.toString(16)};chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(chunkSize)}\r\n\r\n - """.trimIndent().toByteArray() + """.trimIndent().encodeToByteArray() val source = chunkedBytes.source() @@ -71,7 +71,7 @@ class SendChunkedBodyTest { val chunkedBytes = """ 100;chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(256)}\r\n\r\n - """.trimIndent().toByteArray() + """.trimIndent().encodeToByteArray() val channel = SdkByteReadChannel(chunkedBytes) @@ -91,7 +91,7 @@ class SendChunkedBodyTest { val chunkedBytes = """ ${chunkSize.toString(16)};chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(chunkSize)}\r\n\r\n - """.trimIndent().toByteArray() + """.trimIndent().encodeToByteArray() val channel = SdkByteReadChannel(chunkedBytes) diff --git a/runtime/protocol/http-test/build.gradle.kts b/runtime/protocol/http-test/build.gradle.kts index a2077a979c..e966832924 100644 --- a/runtime/protocol/http-test/build.gradle.kts +++ b/runtime/protocol/http-test/build.gradle.kts @@ -28,6 +28,14 @@ kotlin { } } + jvmAndNativeMain { + dependencies { + api(libs.ktor.server.cio) + implementation(libs.ktor.client.core) + implementation(libs.ktor.server.core) + } + } + all { languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi") } diff --git a/runtime/protocol/http-test/jvm/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt similarity index 57% rename from runtime/protocol/http-test/jvm/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt rename to runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 3ffc1a868c..9543954d95 100644 --- a/runtime/protocol/http-test/jvm/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -5,13 +5,18 @@ package aws.smithy.kotlin.runtime.httptest -import io.ktor.server.engine.* +import io.ktor.client.HttpClient +import io.ktor.client.request.get +import io.ktor.client.statement.HttpResponse +import io.ktor.http.isSuccess +import io.ktor.server.engine.EmbeddedServer +import kotlinx.io.IOException +import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout -import java.net.* -import java.util.concurrent.* import kotlin.test.AfterTest import kotlin.test.BeforeTest +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds /** @@ -19,7 +24,7 @@ import kotlin.time.Duration.Companion.seconds * mocking an HTTP client engine is difficult. */ public abstract class TestWithLocalServer { - protected val serverPort: Int = ServerSocket(0).use { it.localPort } + protected val serverPort: Int = 54734 protected val testHost: String = "localhost" public abstract val server: EmbeddedServer<*, *> @@ -33,11 +38,10 @@ public abstract class TestWithLocalServer { attempt++ try { server.start() - println("test server listening on: $testHost:$serverPort") break } catch (cause: Throwable) { if (attempt >= 10) throw cause - Thread.sleep(250L * attempt) + delay(250L * attempt) } } while (true) @@ -47,18 +51,24 @@ public abstract class TestWithLocalServer { @AfterTest public fun stopServer() { - server.stop(0, 0, TimeUnit.SECONDS) + server.stop(0, 0) println("test server stopped") } - private fun ensureServerRunning() { - do { - try { - Socket("localhost", serverPort).close() - break - } catch (_: Throwable) { - Thread.sleep(100) - } - } while (true) + private suspend fun ensureServerRunning() { + val client = HttpClient() + try { + do { + try { + val response: HttpResponse = client.get("http://localhost:$serverPort") + if (response.status.isSuccess()) break + } catch (_: IOException) { + delay(100.milliseconds) + } + } while (true) + } finally { + client.close() + } } + } diff --git a/runtime/runtime-core/build.gradle.kts b/runtime/runtime-core/build.gradle.kts index bbaa9d60ef..d902f42a7f 100644 --- a/runtime/runtime-core/build.gradle.kts +++ b/runtime/runtime-core/build.gradle.kts @@ -23,6 +23,12 @@ kotlin { } } + nativeMain { + dependencies { + api(libs.crt.kotlin) + } + } + commonTest { dependencies { // Coroutines' locking features are used in retry token bucket implementations diff --git a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32Test.kt b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32Test.kt index e3b489aba0..8f622fd513 100644 --- a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32Test.kt +++ b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32Test.kt @@ -20,7 +20,6 @@ class Crc32Test { val input = "foobar" crc.update(input.encodeToByteArray(), 0, input.length) - assertEquals(2666930069U, crc.digestValue()) // checksum of "foobar" assertEquals("nvYflQ==", crc.digest().encodeBase64String()) } @@ -39,9 +38,8 @@ class Crc32Test { val crc = Crc32() val input = "foobar" crc.update(input.encodeToByteArray(), 0, input.length / 2) - assertEquals(2356372769U, crc.digestValue()) // checksum of "foo" crc.update(input.encodeToByteArray(), (input.length - input.length / 2), input.length / 2) - assertEquals(2666930069U, crc.digestValue()) // checksum of "foobar" + assertEquals("nvYflQ==", crc.digest().encodeBase64String()) // checksum of "foobar" } @Test @@ -49,8 +47,7 @@ class Crc32Test { val crc = Crc32() val input = "foobar" crc.update(input.encodeToByteArray(), 0, input.length) - assertEquals(2666930069U, crc.digestValue()) // checksum of "foobar" - crc.digest() + assertEquals("nvYflQ==", crc.digest().encodeBase64String()) // checksum of "foobar" assertEquals(0U, crc.digestValue()) } } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Crc32Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Crc32Native.kt index 2c40576e88..ef86e4e519 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Crc32Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Crc32Native.kt @@ -5,6 +5,7 @@ package aws.smithy.kotlin.runtime.hashing import aws.smithy.kotlin.runtime.InternalApi +import aws.sdk.kotlin.crt.util.hashing.Crc32 as CrtCrc32 /** * CRC-32 checksum. Note: [digest] will return the bytes (big endian) of the CRC32 integer value. Access [digestValue] @@ -12,15 +13,16 @@ import aws.smithy.kotlin.runtime.InternalApi */ @InternalApi public actual class Crc32 actual constructor() : Crc32Base() { - actual override fun digestValue(): UInt { - TODO("Not yet implemented") - } + private val delegate = CrtCrc32() - actual override fun update(input: ByteArray, offset: Int, length: Int) { - TODO("Not yet implemented") + actual override fun digestValue(): UInt { + val bytes = delegate.digest() + return ((bytes[0].toUInt() and 0xffu) shl 24) or + ((bytes[1].toUInt() and 0xffu) shl 16) or + ((bytes[2].toUInt() and 0xffu) shl 8) or + (bytes[3].toUInt() and 0xffu) } - actual override fun reset() { - TODO("Not yet implemented") - } + actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = delegate.update(input, offset, length) + actual override fun reset(): Unit = delegate.reset() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt index 9614543dad..efff134fc8 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Md5Native.kt @@ -5,21 +5,15 @@ package aws.smithy.kotlin.runtime.hashing import aws.smithy.kotlin.runtime.InternalApi +import aws.sdk.kotlin.crt.util.hashing.Md5 as CrtMd5 /** * Implementation of RFC1321 MD5 digest */ @InternalApi public actual class Md5 actual constructor() : Md5Base() { - actual override fun update(input: ByteArray, offset: Int, length: Int) { - TODO("Not yet implemented") - } - - actual override fun digest(): ByteArray { - TODO("Not yet implemented") - } - - actual override fun reset() { - TODO("Not yet implemented") - } + private val delegate = CrtMd5() + actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = delegate.update(input, offset, length) + actual override fun digest(): ByteArray = delegate.digest() + actual override fun reset(): Unit = delegate.reset() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha1Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha1Native.kt index 6a4f4e1abc..541b25246f 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha1Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha1Native.kt @@ -5,21 +5,16 @@ package aws.smithy.kotlin.runtime.hashing import aws.smithy.kotlin.runtime.InternalApi +import aws.sdk.kotlin.crt.util.hashing.Sha1 as CrtSha1 /** * Implementation of SHA-1 (Secure Hash Algorithm 1) hash function. See: https://csrc.nist.gov/projects/hash-functions */ @InternalApi public actual class Sha1 actual constructor() : Sha1Base() { - actual override fun update(input: ByteArray, offset: Int, length: Int) { - TODO("Not yet implemented") - } + private val delegate = CrtSha1() - actual override fun digest(): ByteArray { - TODO("Not yet implemented") - } - - actual override fun reset() { - TODO("Not yet implemented") - } + actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = delegate.update(input, offset, length) + actual override fun digest(): ByteArray = delegate.digest() + actual override fun reset(): Unit = delegate.reset() } diff --git a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha256Native.kt b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha256Native.kt index 6c85dfccea..69a82d4664 100644 --- a/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha256Native.kt +++ b/runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/hashing/Sha256Native.kt @@ -5,10 +5,12 @@ package aws.smithy.kotlin.runtime.hashing import aws.smithy.kotlin.runtime.InternalApi +import aws.sdk.kotlin.crt.util.hashing.Sha256 as CrtSha256 @InternalApi public actual class Sha256 : Sha256Base() { - actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = TODO("native not supported") - actual override fun digest(): ByteArray = TODO("native not supported") - actual override fun reset(): Unit = TODO("native not supported") + private val delegate = CrtSha256() + actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = delegate.update(input, offset, length) + actual override fun digest(): ByteArray = delegate.digest() + actual override fun reset(): Unit = delegate.reset() } From 1b63dc35fc7aefa0ed70c1841ab65c439dd55331 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 09:07:03 -0500 Subject: [PATCH 02/33] CI From b131cd28ce26df5c28744ed864f445e0cf59b1bc Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 09:10:55 -0500 Subject: [PATCH 03/33] ktlint --- .../aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 9543954d95..42792e87c8 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -10,10 +10,10 @@ import io.ktor.client.request.get import io.ktor.client.statement.HttpResponse import io.ktor.http.isSuccess import io.ktor.server.engine.EmbeddedServer -import kotlinx.io.IOException import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout +import kotlinx.io.IOException import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.time.Duration.Companion.milliseconds @@ -70,5 +70,4 @@ public abstract class TestWithLocalServer { client.close() } } - } From 8ae9c99b5d4a69502b8d3a4f962f59e592000dae Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 10:48:46 -0500 Subject: [PATCH 04/33] Replace `ensureServerRunning` with `.start(wait = true)` --- .../runtime/http/engine/crt/AsyncStressTest.kt | 2 +- .../runtime/httptest/TestWithLocalServer.kt | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 index 406a488089..a6800c1edb 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 @@ -34,7 +34,7 @@ class AsyncStressTest : TestWithLocalServer() { call.respondText(text.repeat(respSize / text.length)) } } - } + }.start(wait = true) @Test fun testStreamNotConsumed() = runBlocking { diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 42792e87c8..4470cf3fbb 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -44,8 +44,6 @@ public abstract class TestWithLocalServer { delay(250L * attempt) } } while (true) - - ensureServerRunning() } } @@ -54,20 +52,4 @@ public abstract class TestWithLocalServer { server.stop(0, 0) println("test server stopped") } - - private suspend fun ensureServerRunning() { - val client = HttpClient() - try { - do { - try { - val response: HttpResponse = client.get("http://localhost:$serverPort") - if (response.status.isSuccess()) break - } catch (_: IOException) { - delay(100.milliseconds) - } - } while (true) - } finally { - client.close() - } - } } From e0eb12706de6f0a7d6fa798b5d941f5e087c3c33 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 10:54:53 -0500 Subject: [PATCH 05/33] ktlint --- .../smithy/kotlin/runtime/httptest/TestWithLocalServer.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 4470cf3fbb..4887c5ca2a 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -5,18 +5,13 @@ package aws.smithy.kotlin.runtime.httptest -import io.ktor.client.HttpClient import io.ktor.client.request.get -import io.ktor.client.statement.HttpResponse -import io.ktor.http.isSuccess import io.ktor.server.engine.EmbeddedServer import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout -import kotlinx.io.IOException import kotlin.test.AfterTest import kotlin.test.BeforeTest -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds /** From 0d56c69960bf49e7a4ed0e51eecf91825b68f26d Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 11:39:44 -0500 Subject: [PATCH 06/33] Bump plugin version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fb67d759ca..993b01cc0a 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.15-kn" +aws-kotlin-repo-tools-version = "0.4.16-kn" # libs coroutines-version = "1.9.0" From e3275670c88531b4b8bac910138a40a3a16abccd Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 12:27:06 -0500 Subject: [PATCH 07/33] "Failed" -> "Could not" to make searching logs for compiler errors easier --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index ac7f398bc4..bfd379d2ec 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,7 +46,7 @@ val compositeProjectList = try { } } } catch (e: Throwable) { - logger.error("Failed to load composite project paths from local.properties") + logger.error("Could not load composite project paths from local.properties") listOf(file("../aws-crt-kotlin")) } From f6effee22f53f249afb7e2dba0a4abf05413fb77 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 14:09:28 -0500 Subject: [PATCH 08/33] Add section on using `run-container-test.py` --- CONTRIBUTING.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a48ecefd7d..c5ede600b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -223,3 +223,25 @@ If you discover a potential security issue in this project we ask that you notif See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. + +## Kotlin/Native +Support for Kotlin/Native is in active development. The following sections cover how to effectively test your work. + +### Linux/Unix + +#### Testing Different Linux Distros and Architectures + +1. Build the test executable(s) for the architecture(s) you want to test. + +```sh +# build specific arch +./gradlew linuxX64TestBinaries +``` + +2. Use the `run-container-test.py` helper script to execute tests locally. Change the directory as needed. + +```sh +OCI_EXE=docker python3 .github/scripts/run-container-test.py --distro al2 --arch x64 --test-bin-dir ./runtime/runtime-core/build/bin +``` + +See the usage/help for different distributions provided: `python3 .github/scripts/run-container.py -h` From 688c434a24f1e64e582f4fe2f89d55872d636199 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 15:02:26 -0500 Subject: [PATCH 09/33] CI From 88f8fcd4e27d333de7b1403517a1335e4745d8fc Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 15:55:09 -0500 Subject: [PATCH 10/33] Remove `wait=true` --- .../smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 index a6800c1edb..39f4170550 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/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 @@ -34,7 +34,7 @@ class AsyncStressTest : TestWithLocalServer() { call.respondText(text.repeat(respSize / text.length)) } } - }.start(wait = true) + }.start() @Test fun testStreamNotConsumed() = runBlocking { From ae19ccf564cda58f0f9311fbce7d43d350171738 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 15:55:17 -0500 Subject: [PATCH 11/33] Remove unused import --- .../aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 4887c5ca2a..a5aa5c35af 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -5,7 +5,6 @@ package aws.smithy.kotlin.runtime.httptest -import io.ktor.client.request.get import io.ktor.server.engine.EmbeddedServer import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking From 5b1baacdfbc11f6a2754a53fb9352147a7a2383b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 15:56:40 -0500 Subject: [PATCH 12/33] Add debug step --- .github/actions/setup-build/action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 0a2b5cbb99..2bd1a7ad24 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -20,6 +20,15 @@ runs: path: 'aws-crt-kotlin' repository: 'awslabs/aws-crt-kotlin' + - name: Debug! + working-directory: ./aws-crt-kotlin + shell: bash + run: | + ls -a . + ls -a ./crt + ls -a ./crt/aws-c-common + ls -a ./crt/aws-c-common/cmake + # 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 From 479a389c04e40988d6159c46047f32bf91794263 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 16:02:11 -0500 Subject: [PATCH 13/33] Add debug step --- .github/actions/setup-build/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 2bd1a7ad24..9cc88ee227 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -24,10 +24,12 @@ runs: working-directory: ./aws-crt-kotlin shell: bash run: | + echo "ls -a ." ls -a . + echo "ls -a ./crt" ls -a ./crt + echo "ls -a ./crt/aws-c-common" ls -a ./crt/aws-c-common - ls -a ./crt/aws-c-common/cmake # Cache the Kotlin/Native toolchain based on the input Kotlin version from version catalog # see https://kotlinlang.org/docs/native-improving-compilation-time.html From e7da56ea252993e2ecee9eda43843ed22d6f5665 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 16:19:49 -0500 Subject: [PATCH 14/33] Upgrade plugin version --- .github/actions/setup-build/action.yml | 1 + gradle/libs.versions.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 9cc88ee227..9b541bb032 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -19,6 +19,7 @@ runs: # checkout aws-crt-kotlin as a sibling which will automatically make it an included build path: 'aws-crt-kotlin' repository: 'awslabs/aws-crt-kotlin' + submodules: 'true' - name: Debug! working-directory: ./aws-crt-kotlin diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 993b01cc0a..6d297773cb 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.16-kn" +aws-kotlin-repo-tools-version = "0.4.17-kn" # libs coroutines-version = "1.9.0" From c5c4efb5b4cc03fec3cda8c3710f1ca681901b37 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 16:24:19 -0500 Subject: [PATCH 15/33] Checkout kn-main aws-kotlin-repo-tools --- .github/actions/setup-build/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 9b541bb032..dbb95239f1 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -10,6 +10,7 @@ runs: with: path: 'aws-kotlin-repo-tools' repository: 'awslabs/aws-kotlin-repo-tools' + ref: 'kn-main' sparse-checkout: | .github From 48a1b4019d58423686a00ba766aed900dff1c0a9 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 16:30:19 -0500 Subject: [PATCH 16/33] Bump version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6d297773cb..b3931d8638 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.17-kn" +aws-kotlin-repo-tools-version = "0.4.18-kn" # libs coroutines-version = "1.9.0" From 82dda2da4955905b061cbca773dace0fc6434d6a Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 18 Nov 2024 16:57:54 -0500 Subject: [PATCH 17/33] Remove debug step --- .github/actions/setup-build/action.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index dbb95239f1..d2dc452b7f 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -22,17 +22,6 @@ runs: repository: 'awslabs/aws-crt-kotlin' submodules: 'true' - - name: Debug! - working-directory: ./aws-crt-kotlin - shell: bash - run: | - echo "ls -a ." - ls -a . - echo "ls -a ./crt" - ls -a ./crt - echo "ls -a ./crt/aws-c-common" - ls -a ./crt/aws-c-common - # 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 From 51668052709b76f22dbe8522aa3f8cc8ae082ec0 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:18:12 -0500 Subject: [PATCH 18/33] Parse aws-kotlin-repo-tools version from libs.versions.toml --- .github/actions/setup-build/action.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index d2dc452b7f..fa46318047 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -5,12 +5,19 @@ description: > runs: using: composite steps: - - name: Checkout tools + - name: Extract aws-kotlin-repo-tools version + working-directory: ./smithy-kotlin + run: | + export AWS_KOTLIN_REPO_TOOLS_VERSION=$(grep '^aws-kotlin-repo-tools-version' ./gradle/libs.versions.toml | sed -E 's/.*= "(.*)"/\1/') + echo "Using aws-kotlin-repo-tools version $AWS_KOTLIN_REPO_TOOLS_VERSION" + echo "aws_kotlin_repo_tools_version=$AWS_KOTLIN_REPO_TOOLS_VERSION" >> $GITHUB_ENV + + - name: Checkout aws-kotlin-repo-tools uses: actions/checkout@v4 with: path: 'aws-kotlin-repo-tools' repository: 'awslabs/aws-kotlin-repo-tools' - ref: 'kn-main' + ref: ${{ env.aws_kotlin_repo_tools_version }} sparse-checkout: | .github From 9ff195c1958318d1a3bb0cd85b00bb22d9d1f95c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:18:52 -0500 Subject: [PATCH 19/33] Add `shell` --- .github/actions/setup-build/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index fa46318047..5e72c0c6d5 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -7,6 +7,7 @@ runs: steps: - name: Extract aws-kotlin-repo-tools version working-directory: ./smithy-kotlin + shell: bash run: | export AWS_KOTLIN_REPO_TOOLS_VERSION=$(grep '^aws-kotlin-repo-tools-version' ./gradle/libs.versions.toml | sed -E 's/.*= "(.*)"/\1/') echo "Using aws-kotlin-repo-tools version $AWS_KOTLIN_REPO_TOOLS_VERSION" From 49079ad2089591527082b88e88793b8c59c70491 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:26:37 -0500 Subject: [PATCH 20/33] Remove disabledTests --- .../runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/runtime/auth/aws-signing-crt/jvmAndNative/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 index f180b9e28b..f312bf09a0 100644 --- a/runtime/auth/aws-signing-crt/jvmAndNative/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 @@ -9,10 +9,4 @@ import aws.smithy.kotlin.runtime.auth.awssigning.tests.SigningSuiteTestBase class CrtSigningSuiteTest : SigningSuiteTestBase() { override val signer: AwsSigner = CrtAwsSigner - -// override val disabledTests = super.disabledTests + setOf( -// FIXME - Signature mismatch possibly related to https://github.com/awslabs/aws-crt-java/pull/419. Needs -// investigation. -// "get-utf8", -// ) } From c1d4513a2fc402a3981d52e6a81c1e0f899b549e Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:27:56 -0500 Subject: [PATCH 21/33] Re-enable tests --- .../smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt | 4 ---- .../aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt | 3 --- 2 files changed, 7 deletions(-) diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt index a865dfe439..314cce4737 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt @@ -27,7 +27,6 @@ class ReadChannelBodyStreamTest { return MutableBuffer.of(dest) to dest } - @Ignore @Test fun testClose() = runTest { val chan = SdkByteChannel() @@ -59,7 +58,6 @@ class ReadChannelBodyStreamTest { } } - @Ignore @Test fun testReadFully() = runTest { val data = byteArrayOf(1, 2, 3, 4, 5) @@ -75,7 +73,6 @@ class ReadChannelBodyStreamTest { } } - @Ignore @Test fun testPartialRead() = runTest { val chan = SdkByteReadChannel("123456".encodeToByteArray()) @@ -94,7 +91,6 @@ class ReadChannelBodyStreamTest { assertEquals("456", sent2.decodeToString()) } - @Ignore @Test fun testLargeTransfer() = runTest { val chan = SdkByteChannel() diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt index 6026914906..e262616c37 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt @@ -22,7 +22,6 @@ class SdkSourceBodyStreamTest { return MutableBuffer.of(dest) to dest } - @Ignore @Test fun testReadFully() = runTest { val data = byteArrayOf(1, 2, 3, 4, 5) @@ -37,7 +36,6 @@ class SdkSourceBodyStreamTest { } } - @Ignore @Test fun testPartialRead() = runTest { val source = "123456".encodeToByteArray().source() @@ -55,7 +53,6 @@ class SdkSourceBodyStreamTest { assertEquals("456", sent2.decodeToString()) } - @Ignore @Test fun testLargeTransfer() = runTest { val data = "foobar" From 679982386acbe198610ceac6f2608e10855cc7ac Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:35:52 -0500 Subject: [PATCH 22/33] ktlint --- .../aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt index e262616c37..4c8ee5c3ba 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/SdkSourceBodyStreamTest.kt @@ -10,7 +10,6 @@ import aws.smithy.kotlin.runtime.io.SdkBuffer import aws.smithy.kotlin.runtime.io.SdkSource import aws.smithy.kotlin.runtime.io.source import kotlinx.coroutines.test.runTest -import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse From 84ea65d192ecb27db3b3c27711457e83c7705184 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 19 Nov 2024 10:45:18 -0500 Subject: [PATCH 23/33] Remove @Ignore --- .../aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt index 314cce4737..eb0acf777e 100644 --- a/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt +++ b/runtime/crt-util/jvmAndNative/test/aws/smithy/kotlin/runtime/crt/ReadChannelBodyStreamTest.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import kotlinx.coroutines.yield -import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -43,7 +42,6 @@ class ReadChannelBodyStreamTest { assertTrue(stream.sendRequestBody(sendBuffer)) } - @Ignore @Test fun testCancellation() = runTest { val chan = SdkByteChannel() From 3e967ab788fdebecf71daec4f3d41b60ff40d258 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 20 Nov 2024 16:04:38 -0500 Subject: [PATCH 24/33] Clarify digestValue() behavior --- .../common/src/aws/smithy/kotlin/runtime/hashing/Crc32.kt | 4 +++- .../common/src/aws/smithy/kotlin/runtime/hashing/Crc32c.kt | 2 +- .../jvm/src/aws/smithy/kotlin/runtime/hashing/Crc32JVM.kt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32.kt index 84b76b89a0..454c4fc552 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32.kt @@ -11,11 +11,13 @@ public abstract class Crc32Base : HashFunction { override val blockSizeBytes: Int = 4 override val digestSizeBytes: Int = 4 + /** + * Digest the current checksum, returning it as a [UInt] + */ public abstract fun digestValue(): UInt override fun digest(): ByteArray { val x = digestValue() - reset() return byteArrayOf( ((x shr 24) and 0xffu).toByte(), ((x shr 16) and 0xffu).toByte(), diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32c.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32c.kt index da77560226..a6d9e10a61 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32c.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/hashing/Crc32c.kt @@ -21,7 +21,7 @@ public class Crc32c : Crc32Base() { override fun update(input: ByteArray, offset: Int, length: Int): Unit = md.update(input, offset, length) - override fun digestValue(): UInt = md.getValue().toUInt() + override fun digestValue(): UInt = md.getValue().toUInt().also { reset() } override fun reset(): Unit = md.reset() } diff --git a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Crc32JVM.kt b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Crc32JVM.kt index 0c42a47434..5afae09bad 100644 --- a/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Crc32JVM.kt +++ b/runtime/runtime-core/jvm/src/aws/smithy/kotlin/runtime/hashing/Crc32JVM.kt @@ -13,7 +13,7 @@ public actual class Crc32 : Crc32Base() { actual override fun update(input: ByteArray, offset: Int, length: Int): Unit = md.update(input, offset, length) - actual override fun digestValue(): UInt = md.value.toUInt() + actual override fun digestValue(): UInt = md.value.toUInt().also { reset() } actual override fun reset(): Unit = md.reset() } From 1992bd3da3995cb0241a590d53986872c73f07b4 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 12 Dec 2024 13:19:44 -0500 Subject: [PATCH 25/33] Use port selector, replace `ensureServerRunning` --- .../runtime/httptest/TestWithLocalServer.kt | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index a5aa5c35af..193041ae1d 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -5,7 +5,14 @@ package aws.smithy.kotlin.runtime.httptest +import io.ktor.client.HttpClient +import io.ktor.client.request.get +import io.ktor.http.HttpStatusCode +import io.ktor.network.selector.SelectorManager +import io.ktor.network.sockets.InetSocketAddress +import io.ktor.network.sockets.aSocket import io.ktor.server.engine.EmbeddedServer +import io.ktor.utils.io.core.use import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout @@ -18,7 +25,16 @@ import kotlin.time.Duration.Companion.seconds * mocking an HTTP client engine is difficult. */ public abstract class TestWithLocalServer { - protected val serverPort: Int = 54734 + protected val serverPort: Int + get() = runBlocking { + SelectorManager(this.coroutineContext).use { + aSocket(it) + .tcp() + .bind() + .use { (it.localAddress as InetSocketAddress).port } + } + } + protected val testHost: String = "localhost" public abstract val server: EmbeddedServer<*, *> @@ -38,6 +54,8 @@ public abstract class TestWithLocalServer { delay(250L * attempt) } } while (true) + + ensureServerRunning() } } @@ -46,4 +64,21 @@ public abstract class TestWithLocalServer { server.stop(0, 0) println("test server stopped") } + + private fun ensureServerRunning() = runBlocking { + val client = HttpClient() + val url = "http://$testHost:$serverPort" + try { + while (true) { + try { + val response = client.get(url) + if (response.status == HttpStatusCode.OK) break + } catch (_: Exception) { + delay(100) + } + } + } finally { + client.close() + } + } } From 0049c008385985af7049e663efb9672fd11fc6be Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 12 Dec 2024 15:22:46 -0500 Subject: [PATCH 26/33] Use event monitoring to ensure server is running --- .../runtime/httptest/TestWithLocalServer.kt | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index 193041ae1d..cd84681db7 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -11,8 +11,10 @@ import io.ktor.http.HttpStatusCode import io.ktor.network.selector.SelectorManager import io.ktor.network.sockets.InetSocketAddress import io.ktor.network.sockets.aSocket +import io.ktor.server.application.ApplicationStarted import io.ktor.server.engine.EmbeddedServer import io.ktor.utils.io.core.use +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout @@ -25,15 +27,14 @@ import kotlin.time.Duration.Companion.seconds * mocking an HTTP client engine is difficult. */ public abstract class TestWithLocalServer { - protected val serverPort: Int - get() = runBlocking { - SelectorManager(this.coroutineContext).use { - aSocket(it) - .tcp() - .bind() - .use { (it.localAddress as InetSocketAddress).port } - } + protected val serverPort: Int = runBlocking { + SelectorManager(this.coroutineContext).use { + aSocket(it) + .tcp() + .bind() + .use { (it.localAddress as InetSocketAddress).port } } + } protected val testHost: String = "localhost" @@ -41,6 +42,12 @@ public abstract class TestWithLocalServer { @BeforeTest public fun startServer(): Unit = runBlocking { + val serverStarted = CompletableDeferred() + + server.monitor.subscribe(ApplicationStarted) { + serverStarted.complete(Unit) + } + withTimeout(5.seconds) { var attempt = 0 @@ -55,7 +62,7 @@ public abstract class TestWithLocalServer { } } while (true) - ensureServerRunning() + serverStarted.await() } } @@ -64,21 +71,4 @@ public abstract class TestWithLocalServer { server.stop(0, 0) println("test server stopped") } - - private fun ensureServerRunning() = runBlocking { - val client = HttpClient() - val url = "http://$testHost:$serverPort" - try { - while (true) { - try { - val response = client.get(url) - if (response.status == HttpStatusCode.OK) break - } catch (_: Exception) { - delay(100) - } - } - } finally { - client.close() - } - } } From 5ea2009c8da7f5e1bce696a81177562e6ec1f0aa Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 12 Dec 2024 15:25:58 -0500 Subject: [PATCH 27/33] ktlint --- .../aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt index cd84681db7..370c8f9b7c 100644 --- a/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt +++ b/runtime/protocol/http-test/jvmAndNative/src/aws/smithy/kotlin/runtime/httptest/TestWithLocalServer.kt @@ -5,9 +5,7 @@ package aws.smithy.kotlin.runtime.httptest -import io.ktor.client.HttpClient import io.ktor.client.request.get -import io.ktor.http.HttpStatusCode import io.ktor.network.selector.SelectorManager import io.ktor.network.sockets.InetSocketAddress import io.ktor.network.sockets.aSocket From 8010e22c7488ffd6f7e070f5ef73a7f86cd458d7 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 12 Dec 2024 16:09:55 -0500 Subject: [PATCH 28/33] Fix broken assumption about `digestValue` --- .../test/aws/smithy/kotlin/runtime/hashing/Crc32cTest.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32cTest.kt b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32cTest.kt index 184f62cbd9..0123036e53 100644 --- a/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32cTest.kt +++ b/runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/hashing/Crc32cTest.kt @@ -33,8 +33,6 @@ class Crc32cTest { val input = "foobar" crc.update(input.encodeToByteArray(), 0, input.length / 2) - assertEquals(3485773341U, crc.digestValue()) // checksum of "foo" - crc.update(input.encodeToByteArray(), (input.length - input.length / 2), input.length / 2) assertEquals(224353407U, crc.digestValue()) // checksum of "foobar" } @@ -45,8 +43,7 @@ class Crc32cTest { val input = "foobar" crc.update(input.encodeToByteArray(), 0, input.length) - assertEquals(224353407U, crc.digestValue()) // checksum of "foobar" - assertEquals("DV9cfw==", crc.digest().encodeBase64String()) + assertEquals("DV9cfw==", crc.digest().encodeBase64String()) // checksum of "foobar" } @Test From 215c3478ef5d8ca660b90b12347173482ec68242 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Thu, 12 Dec 2024 16:25:40 -0500 Subject: [PATCH 29/33] Bump to latest build tools plugin --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b3931d8638..8e19642bb2 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.18-kn" +aws-kotlin-repo-tools-version = "0.4.19-kn" # libs coroutines-version = "1.9.0" From b8ddc49fcb085e576b0ba2c9fd3bb65c737ac7b2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 13 Dec 2024 11:12:25 -0500 Subject: [PATCH 30/33] Test disabling cross compile --- .github/workflows/ci.yml | 4 +-- build.gradle.kts | 69 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45b7b9cacc..dd6ee7cad4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: # 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 + ./gradlew -Paws.sdk.kotlin.crt.disableCrossCompile=true -Paws.kotlin.native.disableCrossCompile=true build - name: Save Test Reports if: failure() @@ -126,7 +126,7 @@ jobs: working-directory: ./smithy-kotlin run: | ./gradlew apiCheck - ./gradlew -P"aws.sdk.kotlin.crt.disableCrossCompile"=true build + ./gradlew -P"aws.sdk.kotlin.crt.disableCrossCompile"=true -P"aws.kotlin.native.disableCrossCompile"=true build - name: Save Test Reports if: failure() diff --git a/build.gradle.kts b/build.gradle.kts index ab17214cda..d1e609a3f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,11 @@ import aws.sdk.kotlin.gradle.dsl.configureLinting import aws.sdk.kotlin.gradle.dsl.configureNexus import aws.sdk.kotlin.gradle.util.typedProp +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.konan.target.Family +import org.jetbrains.kotlin.konan.target.HostManager +import kotlin.apply buildscript { // NOTE: buildscript classpath for the root project is the parent classloader for the subprojects, we @@ -154,3 +159,67 @@ apiValidation { ), ) } + +val disableCrossCompile = typedProp("aws.kotlin.native.disableCrossCompile") == true + +if (disableCrossCompile) { + logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.") + disableCrossCompileTargets() +} + +private val KotlinNativeTarget.isLinux: Boolean + get() = konanTarget.family == Family.LINUX + +private val KotlinNativeTarget.isApple: Boolean + get() = konanTarget.family.isAppleFamily + +private val KotlinNativeTarget.isWindows: Boolean + get() = konanTarget.family == Family.MINGW + +/** + * Kotlin/Native Linux and Windows targets are generally enabled on all hosts since + * the Kotlin toolchain and backend compilers support cross compilation. We + * are using cinterop and have to compile CRT for those platforms which sometimes + * requires using docker which isn't always available in CI or setup in users environment. + * + * See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498) + */ +fun Project.disableCrossCompileTargets() { + plugins.withId("org.jetbrains.kotlin.multiplatform") { + configure { + targets.withType { + val knTarget = this + when { + HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget) + HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget) + HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget) + } + } + } + } +} + +internal fun Project.disable(knTarget: KotlinNativeTarget) { + logger.warn("disabling Kotlin/Native target: ${knTarget.name}") + knTarget.apply { + compilations.all { + cinterops.all { + tasks.named(interopProcessingTaskName).configure { enabled = false } + } + compileTaskProvider.configure { enabled = false } + } + + binaries.all { + linkTaskProvider.configure { enabled = false } + } + + mavenPublication { + tasks.withType().configureEach { + onlyIf { publication != this@mavenPublication } + } + tasks.withType().configureEach { + onlyIf { publication != this@mavenPublication } + } + } + } +} From c0da98baf17c0458c86205c8d63f6e3b9d40b760 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 13 Dec 2024 11:34:29 -0500 Subject: [PATCH 31/33] Apply to `allprojects` --- build.gradle.kts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d1e609a3f3..bb3ca025c1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -185,14 +185,16 @@ private val KotlinNativeTarget.isWindows: Boolean * See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498) */ fun Project.disableCrossCompileTargets() { - plugins.withId("org.jetbrains.kotlin.multiplatform") { - configure { - targets.withType { - val knTarget = this - when { - HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget) - HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget) - HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget) + allprojects { + plugins.withId("org.jetbrains.kotlin.multiplatform") { + configure { + targets.withType { + val knTarget = this + when { + HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget) + HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget) + HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget) + } } } } From c1c74af551d756b6342165848a5942f4d7caee76 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 13 Dec 2024 12:02:48 -0500 Subject: [PATCH 32/33] Windows JVM aws.kotlin.native=false --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd6ee7cad4..a3cdbee204 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,7 +126,7 @@ jobs: working-directory: ./smithy-kotlin run: | ./gradlew apiCheck - ./gradlew -P"aws.sdk.kotlin.crt.disableCrossCompile"=true -P"aws.kotlin.native.disableCrossCompile"=true build + ./gradlew -P"aws.kotlin.native=false" build - name: Save Test Reports if: failure() From 15490c5b3dd378b310a3ced3330f1ae49ee894c7 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 13 Dec 2024 12:14:58 -0500 Subject: [PATCH 33/33] Use aws-kotlin-repo-tools disableCrossCompile --- build.gradle.kts | 71 --------------------------------------- gradle/libs.versions.toml | 2 +- runtime/build.gradle.kts | 10 ++++++ 3 files changed, 11 insertions(+), 72 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bb3ca025c1..ab17214cda 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,11 +5,6 @@ import aws.sdk.kotlin.gradle.dsl.configureLinting import aws.sdk.kotlin.gradle.dsl.configureNexus import aws.sdk.kotlin.gradle.util.typedProp -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.konan.target.Family -import org.jetbrains.kotlin.konan.target.HostManager -import kotlin.apply buildscript { // NOTE: buildscript classpath for the root project is the parent classloader for the subprojects, we @@ -159,69 +154,3 @@ apiValidation { ), ) } - -val disableCrossCompile = typedProp("aws.kotlin.native.disableCrossCompile") == true - -if (disableCrossCompile) { - logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.") - disableCrossCompileTargets() -} - -private val KotlinNativeTarget.isLinux: Boolean - get() = konanTarget.family == Family.LINUX - -private val KotlinNativeTarget.isApple: Boolean - get() = konanTarget.family.isAppleFamily - -private val KotlinNativeTarget.isWindows: Boolean - get() = konanTarget.family == Family.MINGW - -/** - * Kotlin/Native Linux and Windows targets are generally enabled on all hosts since - * the Kotlin toolchain and backend compilers support cross compilation. We - * are using cinterop and have to compile CRT for those platforms which sometimes - * requires using docker which isn't always available in CI or setup in users environment. - * - * See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498) - */ -fun Project.disableCrossCompileTargets() { - allprojects { - plugins.withId("org.jetbrains.kotlin.multiplatform") { - configure { - targets.withType { - val knTarget = this - when { - HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget) - HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget) - HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget) - } - } - } - } - } -} - -internal fun Project.disable(knTarget: KotlinNativeTarget) { - logger.warn("disabling Kotlin/Native target: ${knTarget.name}") - knTarget.apply { - compilations.all { - cinterops.all { - tasks.named(interopProcessingTaskName).configure { enabled = false } - } - compileTaskProvider.configure { enabled = false } - } - - binaries.all { - linkTaskProvider.configure { enabled = false } - } - - mavenPublication { - tasks.withType().configureEach { - onlyIf { publication != this@mavenPublication } - } - tasks.withType().configureEach { - onlyIf { publication != this@mavenPublication } - } - } - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8e19642bb2..31cf20db25 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.19-kn" +aws-kotlin-repo-tools-version = "0.4.20-kn" # libs coroutines-version = "1.9.0" diff --git a/runtime/build.gradle.kts b/runtime/build.gradle.kts index 2c136ebdbf..393b614360 100644 --- a/runtime/build.gradle.kts +++ b/runtime/build.gradle.kts @@ -4,6 +4,7 @@ */ import aws.sdk.kotlin.gradle.dsl.configurePublishing import aws.sdk.kotlin.gradle.kmp.* +import aws.sdk.kotlin.gradle.util.typedProp import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { @@ -17,6 +18,15 @@ val sdkVersion: String by project // Apply KMP configuration from build plugin configureKmpTargets() +// Disable cross compilation if flag is set +val disableCrossCompile = typedProp("aws.kotlin.native.disableCrossCompile") == true +if (disableCrossCompile) { + logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.") + allprojects { + disableCrossCompileTargets() + } +} + // capture locally - scope issue with custom KMP plugin val libraries = libs