Skip to content

Commit

Permalink
Add GraalVM native-image configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
n3o59hf committed Dec 22, 2021
1 parent af945be commit fa66499
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
20 changes: 17 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

plugins {
java
id("org.jetbrains.kotlin.jvm") version "1.6.0"
id("org.jetbrains.kotlin.jvm") version "1.6.10"
id("org.graalvm.buildtools.native") version "0.9.9"
application
}

Expand All @@ -11,9 +11,23 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
}

application {
mainClass.set("lv.n3o.aoc2021.Main")
}

tasks.named("run").configure {
outputs.upToDateWhen { false }
}

graalvmNative {
binaries {
named("main") {
agent {
enabled.set(true)
}
}
}
}
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ See [AoC 2021](https://adventofcode.com/2021/) for puzzles.

Inputs are usually defined in input files in `src/main/resources/` (`i{nn}.txt` wheren `{nn}` is 0-padded day number).

To run all, use `./gradlew run` (or `gradlew.bat run` on Windows)
To run all, use `./gradlew run` (or `gradlew.bat run` on Windows)

To compile native image using GraalVM, run `nativeCompile` task. Result will be placed in `build/native/nativeCompile/`
2 changes: 0 additions & 2 deletions settings.gradle

This file was deleted.

7 changes: 7 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "aoc2021"
2 changes: 1 addition & 1 deletion src/main/kotlin/lv/n3o/aoc2021/Task.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class Input {

class ClasspathInput(val name: String) : Input() {
override fun readInput(): String {
with(this::class.java.classLoader.getResourceAsStream(name)!!) {
with(javaClass.getResourceAsStream(name) ?: ClassLoader.getSystemClassLoader().getResourceAsStream(name)) {
return bufferedReader(Charsets.UTF_8).readText()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/lv/n3o/aoc2021/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private const val REPEAT_RUNS = 1
private fun ci(number: Int, expectedA: String, expectedB: String): TestCase {
val paddedNumber = "$number".padStart(2, '0')
val className = "T$paddedNumber"
val inputFile = "i$paddedNumber.txt"
val inputFile = "/i$paddedNumber.txt"
val taskClass = Class.forName("lv.n3o.aoc2021.tasks.$className")
val constructor: (Input) -> Task =
{ input -> taskClass.getConstructor(Input::class.java).newInstance(input) as Task }
Expand Down

0 comments on commit fa66499

Please sign in to comment.