Skip to content

Commit ef8137a

Browse files
authored
fix: use same toolchain on arm that k/n does (#95)
* fix glibc version to 2.19 by using manylinux images. * fix aarch64 to not use `moutline-atomics` by using the same toolchain that K/N is using
1 parent 700af3d commit ef8137a

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ aws_use_package(aws-c-http)
103103
aws_use_package(aws-c-auth)
104104
aws_use_package(aws-checksums)
105105

106+
# TODO - bundling static libraries into single static library composed of all the static libraries
107+
# to enable IPO/LTO. See also:
108+
# * https://cristianadam.eu/20190501/bundling-together-static-libraries-with-cmake/
109+
# * https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html

aws-crt-kotlin/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
import aws.sdk.kotlin.gradle.crt.CMakeBuildType
56
import aws.sdk.kotlin.gradle.crt.cmakeInstallDir
67
import aws.sdk.kotlin.gradle.crt.configureCrtCMakeBuild
78
import aws.sdk.kotlin.gradle.crt.disableCrossCompileTargets
@@ -10,6 +11,7 @@ import aws.sdk.kotlin.gradle.kmp.IDEA_ACTIVE
1011
import aws.sdk.kotlin.gradle.kmp.configureKmpTargets
1112
import aws.sdk.kotlin.gradle.util.typedProp
1213
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
14+
import org.jetbrains.kotlin.konan.target.KonanTarget
1315

1416
plugins {
1517
alias(libs.plugins.kotlin.multiplatform)
@@ -23,7 +25,7 @@ version = sdkVersion
2325
description = "Kotlin Multiplatform bindings for AWS SDK Common Runtime"
2426

2527
// See: https://kotlinlang.org/docs/reference/opt-in-requirements.html#opting-in-to-using-api
26-
val optinAnnotations = listOf("kotlin.RequiresOptIn")
28+
val optinAnnotations = listOf("kotlin.RequiresOptIn", "kotlinx.cinterop.ExperimentalForeignApi")
2729

2830
// KMP configuration from build plugin
2931
configureKmpTargets()
@@ -136,7 +138,7 @@ kotlin {
136138
targets.withType<KotlinNativeTarget> {
137139
val knTarget = this
138140
logger.info("configuring $knTarget: ${knTarget.name}")
139-
val cmakeInstallTask = configureCrtCMakeBuild(knTarget)
141+
val cmakeInstallTask = configureCrtCMakeBuild(knTarget, CMakeBuildType.Release)
140142
val targetInstallDir = project.cmakeInstallDir(knTarget)
141143
val headerDir = targetInstallDir.resolve("include")
142144
val libDir = targetInstallDir.resolve("lib")
@@ -148,6 +150,7 @@ kotlin {
148150
defFile("$interopDir/crt.def")
149151
includeDirs(headerDir)
150152
compilerOpts("-L${libDir.absolutePath}")
153+
extraOpts("-libraryPath", libDir.absolutePath)
151154
}
152155

153156
// cinterop tasks processes header files which requires the corresponding CMake build/install to run
@@ -158,6 +161,7 @@ kotlin {
158161
}
159162

160163
compilations["test"].compilerOptions.configure {
164+
// TODO - can we remove this if we are bundling the static libs
161165
freeCompilerArgs.addAll(listOf("-linker-options", "-L${libDir.absolutePath}"))
162166
}
163167
}

aws-crt-kotlin/native/interop/crt.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ linkerOpts = -laws-c-common -laws-c-cal -laws-c-io -laws-c-http -laws-c-compress
1212
linkerOpts.osx = -framework Security
1313
linkerOpts.linux = -ls2n -lcrypto
1414

15+
staticLibraries = libaws-c-common.a \
16+
libaws-c-cal.a \
17+
libaws-c-io.a \
18+
libaws-c-compression.a \
19+
libaws-c-sdkutils.a \
20+
libaws-c-http.a \
21+
libaws-c-auth.a \
22+
libaws-checksums.a
23+
24+
staticLibraries.linux = libs2n.a libcrypto.a
25+
1526
---
1627

1728
// prototypes
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
FROM dockcross/linux-arm64:20240104-6eda627
1+
FROM dockcross/manylinux2014-aarch64:20240104-6eda627
22
ENV DEFAULT_DOCKCROSS_IMAGE aws-crt-kotlin/linux-arm64:latest
3+
4+
RUN curl -LJo konan-toolchain.tar.gz https://download.jetbrains.com/kotlin/native/aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2.tar.gz
5+
# Remove the cross compile root from the original image and put our own one based
6+
# on the K/N toolchain.
7+
RUN mv /usr/xcc/aarch64-unknown-linux-gnu /tmp/original && \
8+
mkdir -p /usr/xcc/aarch64-unknown-linux-gnu && \
9+
tar -xzf konan-toolchain.tar.gz -C /usr/xcc/aarch64-unknown-linux-gnu --strip-components=1 && \
10+
cp /tmp/original/Toolchain.cmake /usr/xcc/aarch64-unknown-linux-gnu && \
11+
rm -rf /tmp/original

docker-images/linux-x64/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
FROM dockcross/linux-x64:20240104-6eda627
1+
# We need glibc <= 2.19, see https://youtrack.jetbrains.com/issue/KT-47061
2+
# TODO - explore creating a custom image using the same toolchain K/N uses
3+
# see https://github.com/JetBrains/kotlin/tree/master/kotlin-native/tools/toolchain_builder
4+
# OR via https://download.jetbrains.com/kotlin/native/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2.tar.gz
5+
FROM dockcross/manylinux2014-x64:20240104-6eda627
26
ENV DEFAULT_DOCKCROSS_IMAGE aws-crt-kotlin/linux-x64:latest

0 commit comments

Comments
 (0)