Skip to content

Commit f9d5104

Browse files
committed
kn: checksum bindings (#1182)
1 parent b79d37b commit f9d5104

File tree

23 files changed

+279
-86
lines changed

23 files changed

+279
-86
lines changed

.github/actions/setup-build/action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@ description: >
55
runs:
66
using: composite
77
steps:
8-
- name: Checkout tools
8+
- name: Extract aws-kotlin-repo-tools version
9+
working-directory: ./smithy-kotlin
10+
shell: bash
11+
run: |
12+
export AWS_KOTLIN_REPO_TOOLS_VERSION=$(grep '^aws-kotlin-repo-tools-version' ./gradle/libs.versions.toml | sed -E 's/.*= "(.*)"/\1/')
13+
echo "Using aws-kotlin-repo-tools version $AWS_KOTLIN_REPO_TOOLS_VERSION"
14+
echo "aws_kotlin_repo_tools_version=$AWS_KOTLIN_REPO_TOOLS_VERSION" >> $GITHUB_ENV
15+
16+
- name: Checkout aws-kotlin-repo-tools
917
uses: actions/checkout@v4
1018
with:
1119
path: 'aws-kotlin-repo-tools'
1220
repository: 'awslabs/aws-kotlin-repo-tools'
21+
ref: ${{ env.aws_kotlin_repo_tools_version }}
1322
sparse-checkout: |
1423
.github
1524
@@ -19,6 +28,7 @@ runs:
1928
# checkout aws-crt-kotlin as a sibling which will automatically make it an included build
2029
path: 'aws-crt-kotlin'
2130
repository: 'awslabs/aws-crt-kotlin'
31+
submodules: 'true'
2232

2333
# Cache the Kotlin/Native toolchain based on the input Kotlin version from version catalog
2434
# see https://kotlinlang.org/docs/native-improving-compilation-time.html
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
"""
7+
Run precompiled Kotlin/Native test binaries in a Docker container for a specific Linux distribution and architecture.
8+
9+
This requires Docker multiarch support, see https://docs.docker.com/build/building/multi-platform/ and https://github.com/multiarch/qemu-user-static
10+
In GitHub we use a provided action for this: https://github.com/docker/setup-qemu-action
11+
12+
Locally you would need to run one of:
13+
14+
`docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes`
15+
16+
OR
17+
18+
`docker run --privileged --rm tonistiigi/binfmt --install all`
19+
"""
20+
21+
import argparse
22+
import os
23+
import subprocess
24+
import shlex
25+
import shutil
26+
27+
VERBOSE = False
28+
29+
DISTRO_TO_IMAGE_NAME = {
30+
"ubuntu-22.04": "public.ecr.aws/lts/ubuntu:22.04_stable",
31+
"al2023": "public.ecr.aws/amazonlinux/amazonlinux:2023",
32+
"al2": "public.ecr.aws/amazonlinux/amazonlinux:2"
33+
}
34+
35+
DOCKER_PLATFORM_BY_ARCH = {
36+
"x64": "linux/amd64",
37+
"arm64": "linux/arm64"
38+
}
39+
40+
41+
def vprint(message):
42+
global VERBOSE
43+
if VERBOSE:
44+
print(message)
45+
46+
47+
def running_in_github_action():
48+
"""
49+
Test if currently running in a GitHub action or running locally
50+
:return: True if running in GH, False otherwise
51+
"""
52+
return "GITHUB_WORKFLOW" in os.environ
53+
54+
55+
def shell(command, cwd=None, check=True, capture_output=False):
56+
"""
57+
Run a command
58+
:param command: command to run
59+
:param cwd: the current working directory to change to before executing the command
60+
:param check: flag indicating if the status code should be checked. When true an exception will be
61+
thrown if the command exits with a non-zero exit status.
62+
:returns: the subprocess CompletedProcess output
63+
"""
64+
vprint(f"running `{command}`")
65+
return subprocess.run(command, shell=True, check=check, cwd=cwd, capture_output=capture_output)
66+
67+
68+
def oci_executable():
69+
"""
70+
Attempt to find the OCI container executor used to build and run docker containers
71+
"""
72+
oci_exe = os.environ.get('OCI_EXE')
73+
if oci_exe is not None:
74+
return oci_exe
75+
76+
executors = ['finch', 'podman', 'docker']
77+
78+
for exe in executors:
79+
if shutil.which(exe) is not None:
80+
return exe
81+
82+
print("cannot find container executor")
83+
exit(1)
84+
85+
86+
def run_docker_test(opts):
87+
"""
88+
Run a docker test for a precompiled Kotlin/Native binary
89+
90+
:param opts: the parsed command line options
91+
"""
92+
platform = DOCKER_PLATFORM_BY_ARCH[opts.arch]
93+
oci_exe = oci_executable()
94+
95+
test_bin_dir = os.path.abspath(opts.test_bin_dir)
96+
image_name = DISTRO_TO_IMAGE_NAME[opts.distro]
97+
path_to_exe = f'./linux{opts.arch.capitalize()}/debugTest/test.kexe'
98+
99+
cmd = [
100+
oci_exe,
101+
'run',
102+
'--rm',
103+
f'-v{test_bin_dir}:/test',
104+
]
105+
if not opts.no_system_certs:
106+
cmd.append(f'-v/etc/ssl:/etc/ssl')
107+
108+
cmd.extend(
109+
[
110+
'-w/test',
111+
'-e DEBIAN_FRONTEND=noninteractive',
112+
'--platform',
113+
platform,
114+
image_name,
115+
path_to_exe,
116+
]
117+
)
118+
119+
cmd = shlex.join(cmd)
120+
print(cmd)
121+
shell(cmd)
122+
123+
124+
def create_cli():
125+
parser = argparse.ArgumentParser(
126+
prog="run-container-test",
127+
description="Run cross platform test binaries in a container",
128+
formatter_class=argparse.ArgumentDefaultsHelpFormatter
129+
)
130+
131+
parser.add_argument("-v", "--verbose", help="enable verbose output", action="store_true")
132+
133+
parser.add_argument("--distro", required=True, choices=DISTRO_TO_IMAGE_NAME.keys(), help="the distribution name to run the task on")
134+
parser.add_argument("--arch", required=True, choices=DOCKER_PLATFORM_BY_ARCH.keys(), help="the architecture to use")
135+
parser.add_argument("--test-bin-dir", required=True, help="the path to the test binary directory root")
136+
parser.add_argument("--no-system-certs", action='store_true', help="disable mounting system certificates into the container")
137+
138+
return parser
139+
140+
141+
def main():
142+
cli = create_cli()
143+
opts = cli.parse_args()
144+
if opts.verbose:
145+
global VERBOSE
146+
VERBOSE = True
147+
148+
run_docker_test(opts)
149+
150+
151+
if __name__ == '__main__':
152+
main()

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
# FIXME K2. Re-enable warnings as errors after this warning is removed: https://youtrack.jetbrains.com/issue/KT-68532
6868
# echo "kotlinWarningsAsErrors=true" >> $GITHUB_WORKSPACE/local.properties
6969
./gradlew apiCheck
70-
./gradlew -Paws.sdk.kotlin.crt.disableCrossCompile=true build
70+
./gradlew -Paws.sdk.kotlin.crt.disableCrossCompile=true -Paws.kotlin.native.disableCrossCompile=true build
7171
7272
- name: Save Test Reports
7373
if: failure()
@@ -126,7 +126,7 @@ jobs:
126126
working-directory: ./smithy-kotlin
127127
run: |
128128
./gradlew apiCheck
129-
./gradlew -P"aws.sdk.kotlin.crt.disableCrossCompile"=true build
129+
./gradlew -P"aws.kotlin.native=false" build
130130
131131
- name: Save Test Reports
132132
if: failure()

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,25 @@ If you discover a potential security issue in this project we ask that you notif
223223
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
224224

225225
We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
226+
227+
## Kotlin/Native
228+
Support for Kotlin/Native is in active development. The following sections cover how to effectively test your work.
229+
230+
### Linux/Unix
231+
232+
#### Testing Different Linux Distros and Architectures
233+
234+
1. Build the test executable(s) for the architecture(s) you want to test.
235+
236+
```sh
237+
# build specific arch
238+
./gradlew linuxX64TestBinaries
239+
```
240+
241+
2. Use the `run-container-test.py` helper script to execute tests locally. Change the directory as needed.
242+
243+
```sh
244+
OCI_EXE=docker python3 .github/scripts/run-container-test.py --distro al2 --arch x64 --test-bin-dir ./runtime/runtime-core/build/bin
245+
```
246+
247+
See the usage/help for different distributions provided: `python3 .github/scripts/run-container.py -h`

bom/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
77
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
88
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
99
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
10-
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
11-
import java.util.*
1210

1311
plugins {
1412
`maven-publish`
@@ -52,7 +50,6 @@ fun createBomConstraintsAndVersionCatalog() {
5250

5351
fun Project.artifactId(target: KotlinTarget): String = when (target) {
5452
is KotlinMetadataTarget -> name
55-
is KotlinJsTarget -> "$name-js"
5653
else -> "$name-${target.targetName.lowercase()}"
5754
}
5855

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kotlin-version = "2.0.21"
33
dokka-version = "1.9.10"
44

5-
aws-kotlin-repo-tools-version = "0.4.15-kn"
5+
aws-kotlin-repo-tools-version = "0.4.20-kn"
66

77
# libs
88
coroutines-version = "1.9.0"
@@ -96,6 +96,7 @@ ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor-
9696
ktor-server-jetty-jakarta = { module = "io.ktor:ktor-server-jetty-jakarta", version.ref = "ktor-version" }
9797
ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor-version" }
9898
ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor-version" }
99+
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor-version" }
99100

100101
kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml-version" }
101102
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup-version" }

runtime/auth/aws-signing-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/auth/awssigning/crt/CrtSigningSuiteTest.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,4 @@ import aws.smithy.kotlin.runtime.auth.awssigning.tests.SigningSuiteTestBase
99

1010
class CrtSigningSuiteTest : SigningSuiteTestBase() {
1111
override val signer: AwsSigner = CrtAwsSigner
12-
13-
override val disabledTests = super.disabledTests + setOf(
14-
// FIXME - Signature mismatch possibly related to https://github.com/awslabs/aws-crt-java/pull/419. Needs
15-
// investigation.
16-
"get-utf8",
17-
)
1812
}

runtime/build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import aws.sdk.kotlin.gradle.dsl.configurePublishing
66
import aws.sdk.kotlin.gradle.kmp.*
7+
import aws.sdk.kotlin.gradle.util.typedProp
78
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
89

910
plugins {
@@ -17,6 +18,15 @@ val sdkVersion: String by project
1718
// Apply KMP configuration from build plugin
1819
configureKmpTargets()
1920

21+
// Disable cross compilation if flag is set
22+
val disableCrossCompile = typedProp<Boolean>("aws.kotlin.native.disableCrossCompile") == true
23+
if (disableCrossCompile) {
24+
logger.warn("aws.kotlin.native.disableCrossCompile=true: Cross compilation is disabled.")
25+
allprojects {
26+
disableCrossCompileTargets()
27+
}
28+
}
29+
2030
// capture locally - scope issue with custom KMP plugin
2131
val libraries = libs
2232

runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/AsyncStressTest.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import aws.smithy.kotlin.runtime.http.request.url
1313
import aws.smithy.kotlin.runtime.httptest.TestWithLocalServer
1414
import aws.smithy.kotlin.runtime.net.Host
1515
import aws.smithy.kotlin.runtime.net.Scheme
16-
import aws.smithy.kotlin.runtime.testing.IgnoreWindows
1716
import io.ktor.server.cio.*
1817
import io.ktor.server.engine.*
1918
import io.ktor.server.response.*
@@ -25,9 +24,7 @@ import kotlinx.coroutines.yield
2524
import kotlin.test.Test
2625
import kotlin.time.Duration.Companion.seconds
2726

28-
// FIXME This test implements [TestWithLocalServer] which is JVM-only.
2927
class AsyncStressTest : TestWithLocalServer() {
30-
3128
override val server = embeddedServer(CIO, serverPort) {
3229
routing {
3330
get("/largeResponse") {
@@ -37,9 +34,8 @@ class AsyncStressTest : TestWithLocalServer() {
3734
call.respondText(text.repeat(respSize / text.length))
3835
}
3936
}
40-
}
37+
}.start()
4138

42-
@IgnoreWindows("FIXME - times out after upgrade to kotlinx.coroutines 1.6.0")
4339
@Test
4440
fun testStreamNotConsumed() = runBlocking {
4541
// test that filling the stream window and not consuming the body stream still cleans up resources

runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/test/aws/smithy/kotlin/runtime/http/engine/crt/SendChunkedBodyTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SendChunkedBodyTest {
3333

3434
val chunkedBytes = """
3535
100;chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(256)}\r\n\r\n
36-
""".trimIndent().toByteArray()
36+
""".trimIndent().encodeToByteArray()
3737

3838
val source = chunkedBytes.source()
3939

@@ -52,7 +52,7 @@ class SendChunkedBodyTest {
5252

5353
val chunkedBytes = """
5454
${chunkSize.toString(16)};chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(chunkSize)}\r\n\r\n
55-
""".trimIndent().toByteArray()
55+
""".trimIndent().encodeToByteArray()
5656

5757
val source = chunkedBytes.source()
5858

@@ -71,7 +71,7 @@ class SendChunkedBodyTest {
7171

7272
val chunkedBytes = """
7373
100;chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(256)}\r\n\r\n
74-
""".trimIndent().toByteArray()
74+
""".trimIndent().encodeToByteArray()
7575

7676
val channel = SdkByteReadChannel(chunkedBytes)
7777

@@ -91,7 +91,7 @@ class SendChunkedBodyTest {
9191

9292
val chunkedBytes = """
9393
${chunkSize.toString(16)};chunk-signature=${"0".repeat(64)}\r\n${"0".repeat(chunkSize)}\r\n\r\n
94-
""".trimIndent().toByteArray()
94+
""".trimIndent().encodeToByteArray()
9595

9696
val channel = SdkByteReadChannel(chunkedBytes)
9797

0 commit comments

Comments
 (0)