Skip to content

Commit 5654cc9

Browse files
authored
Enabled ARM support (#8)
Enabled ARM support
1 parent 126835f commit 5654cc9

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ A runtime for executing AWS Lambda Functions written in Kotlin/Native, designed
1111

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

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

1717
## Performance
1818

@@ -151,6 +151,7 @@ $ aws lambda create-function --function-name LAMBDA_FUNCTION_NAME \
151151
--handler YOUR_MODULE_NAME.kexe \ # Important to specify the name of the Lambda executable.
152152
--zip-file YOUR_MODULE_NAME.zip \
153153
--runtime provided.al2023 \ # Change this to provided.al2 if you would like to use Amazon Linux 2
154+
--architecture x86_64 \ # or arm64
154155
--role arn:aws:iam::XXXXXXXXXXXXX:role/YOUR_LAMBDA_EXECUTION_ROLE \
155156
--tracing-config Mode=Active
156157
```

gradle-plugin/src/main/kotlin/LambdaPlugin.kt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
import org.gradle.api.DefaultTask
22
import org.gradle.api.Plugin
33
import org.gradle.api.Project
4+
import org.gradle.api.provider.Property
5+
import org.gradle.api.tasks.Input
46
import org.gradle.api.tasks.TaskAction
7+
import org.gradle.kotlin.dsl.property
58
import java.io.File
69

710
class LambdaPlugin : Plugin<Project> {
811
override fun apply(project: Project) {
9-
project.tasks.create("buildLambdaRelease", LambdaPackagerTask::class.java)
12+
project.run {
13+
val buildLambdaRelease = extensions.create(
14+
"buildLambdaRelease",
15+
LambdaPackagerExtension::class.java,
16+
project
17+
)
18+
tasks.apply {
19+
register("buildLambdaRelease", LambdaPackagerTask::class.java).configure {
20+
architecture.set(buildLambdaRelease.architecture)
21+
}
22+
}
23+
}
24+
}
25+
}
26+
27+
enum class Architecture(val path: String) {
28+
LINUX_X64("linuxX64"),
29+
LINUX_ARM64("linuxArm64");
30+
31+
override fun toString(): String = path
32+
}
33+
34+
/**
35+
* Gradle project level extension object definition for the LambdaPackagerTask
36+
*
37+
*/
38+
open class LambdaPackagerExtension(project: Project) {
39+
/**
40+
* The architecture of the desired Lambda runtime, default: LINUX_X64
41+
*/
42+
val architecture = project.objects.property<Architecture>()
43+
44+
init {
45+
architecture.set(Architecture.LINUX_X64)
1046
}
1147
}
1248

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

1554
@TaskAction
1655
fun packageLambda() {
@@ -20,7 +59,7 @@ abstract class LambdaPackagerTask : DefaultTask() {
2059
}
2160

2261
val buildDir = project.layout.buildDirectory
23-
val executableDir = project.file(buildDir.dir("bin/linuxX64/releaseExecutable"))
62+
val executableDir = project.file(buildDir.dir("bin/${architecture.get()}/releaseExecutable"))
2463
val executable = executableDir
2564
.listFiles()
2665
?.first { it.name.endsWith(".kexe") }

lambda-events/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
kotlin {
99
macosArm64()
1010
macosX64()
11-
//linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
11+
linuxArm64()
1212
linuxX64()
1313

1414
sourceSets {

lambda-runtime/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
kotlin {
1515
macosArm64()
1616
macosX64()
17-
//linuxArm64() // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
17+
linuxArm64()
1818
linuxX64()
1919

2020
@OptIn(ExperimentalKotlinGradlePluginApi::class)

sample/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ kotlin {
88
listOf(
99
macosArm64(),
1010
macosX64(),
11-
//linuxArm64(), // https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
11+
linuxArm64(),
1212
linuxX64(),
1313
).forEach {
1414
it.binaries {
@@ -27,3 +27,7 @@ kotlin {
2727
}
2828
}
2929
}
30+
31+
buildLambdaRelease {
32+
architecture.set(Architecture.LINUX_X64) // or Architecture.LINUX_ARM64
33+
}

0 commit comments

Comments
 (0)