Skip to content

Enabled ARM support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ A runtime for executing AWS Lambda Functions written in Kotlin/Native, designed

## Supported [OS-only runtime machines](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)

- Amazon Linux 2023 (provided.al2023) with x86_64 architecture
- Amazon Linux 2 (provided.al2) with x86_64 architecture
- Amazon Linux 2023 (provided.al2023) with x86_64 or ARM architecture
- Amazon Linux 2 (provided.al2) with x86_64 or ARM architecture

## Performance

Expand Down Expand Up @@ -151,6 +151,7 @@ $ aws lambda create-function --function-name LAMBDA_FUNCTION_NAME \
--handler YOUR_MODULE_NAME.kexe \ # Important to specify the name of the Lambda executable.
--zip-file YOUR_MODULE_NAME.zip \
--runtime provided.al2023 \ # Change this to provided.al2 if you would like to use Amazon Linux 2
--architecture x86_64 \ # or arm64
--role arn:aws:iam::XXXXXXXXXXXXX:role/YOUR_LAMBDA_EXECUTION_ROLE \
--tracing-config Mode=Active
```
Expand Down
43 changes: 41 additions & 2 deletions gradle-plugin/src/main/kotlin/LambdaPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.property
import java.io.File

class LambdaPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.create("buildLambdaRelease", LambdaPackagerTask::class.java)
project.run {
val buildLambdaRelease = extensions.create(
"buildLambdaRelease",
LambdaPackagerExtension::class.java,
project
)
tasks.apply {
register("buildLambdaRelease", LambdaPackagerTask::class.java).configure {
architecture.set(buildLambdaRelease.architecture)
}
}
}
}
}

enum class Architecture(val path: String) {
LINUX_X64("linuxX64"),
LINUX_ARM64("linuxArm64");

override fun toString(): String = path
}

/**
* Gradle project level extension object definition for the LambdaPackagerTask
*
*/
open class LambdaPackagerExtension(project: Project) {
/**
* The architecture of the desired Lambda runtime, default: LINUX_X64
*/
val architecture = project.objects.property<Architecture>()

init {
architecture.set(Architecture.LINUX_X64)
}
}

abstract class LambdaPackagerTask : DefaultTask() {
@Input
val architecture: Property<Architecture> =
project.objects.property(Architecture::class.java).convention(Architecture.LINUX_X64)

@TaskAction
fun packageLambda() {
Expand All @@ -20,7 +59,7 @@ abstract class LambdaPackagerTask : DefaultTask() {
}

val buildDir = project.layout.buildDirectory
val executableDir = project.file(buildDir.dir("bin/linuxX64/releaseExecutable"))
val executableDir = project.file(buildDir.dir("bin/${architecture.get()}/releaseExecutable"))
val executable = executableDir
.listFiles()
?.first { it.name.endsWith(".kexe") }
Expand Down
2 changes: 1 addition & 1 deletion lambda-events/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
kotlin {
macosArm64()
macosX64()
//linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
linuxArm64()
linuxX64()

sourceSets {
Expand Down
2 changes: 1 addition & 1 deletion lambda-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
kotlin {
macosArm64()
macosX64()
//linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
linuxArm64()
linuxX64()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
Expand Down
6 changes: 5 additions & 1 deletion sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin {
listOf(
macosArm64(),
macosX64(),
//linuxArm64(), // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
linuxArm64(),
linuxX64(),
).forEach {
it.binaries {
Expand All @@ -27,3 +27,7 @@ kotlin {
}
}
}

buildLambdaRelease {
architecture.set(Architecture.LINUX_X64) // or Architecture.LINUX_ARM64
}