Skip to content

Commit b1ba932

Browse files
committed
Try to set compiler options globally
1 parent 961a60f commit b1ba932

File tree

4 files changed

+10
-78
lines changed

4 files changed

+10
-78
lines changed

build.gradle.kts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
2+
13
plugins {
24
// this is necessary to avoid the plugins to be loaded multiple times
35
// in each subproject's classloader
@@ -10,11 +12,10 @@ allprojects {
1012
group = "io.github.trueangle"
1113
version = "0.0.2"
1214
}
13-
/*
1415

15-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
16+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
1617
compilerOptions {
1718
freeCompilerArgs.add("-Xallocator=std")
1819
freeCompilerArgs.add("-Xruntime-logs=gc=info")
1920
}
20-
}*/
21+
}

lambda-runtime/build.gradle.kts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dev.mokkery.MockMode
2-
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
32

43
plugins {
54
alias(libs.plugins.kotlin.multiplatform)
@@ -10,18 +9,16 @@ plugins {
109
}
1110

1211
kotlin {
13-
macosArm64 {
14-
binaries {
15-
getTest(NativeBuildType.DEBUG).freeCompilerArgs += listOf("-Xruntime-logs=gc=info", "-Xallocator=std")
16-
executable {
17-
freeCompilerArgs += listOf("-Xallocator=std")
18-
}
19-
}
20-
}
12+
macosArm64()
2113
macosX64()
2214
//linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
2315
linuxX64()
2416

17+
/* @OptIn(ExperimentalKotlinGradlePluginApi::class)
18+
compilerOptions {
19+
freeCompilerArgs.add("-Xallocator=std")
20+
}*/
21+
2522
sourceSets {
2623
commonMain.dependencies {
2724
implementation(projects.lambdaEvents)

lambda-runtime/src/nativeTest/kotlin/io/github/trueangle/knative/lambda/runtime/LambdaRuntimeTest.kt

-65
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ import kotlinx.coroutines.test.runTest
4848
import kotlinx.serialization.json.Json
4949
import platform.posix.getenv
5050
import platform.posix.setenv
51-
import kotlin.experimental.ExperimentalNativeApi
52-
import kotlin.native.runtime.GC
53-
import kotlin.native.runtime.NativeRuntimeApi
5451
import kotlin.test.BeforeTest
5552
import kotlin.test.Test
5653
import kotlin.test.assertFailsWith
@@ -361,68 +358,6 @@ class LambdaRuntimeTest {
361358
verify(not) { lambdaRunner.env.terminate() }
362359
}
363360

364-
@OptIn(NativeRuntimeApi::class, ExperimentalStdlibApi::class, ExperimentalNativeApi::class)
365-
@Test
366-
fun `Validate leaks`() = runTest {
367-
val invocationCount = 3
368-
var invocationIndex = 0
369-
val events = buildList(invocationCount) {
370-
repeat(invocationCount) { add("Hello world") }
371-
}
372-
373-
val lambdaRunner = createRunner(MockEngine { request ->
374-
val path = request.url.encodedPath
375-
when {
376-
path.contains("invocation/next") -> {
377-
if (invocationIndex >= invocationCount) {
378-
respondError(HttpStatusCode.InternalServerError, headers = headers {
379-
append(HttpHeaders.ContentType, "application/json")
380-
append("Lambda-Runtime-Aws-Request-Id", context.awsRequestId)
381-
append("Lambda-Runtime-Deadline-Ms", context.deadlineTimeInMs.toString())
382-
append("Lambda-Runtime-Invoked-Function-Arn", context.invokedFunctionArn)
383-
})
384-
} else {
385-
respondNextEventSuccess(events[invocationIndex++])
386-
}
387-
}
388-
389-
path.contains("/invocation/${context.awsRequestId}/response") -> respond(
390-
content = ByteReadChannel("Ok"),
391-
status = HttpStatusCode.Accepted,
392-
headers = headersOf(HttpHeaders.ContentType, "application/json")
393-
)
394-
395-
else -> respondBadRequest()
396-
}
397-
})
398-
399-
val handler = object : LambdaBufferedHandler<String, String> {
400-
override suspend fun handleRequest(input: String, context: Context): String = "Hello"
401-
}
402-
403-
assertFailsWith<TerminateException> {
404-
lambdaRunner.run { handler }
405-
}
406-
407-
GC.collect()
408-
GC.lastGCInfo?.let {gcInfo->
409-
println(
410-
"Heap Size Before: ${
411-
gcInfo.memoryUsageBefore.map {
412-
it.key + " - " + it.value.totalObjectsSizeBytes / 1024 / 1024
413-
}
414-
}"
415-
)
416-
println(
417-
"Heap Size After: ${
418-
gcInfo.memoryUsageAfter.map {
419-
it.key + " - " + it.value.totalObjectsSizeBytes / 1024 / 1024
420-
}
421-
}"
422-
)
423-
}
424-
}
425-
426361
@OptIn(ExperimentalForeignApi::class)
427362
private fun mockEnvironment() {
428363
if (getenv(AWS_LAMBDA_FUNCTION_NAME)?.toKString().isNullOrEmpty()) {

sample/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ kotlin {
1414
it.binaries {
1515
executable {
1616
entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main"
17-
freeCompilerArgs += listOf("-Xallocator=std")
1817
}
1918
}
2019
}

0 commit comments

Comments
 (0)