Repository: apple/pkl
File: pkl-cli/pkl-cli.gradle.kts (Kotlin)

Code before:
 *
 * Right now, this is built within a container on Mac using emulation because CI does not have
 * ARM instances.
 */
val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
  if (buildInfo.os.isLinux && buildInfo.arch == "aarch64") {
    dependsOn(":installGraalVmAarch64")
    configureExecutable(
      buildInfo.graalVmAarch64,
      layout.buildDirectory.file("executable/pkl-linux-aarch64")
    )
  } else {
    enabled = false
  }
}

/**
 * Builds a statically linked CLI for linux/amd64.
 *
 * Note: we don't publish the same for linux/aarch64 because native-image doesn't support this.
 * Details: https://www.graalvm.org/22.0/reference-manual/native-image/ARM64/
 */
val alpineExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
  if (buildInfo.os.isLinux && buildInfo.arch == "amd64" && buildInfo.hasMuslToolchain) {
    dependsOn(":installGraalVmAmd64")
    configureExecutable(
      buildInfo.graalVmAmd64,
      layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
      listOf("--static", "--libc=musl")
    )
  } else {
    enabled = false
  }
}

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

// make Java executable available to other subprojects
// (we don't do the same for native executables because we don't want tasks assemble/build to build them)
artifacts {
  add("javaExecutable", javaExecutable.map { it.outputs.files.singleFile }) {
    name = "pkl-cli-java"
    classifier = null
    extension = "jar"
    builtBy(javaExecutable)
  }
}

//region Maven Publishing

Review comment (suggestion):
```suggestion
    buildInfo.os.isMacOsX -> {
      dependsOn(macExecutableAarch64)
      dependsOn(macExecutableAmd64)
    }
```

Code after:
/**
 * Builds a statically linked CLI for linux/amd64.
 *
 * Note: we don't publish the same for linux/aarch64 because native-image doesn't support this.
 * Details: https://www.graalvm.org/22.0/reference-manual/native-image/ARM64/
 */
val alpineExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
  dependsOn(":installGraalVmAmd64")
  configureExecutable(
    buildInfo.graalVmAmd64,
    layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
    listOf("--static", "--libc=musl")
  )
}

tasks.assembleNative {
  when {
    buildInfo.os.isMacOsX -> {
      dependsOn(macExecutableAmd64)
      if (buildInfo.arch == "aarch64") {
        dependsOn(macExecutableAarch64)
      }
    }
    buildInfo.os.isLinux && buildInfo.arch == "aarch64" -> {
      dependsOn(linuxExecutableAarch64)
    }
    buildInfo.os.isLinux && buildInfo.arch == "amd64" -> {
      dependsOn(linuxExecutableAmd64)
      if (buildInfo.hasMuslToolchain) {
        dependsOn(alpineExecutableAmd64)
      }
    }
  }
}

// make Java executable available to other subprojects
// (we don't do the same for native executables because we don't want tasks assemble/build to build them)
artifacts {
  add("javaExecutable", javaExecutable.map { it.outputs.files.singleFile }) {
    name = "pkl-cli-java"
    classifier = null
    extension = "jar"
    builtBy(javaExecutable)
  }
}

//region Maven Publishing
publishing {
  publications {
    register<MavenPublication>("javaExecutable") {
      artifactId = "pkl-cli-java"