Skip to content

Commit

Permalink
chore: better build avoidance for native builds
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Feb 21, 2024
1 parent bd56dcf commit 995ae76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
6 changes: 2 additions & 4 deletions build-logic/src/main/kotlin/pklGraalVm.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ val verifyGraalVm by tasks.registering(Verify::class) {
// minimize chances of corruption by extract-to-random-dir-and-flip-symlink
val installGraalVm by tasks.registering {
dependsOn(verifyGraalVm)

onlyIf {
!installDir.exists()
}
outputs.cacheIf { installDir.exists() }
onlyIf { !installDir.exists() }

doLast {
val distroDir = "$homeDir/${UUID.randomUUID()}"
Expand Down
33 changes: 20 additions & 13 deletions pkl-cli/pkl-cli.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ val pgoInstrument = enablePgo
val enableExperimental = true
val profilesZip = layout.projectDirectory.file("pgo.zip")
val enableRelease = findProperty("nativeRelease") == "true"
val isNativeBuildEnabled = gradle.startParameter.taskNames.any { subject ->
subject.lowercase().let {
"native" in it || "executable" in it
}
}
val extraJavacArgs: List<String> = listOfNotNull(
"--add-exports=org.graalvm.truffle.runtime.svm/com.oracle.svm.truffle=$module",
if (oracleGvm) null else "--add-reads=org.graalvm.truffle.runtime.svm=$module",
Expand Down Expand Up @@ -82,7 +87,7 @@ val experimentalGvmNativeFlags: List<String> = listOf(
)
)

private val nativeImageExclusions = listOf(
val nativeImageExclusions = listOf(
libs.graalSdk,
)

Expand Down Expand Up @@ -189,6 +194,7 @@ val inflateProfiles by tasks.registering(Copy::class) {
val releasePrep by tasks.registering {
onlyIf { enableRelease }
dependsOn(inflateProfiles)
outputs.cacheIf { true }
}

val javaExecutable by tasks.registering(ExecutableJar::class) {
Expand Down Expand Up @@ -223,12 +229,11 @@ val testStartJavaExecutable by tasks.registering(Exec::class) {
// dummy output to satisfy up-to-date check
val outputFile = layout.buildDirectory.dir("testStartJavaExecutable").get().asFile
outputs.file(outputFile)

executable = javaExecutable.get().outputs.files.singleFile.toString()
args("--version")

doFirst { outputFile.delete() }

doLast { outputFile.writeText("OK") }
}

Expand Down Expand Up @@ -289,7 +294,7 @@ fun createArchiveTasks(
}

fun Exec.configureExecutable(isEnabled: Boolean, outputFile: File, extraArgs: List<String> = listOf()) {
enabled = isEnabled
enabled = isEnabled && isNativeBuildEnabled
dependsOn(":installGraalVm", releasePrep)

inputs.files(sourceSets.main.map { it.output })
Expand Down Expand Up @@ -500,15 +505,17 @@ createArchiveTasks(
layout.buildDirectory.file("executable/pkl-windows-amd64").get().asFile,
)

val nativeTargets = listOf(
macExecutableAmd64,
macExecutableAarch64,
linuxExecutableAmd64,
linuxExecutableAarch64,
alpineExecutableAmd64,
windowsAmd64,
)

tasks.assembleNative {
dependsOn(
macExecutableAmd64,
macExecutableAarch64,
linuxExecutableAmd64,
linuxExecutableAarch64,
alpineExecutableAmd64,
windowsAmd64,
)
dependsOn(nativeTargets)
}

// make Java executable available to other subprojects
Expand Down

0 comments on commit 995ae76

Please sign in to comment.