From b1ba9324d176e905d7ffbcce31e0e47c95c792b6 Mon Sep 17 00:00:00 2001 From: Viacheslav Ivanovichev Date: Wed, 25 Sep 2024 22:40:59 +0200 Subject: [PATCH] Try to set compiler options globally --- build.gradle.kts | 7 +- lambda-runtime/build.gradle.kts | 15 ++--- .../lambda/runtime/LambdaRuntimeTest.kt | 65 ------------------- sample/build.gradle.kts | 1 - 4 files changed, 10 insertions(+), 78 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 424e7c0..e594465 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask + plugins { // this is necessary to avoid the plugins to be loaded multiple times // in each subproject's classloader @@ -10,11 +12,10 @@ allprojects { group = "io.github.trueangle" version = "0.0.2" } -/* -tasks.withType { +tasks.withType().configureEach { compilerOptions { freeCompilerArgs.add("-Xallocator=std") freeCompilerArgs.add("-Xruntime-logs=gc=info") } -}*/ +} \ No newline at end of file diff --git a/lambda-runtime/build.gradle.kts b/lambda-runtime/build.gradle.kts index 13e8896..994fd15 100644 --- a/lambda-runtime/build.gradle.kts +++ b/lambda-runtime/build.gradle.kts @@ -1,5 +1,4 @@ import dev.mokkery.MockMode -import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType plugins { alias(libs.plugins.kotlin.multiplatform) @@ -10,18 +9,16 @@ plugins { } kotlin { - macosArm64 { - binaries { - getTest(NativeBuildType.DEBUG).freeCompilerArgs += listOf("-Xruntime-logs=gc=info", "-Xallocator=std") - executable { - freeCompilerArgs += listOf("-Xallocator=std") - } - } - } + macosArm64() macosX64() //linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native linuxX64() + /* @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + freeCompilerArgs.add("-Xallocator=std") + }*/ + sourceSets { commonMain.dependencies { implementation(projects.lambdaEvents) diff --git a/lambda-runtime/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/LambdaRuntimeTest.kt b/lambda-runtime/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/LambdaRuntimeTest.kt index 1354578..50ba3c5 100644 --- a/lambda-runtime/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/LambdaRuntimeTest.kt +++ b/lambda-runtime/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/LambdaRuntimeTest.kt @@ -48,9 +48,6 @@ import kotlinx.coroutines.test.runTest import kotlinx.serialization.json.Json import platform.posix.getenv import platform.posix.setenv -import kotlin.experimental.ExperimentalNativeApi -import kotlin.native.runtime.GC -import kotlin.native.runtime.NativeRuntimeApi import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertFailsWith @@ -361,68 +358,6 @@ class LambdaRuntimeTest { verify(not) { lambdaRunner.env.terminate() } } - @OptIn(NativeRuntimeApi::class, ExperimentalStdlibApi::class, ExperimentalNativeApi::class) - @Test - fun `Validate leaks`() = runTest { - val invocationCount = 3 - var invocationIndex = 0 - val events = buildList(invocationCount) { - repeat(invocationCount) { add("Hello world") } - } - - val lambdaRunner = createRunner(MockEngine { request -> - val path = request.url.encodedPath - when { - path.contains("invocation/next") -> { - if (invocationIndex >= invocationCount) { - respondError(HttpStatusCode.InternalServerError, headers = headers { - append(HttpHeaders.ContentType, "application/json") - append("Lambda-Runtime-Aws-Request-Id", context.awsRequestId) - append("Lambda-Runtime-Deadline-Ms", context.deadlineTimeInMs.toString()) - append("Lambda-Runtime-Invoked-Function-Arn", context.invokedFunctionArn) - }) - } else { - respondNextEventSuccess(events[invocationIndex++]) - } - } - - path.contains("/invocation/${context.awsRequestId}/response") -> respond( - content = ByteReadChannel("Ok"), - status = HttpStatusCode.Accepted, - headers = headersOf(HttpHeaders.ContentType, "application/json") - ) - - else -> respondBadRequest() - } - }) - - val handler = object : LambdaBufferedHandler { - override suspend fun handleRequest(input: String, context: Context): String = "Hello" - } - - assertFailsWith { - lambdaRunner.run { handler } - } - - GC.collect() - GC.lastGCInfo?.let {gcInfo-> - println( - "Heap Size Before: ${ - gcInfo.memoryUsageBefore.map { - it.key + " - " + it.value.totalObjectsSizeBytes / 1024 / 1024 - } - }" - ) - println( - "Heap Size After: ${ - gcInfo.memoryUsageAfter.map { - it.key + " - " + it.value.totalObjectsSizeBytes / 1024 / 1024 - } - }" - ) - } - } - @OptIn(ExperimentalForeignApi::class) private fun mockEnvironment() { if (getenv(AWS_LAMBDA_FUNCTION_NAME)?.toKString().isNullOrEmpty()) { diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index a854e23..7550ee1 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -14,7 +14,6 @@ kotlin { it.binaries { executable { entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main" - freeCompilerArgs += listOf("-Xallocator=std") } } }