Skip to content

Commit 913683f

Browse files
kn: prepare for release (#1421)
2 parents 0ef0e81 + 8cfd410 commit 913683f

File tree

8 files changed

+33
-316
lines changed

8 files changed

+33
-316
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kotlin-version = "2.2.0"
33
dokka-version = "2.0.0"
44

5-
aws-kotlin-repo-tools-version = "0.4.51"
5+
aws-kotlin-repo-tools-version = "0.4.56"
66

77
# libs
88
coroutines-version = "1.10.2"
@@ -13,7 +13,7 @@ okio-version = "3.16.0"
1313
otel-version = "1.52.0"
1414
slf4j-version = "2.0.17"
1515
slf4j-v1x-version = "1.7.36"
16-
crt-kotlin-version = "0.10.3"
16+
crt-kotlin-version = "0.11.5"
1717
micrometer-version = "1.15.2"
1818
binary-compatibility-validator-version = "0.18.1"
1919
kotlin-multiplatform-bignum-version = "0.3.10"

runtime/runtime-core/build.gradle.kts

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
*/
55

66
import aws.sdk.kotlin.gradle.kmp.NATIVE_ENABLED
7-
import aws.sdk.kotlin.gradle.util.typedProp
87
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
98
import org.jetbrains.kotlin.konan.target.HostManager
10-
import java.nio.file.Files
11-
import java.nio.file.Paths
129

1310
plugins {
1411
alias(libs.plugins.kotlinx.serialization)
@@ -69,64 +66,4 @@ kotlin {
6966
}
7067
}
7168
}
72-
73-
if (NATIVE_ENABLED && HostManager.hostIsMingw) {
74-
mingwX64 {
75-
val mingwHome = findMingwHome()
76-
val defPath = layout.buildDirectory.file("cinterop/winver.def")
77-
78-
// Dynamically construct def file because of dynamic mingw paths
79-
val defFileTask by tasks.registering {
80-
outputs.file(defPath)
81-
82-
val mingwLibs = Paths.get(mingwHome, "lib").toString().replace("\\", "\\\\") // Windows path shenanigans
83-
84-
doLast {
85-
Files.writeString(
86-
defPath.get().asFile.toPath(),
87-
"""
88-
package = aws.smithy.kotlin.native.winver
89-
headers = windows.h
90-
compilerOpts = \
91-
-DUNICODE \
92-
-DWINVER=0x0601 \
93-
-D_WIN32_WINNT=0x0601 \
94-
-DWINAPI_FAMILY=3 \
95-
-DOEMRESOURCE \
96-
-Wno-incompatible-pointer-types \
97-
-Wno-deprecated-declarations
98-
libraryPaths = $mingwLibs
99-
staticLibraries = libversion.a
100-
""".trimIndent(),
101-
)
102-
}
103-
}
104-
compilations["main"].cinterops {
105-
create("winver") {
106-
val mingwIncludes = Paths.get(mingwHome, "include").toString()
107-
includeDirs(mingwIncludes)
108-
definitionFile.set(defPath)
109-
110-
// Ensure that the def file is written first
111-
tasks[interopProcessingTaskName].dependsOn(defFileTask)
112-
}
113-
}
114-
115-
// TODO clean up
116-
val compilerArgs = listOf(
117-
"-Xverbose-phases=linker", // Enable verbose linking phase from the compiler
118-
"-linker-option",
119-
"-v",
120-
)
121-
compilerOptions.freeCompilerArgs.addAll(compilerArgs)
122-
}
123-
}
12469
}
125-
126-
private fun findMingwHome(): String =
127-
System.getenv("MINGW_PREFIX")?.takeUnless { it.isBlank() }
128-
?: typedProp("mingw.prefix")
129-
?: throw IllegalStateException(
130-
"Cannot determine MinGW prefix location. Please verify MinGW is installed correctly " +
131-
"and that either the `MINGW_PREFIX` environment variable or the `mingw.prefix` Gradle property is set.",
132-
)

runtime/runtime-core/mingw/src/aws/smithy/kotlin/runtime/net/DefaultHostResolverMingw.kt

Lines changed: 0 additions & 101 deletions
This file was deleted.

runtime/runtime-core/mingw/src/aws/smithy/kotlin/runtime/util/SystemDefaultProviderMingw.kt

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55

66
package aws.smithy.kotlin.runtime.util
77

8-
import aws.smithy.kotlin.native.winver.*
8+
import aws.sdk.kotlin.crt.util.osVersionFromKernel
99
import kotlinx.cinterop.*
1010
import platform.posix.environ
11-
import platform.posix.memcpy
1211

1312
public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
1413
actual override val filePathSeparator: String = "\\"
14+
15+
// FIXME We currently get the OS info by parsing from Kernel32.dll. Is there a less hacky way we can do this?
1516
actual override fun osInfo(): OperatingSystem = OperatingSystem(OsFamily.Windows, osVersionFromKernel())
1617

