Skip to content

Commit

Permalink
Try to set compiler options globally
Browse files Browse the repository at this point in the history
  • Loading branch information
trueangle committed Sep 25, 2024
1 parent 961a60f commit b1ba932
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 78 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,11 +12,10 @@ allprojects {
group = "io.github.trueangle"
version = "0.0.2"
}
/*

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xallocator=std")
freeCompilerArgs.add("-Xruntime-logs=gc=info")
}
}*/
}
15 changes: 6 additions & 9 deletions lambda-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dev.mokkery.MockMode
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String, String> {
override suspend fun handleRequest(input: String, context: Context): String = "Hello"
}

assertFailsWith<TerminateException> {
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()) {
Expand Down
1 change: 0 additions & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ kotlin {
it.binaries {
executable {
entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main"
freeCompilerArgs += listOf("-Xallocator=std")
}
}
}
Expand Down

0 comments on commit b1ba932

Please sign in to comment.