Skip to content
Open
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
2 changes: 1 addition & 1 deletion buildSrc/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# GRADLE JVM WRAPPER START MARKER
BUILD_DIR="$APP_HOME/gradle/jdk"
BUILD_DIR="$HOME/.gradle/jdks/graalvm-21.0.2"
JVM_ARCH=$(uname -m)
JVM_TEMP_FILE=$BUILD_DIR/gradle-jvm-temp.tar.gz
if [ "$darwin" = "true" ]; then
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem GRADLE JVM WRAPPER START MARKER

setlocal
set BUILD_DIR=%APP_HOME%\gradle\jdk
set BUILD_DIR=%USERPROFILE%\.gradle\jdks\graalvm-21.0.2
set JVM_TARGET_DIR=%BUILD_DIR%\graalvm-community-jdk-21.0.2_windows-x64_bin-8bbfc2\

set JVM_URL=https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_windows-x64_bin.zip
Expand Down
36 changes: 15 additions & 21 deletions buildSrc/src/main/kotlin/org/kson/GraalVmHelper.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
package org.kson

import org.gradle.api.GradleException
import org.gradle.api.Project
import java.io.File

object GraalVmHelper {
val os = System.getProperty("os.name").lowercase()
private val os = System.getProperty("os.name").lowercase()

/**
* Locates the GraalVM JDK installation directory within the gradle/jdk folder.
* The JDK is automatically downloaded by the Gradle wrapper based on jdk.properties.
* Handles platform-specific directory structures (e.g., macOS's Contents/Home subdirectory).
* Gets the GraalVM home directory. Since Gradle is already running with the JDK from
* jdk.properties (via the jvm.wrapper plugin), we just use Gradle's own JAVA_HOME.
* @return The GraalVM home directory
* @throws GradleException if GraalVM JDK is not found
*/
fun getGraalVMHome(rootProject: Project): File {
val graalvmDir = File("${rootProject.projectDir}/gradle/jdk")
fun getGraalVMHome(): File {
val javaHome = File(System.getProperty("java.home"))

val graalvmTopLevelDir = graalvmDir.listFiles()?.find {
it.isDirectory && it.name.contains("graalvm")
} ?: throw GradleException("GraalVM JDK not found in $graalvmDir (no top-level dir present). Run './gradlew' to download it.")

// In MacOS the graalvm directory is unpacked inside a graalvm directory, try to find it
val graalvmUnpackDir = graalvmTopLevelDir.listFiles()?.find {
it.isDirectory && it.name.contains("graalvm")
} ?: graalvmTopLevelDir // Fall back to top-level if no nested dir found

// Special handling for macOS: use Contents/Home subdirectory if it exists
return if ((os.contains("mac") || os.contains("darwin")) && File("$graalvmUnpackDir/Contents/Home").exists()) {
File("$graalvmUnpackDir/Contents/Home")
} else {
graalvmUnpackDir
// Verify it's actually GraalVM
val nativeImageExe = File(javaHome, "bin/native-image${getNativeImageExtension()}")
if (!nativeImageExe.exists()) {
throw GradleException(
"native-image not found at $nativeImageExe. " +
"The JDK at $javaHome does not appear to be GraalVM. " +
"Please ensure jdk.properties points to a GraalVM distribution."
)
}

return javaHome
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# GRADLE JVM WRAPPER START MARKER
BUILD_DIR="$APP_HOME/gradle/jdk"
BUILD_DIR="$HOME/.gradle/jdks/graalvm-21.0.2"
JVM_ARCH=$(uname -m)
JVM_TEMP_FILE=$BUILD_DIR/gradle-jvm-temp.tar.gz
if [ "$darwin" = "true" ]; then
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem GRADLE JVM WRAPPER START MARKER

setlocal
set BUILD_DIR=%APP_HOME%\gradle\jdk
set BUILD_DIR=%USERPROFILE%\.gradle\jdks\graalvm-21.0.2
set JVM_TARGET_DIR=%BUILD_DIR%\graalvm-community-jdk-21.0.2_windows-x64_bin-8bbfc2\

set JVM_URL=https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_windows-x64_bin.zip
Expand Down
4 changes: 2 additions & 2 deletions jdk.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ JDK_VERSION=21.0.2
#
# IF THESE URLs CHANGE: `./gradlew wrapper` must be run after any edits for them to take effect,
# and `./gradlew check` should also be run to ensure the new JDK is loaded and verified
unixJvmInstallDir=$APP_HOME/gradle/jdk
winJvmInstallDir=%APP_HOME%\\gradle\\jdk
unixJvmInstallDir=$HOME/.gradle/jdks/graalvm-21.0.2
winJvmInstallDir=%USERPROFILE%\\.gradle\\jdks\\graalvm-21.0.2
macAarch64JvmUrl=https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_macos-aarch64_bin.tar.gz
macX64JvmUrl=https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_macos-x64_bin.tar.gz
linuxAarch64JvmUrl = https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-aarch64_bin.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion kson-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ tasks.register<PixiExecTask>("buildWithGraalVmNativeImage") {

// Configure the command at configuration time using providers
command.set(provider {
val graalHome = GraalVmHelper.getGraalVMHome(rootProject)
val graalHome = GraalVmHelper.getGraalVMHome()

val nativeImageExe = file("${graalHome}/bin/native-image${GraalVmHelper.getNativeImageExtension()}")
if (!nativeImageExe.exists()) {
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ val buildNativeImage by tasks.registering(PixiExecTask::class) {

// Configure the command at configuration time using providers
command.set(provider {
val graalHome = GraalVmHelper.getGraalVMHome(rootProject)
val graalHome = GraalVmHelper.getGraalVMHome()

val nativeImageExe = file("${graalHome}/bin/native-image${GraalVmHelper.getNativeImageExtension()}")
if (!nativeImageExe.exists()) {
Expand Down