1718
actual override fun getAllEnvVars(): Map<String, String> = memScoped {
1819
generateSequence(0) { it + 1 }
19-
.map { idx -> environ.get(idx)?.toKString() }
20+
.map { idx -> environ?.get(idx)?.toKString() }
2021
.takeWhile { it != null }
2122
.associate { env ->
2223
val parts = env?.split("=", limit = 2)
@@ -25,87 +26,3 @@ public actual object SystemDefaultProvider : SystemDefaultProviderBase() {
2526
}
2627
}
2728
}
28-
29-
// The functions below are adapted from C++ SDK:
30-
// https://github.com/aws/aws-sdk-cpp/blob/0e6085bf0dd9a1cb1f27d101c4cf2db6ade6f307/src/aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp#L49-L106
31-
32-
private val wordHexFormat = HexFormat {
33-
upperCase = false
34-
number {
35-
removeLeadingZeros = true
36-
minLength = 4
37-
}
38-
}
39-
40-
private data class LangCodePage(
41-
val language: UShort,
42-
val codePage: UShort,
43-
)
44-
45-
private fun osVersionFromKernel(): String? = memScoped {
46-
withFileVersionInfo("Kernel32.dll") { versionInfoPtr ->
47-
getLangCodePage(versionInfoPtr)?.let { langCodePage ->
48-
getProductVersion(versionInfoPtr, langCodePage)
49-
}
50-
}
51-
}
52-
53-
private inline fun <R> withFileVersionInfo(fileName: String, block: (CPointer<ByteVarOf<Byte>>) -> R?): R? {
54-
val blobSize = GetFileVersionInfoSizeW(fileName, null)
55-
val blob = ByteArray(blobSize.convert())
56-
blob.usePinned { pinned ->
57-
val result = GetFileVersionInfoW(fileName, 0u, blobSize, pinned.addressOf(0))
58-
return if (result == 0) {
59-
null
60-
} else {
61-
block(pinned.addressOf(0))
62-
}
63-
}
64-
}
65-
66-
private fun MemScope.getLangCodePage(versionInfoPtr: CPointer<ByteVarOf<Byte>>): LangCodePage? {
67-
// Get _any_ language pack and codepage since they should all have the same version
68-
val langAndCodePagePtr = alloc<COpaquePointerVar>()
69-
val codePageSize = alloc<UIntVar>()
70-
val result = VerQueryValueW(
71-
versionInfoPtr,
72-
"""\VarFileInfo\Translation""",
73-
langAndCodePagePtr.ptr,
74-
codePageSize.ptr,
75-
)
76-
77-
return if (result == 0) {
78-
null
79-
} else {
80-
val langAndCodePage = langAndCodePagePtr.value!!.reinterpret<UIntVar>().pointed.value
81-
val language = (langAndCodePage and 0x0000ffffu).toUShort() // low WORD
82-
val codePage = (langAndCodePage and 0xffff0000u shr 16).toUShort() // high WORD
83-
LangCodePage(language, codePage)
84-
}
85-
}
86-
87-
private fun MemScope.getProductVersion(versionInfoPtr: CPointer<ByteVarOf<Byte>>, langCodePage: LangCodePage): String? {
88-
val versionId = buildString {
89-
// Something like: \StringFileInfo\04090fb0\ProductVersion
90-
append("""\StringFileInfo\""")
91-
append(langCodePage.language.toHexString(wordHexFormat))
92-
append(langCodePage.codePage.toHexString(wordHexFormat))
93-
append("""\ProductVersion""")
94-
}
95-
96-
// Get the block corresponding to versionId
97-
val block = alloc<COpaquePointerVar>()
98-
val blockSize = alloc<UIntVar>()
99-
val result = VerQueryValueW(versionInfoPtr, versionId, block.ptr, blockSize.ptr)
100-
101-
return if (result == 0) {
102-
null
103-
} else {
104-
// Copy the bytes into a Kotlin byte array
105-
val blockBytes = ByteArray(blockSize.value.convert())
106-
blockBytes.usePinned { pinned ->
107-
memcpy(pinned.addressOf(0), block.value!!.reinterpret<ByteVar>(), blockSize.value.convert())
108-
}
109-
blockBytes.decodeToString()
110-
}
111-
}

runtime/runtime-core/mingw/test/aws/smithy/kotlin/runtime/util/SystemPlatformProviderMingwTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class SystemPlatformProviderMingwTest {
1313
@Test
1414
fun testOsInfo() = runTest {
1515
val osInfo = PlatformProvider.System.osInfo()
16-
println(osInfo)
1716
assertEquals(OsFamily.Windows, osInfo.family)
1817
assertNotNull(osInfo.version)
1918
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.smithy.kotlin.runtime.net
6+
7+
import aws.sdk.kotlin.crt.io.CrtHostAddress
8+
import aws.sdk.kotlin.crt.use
9+
import aws.sdk.kotlin.crt.io.HostResolver as CrtHostResolver
10+
11+
internal actual object DefaultHostResolver : HostResolver {
12+
actual override suspend fun resolve(hostname: String): List<HostAddress> {
13+
val results = CrtHostResolver().use {
14+
it.resolve(hostname)
15+
}
16+
return results.map { it.toHostAddress() }
17+
}
18+
19+
// No-op, matches JVM implementation
20+
actual override fun purgeCache(addr: HostAddress?) { }
21+
22+
// No-op, matches JVM implementation
23+
actual override fun reportFailure(addr: HostAddress) { }
24+
25+
private fun CrtHostAddress.toHostAddress() = HostAddress(host, IpAddr.parse(address))
26+
}

runtime/runtime-core/native/src/aws/smithy/kotlin/runtime/util/SystemDefaultProviderBase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class SystemDefaultProviderBase : PlatformProvider {
1919
val size = memScoped {
2020
val statResult = alloc<stat>()
2121
if (stat(path, statResult.ptr) != 0) return@withContext null
22+
@OptIn(UnsafeNumber::class)
2223
statResult.st_size.convert<Int>()
2324
}
2425

0 commit comments

Comments
 (0)