diff --git a/pkgs/by-name/pk/pkl/disable_bad_tests.patch b/pkgs/by-name/pk/pkl/disable_bad_tests.patch index 6c8028cedda95..a91b4267c88ba 100644 --- a/pkgs/by-name/pk/pkl/disable_bad_tests.patch +++ b/pkgs/by-name/pk/pkl/disable_bad_tests.patch @@ -1,12 +1,11 @@ -diff --git i/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt w/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt -index df88c423..ae1db500 100644 ---- i/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt -+++ w/pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt -@@ -1497,6 +1497,7 @@ result = someLib.x - assertThat(output).isEqualTo("result = 1\n") - } - -+ @Disabled - @Test - fun `eval file with non-ASCII name`() { - val tempDirUri = tempDir.toUri() +diff --git a/pkl-core/src/test/kotlin/org/pkl/core/LanguageSnippetTestsEngine.kt b/pkl-core/src/test/kotlin/org/pkl/core/LanguageSnippetTestsEngine.kt +index 99cf9479..45269d6d 100644 +--- a/pkl-core/src/test/kotlin/org/pkl/core/LanguageSnippetTestsEngine.kt ++++ b/pkl-core/src/test/kotlin/org/pkl/core/LanguageSnippetTestsEngine.kt +@@ -215,6 +215,7 @@ abstract class AbstractNativeLanguageSnippetTestsEngine : AbstractLanguageSnippe + // on the other hand, don't exclude /native/ + Regex(".*/import1b\\.pkl"), + // URIs get rendered slightly differently (percent-encoded vs raw) ++ Regex(".*日本語.pkl"), + Regex(".*日本語_error\\.pkl"), + ) + exclusionsForThisJvm() diff --git a/pkgs/by-name/pk/pkl/package.nix b/pkgs/by-name/pk/pkl/package.nix index 9d023e18779b2..279b0a99e2360 100644 --- a/pkgs/by-name/pk/pkl/package.nix +++ b/pkgs/by-name/pk/pkl/package.nix @@ -3,16 +3,32 @@ lib, fetchFromGitHub, gradle, - temurin-bin-21, + openjdk, kotlin, nix-update-script, replaceVars, makeWrapper, + graalvmPackages, + buildNative ? true, }: let - jdk = temurin-bin-21; + jdk = openjdk; + sourceJdkVersion = "21"; + targetJdkVersion = lib.versions.major jdk.version; + graalvmDir = graalvmPackages.graalvm-oracle_23; gradleOverlay = gradle.override { java = jdk; }; kotlinOverlay = kotlin.override { jre = jdk; }; + binaries = { + aarch64-darwin = "pkl-macos-aarch64"; + aarch64-linux = "pkl-linux-aarch64"; + x86_64-darwin = "pkl-macos-amd64"; + x86_64-linux = "pkl-linux-amd64"; + java = "jpkl"; + }; + inherit (stdenv.hostPlatform) system; + nativeBuild = (builtins.hasAttr system binaries) && buildNative; + binary = if nativeBuild then binaries.${system} else binaries.java; + binaryPath = "./pkl-cli/build/executable/" + binary; in stdenv.mkDerivation (finalAttrs: { pname = "pkl"; @@ -32,11 +48,33 @@ stdenv.mkDerivation (finalAttrs: { ''; }; - patches = [ - (replaceVars ./fix_kotlin_classpath.patch { gradle = gradle.unwrapped; }) - ./disable_gradle_codegen_tests.patch - ./disable_bad_tests.patch - ]; + patches = + [ + (replaceVars ./fix_kotlin_classpath.patch { gradle = gradle.unwrapped; }) + ./disable_gradle_codegen_tests.patch + ./disable_bad_tests.patch + ] + ++ ( + if nativeBuild then + [ + (replaceVars ./use_nix_graalvm_instead_of_download.patch { inherit graalvmDir; }) + ] + else + [ ] + ); + + postPatch = '' + substituteInPlace buildSrc/build.gradle.kts \ + --replace-fail "vendor = JvmVendorSpec.ADOPTIUM" "" \ + --replace-fail "toolchainVersion = ${sourceJdkVersion}" \ + "toolchainVersion = ${targetJdkVersion}" + + substituteInPlace buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts \ + --replace-fail "vendor = info.jdkVendor" "" + + substituteInPlace buildSrc/src/main/kotlin/BuildInfo.kt \ + --replace-fail "vendor.set(jdkVendor)" "" + ''; nativeBuildInputs = [ gradleOverlay @@ -52,7 +90,12 @@ stdenv.mkDerivation (finalAttrs: { doCheck = !(stdenv.hostPlatform.isDarwin); + gradleCheckTask = if nativeBuild then "testNative" else "test"; + + gradleBuildTask = if nativeBuild then "assembleNative" else "assemble"; + gradleFlags = [ + "-s" "-x" "spotlessCheck" "-DreleaseBuild=true" @@ -77,9 +120,12 @@ stdenv.mkDerivation (finalAttrs: { runHook preInstall mkdir -p "$out/bin" "$out/opt/pkl" - cp ./pkl-cli/build/executable/jpkl "$out/opt/pkl/jpkl.jar" - - makeWrapper ${lib.getExe jdk} $out/bin/pkl --add-flags "-jar $out/opt/pkl/jpkl.jar" + if [ ${builtins.toString nativeBuild} ]; then + install -Dm755 ${binaryPath} "$out/bin/pkl" + else + cp ${binaryPath} "$out/opt/pkl/jpkl.jar" + makeWrapper ${lib.getExe jdk} $out/bin/pkl --add-flags "-jar $out/opt/pkl/jpkl.jar" + fi runHook postInstall ''; diff --git a/pkgs/by-name/pk/pkl/use_nix_graalvm_instead_of_download.patch b/pkgs/by-name/pk/pkl/use_nix_graalvm_instead_of_download.patch new file mode 100644 index 0000000000000..55a986b0da0a5 --- /dev/null +++ b/pkgs/by-name/pk/pkl/use_nix_graalvm_instead_of_download.patch @@ -0,0 +1,69 @@ +diff --git i/buildSrc/src/main/kotlin/BuildInfo.kt w/buildSrc/src/main/kotlin/BuildInfo.kt +index 3020857b..54d0da41 100644 +--- i/buildSrc/src/main/kotlin/BuildInfo.kt ++++ w/buildSrc/src/main/kotlin/BuildInfo.kt +@@ -100,10 +100,10 @@ open class BuildInfo(private val project: Project) { + File(homeDir, "${baseName}.$extension") + } + +- val installDir: File by lazy { File(homeDir, baseName) } ++ val installDir: File by lazy { File("@graalvmDir@") } + + val baseDir: String by lazy { +- if (os.isMacOsX) "$installDir/Contents/Home" else installDir.toString() ++ "@graalvmDir@" + } + } + +diff --git i/pkl-cli/pkl-cli.gradle.kts w/pkl-cli/pkl-cli.gradle.kts +index facfeabb..7b48201f 100644 +--- i/pkl-cli/pkl-cli.gradle.kts ++++ w/pkl-cli/pkl-cli.gradle.kts +@@ -313,7 +313,6 @@ fun Exec.configureExecutable( + /** Builds the pkl CLI for macOS/amd64. */ + val macExecutableAmd64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAmd64") + configureExecutable( + buildInfo.graalVmAmd64, + layout.buildDirectory.file("executable/pkl-macos-amd64"), +@@ -323,7 +322,6 @@ val macExecutableAmd64: TaskProvider by + /** Builds the pkl CLI for macOS/aarch64. */ + val macExecutableAarch64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAarch64") + configureExecutable( + buildInfo.graalVmAarch64, + layout.buildDirectory.file("executable/pkl-macos-aarch64"), +@@ -334,7 +332,6 @@ val macExecutableAarch64: TaskProvider by + /** Builds the pkl CLI for linux/amd64. */ + val linuxExecutableAmd64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAmd64") + configureExecutable( + buildInfo.graalVmAmd64, + layout.buildDirectory.file("executable/pkl-linux-amd64"), +@@ -349,7 +346,6 @@ val linuxExecutableAmd64: TaskProvider by + */ + val linuxExecutableAarch64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAarch64") + configureExecutable( + buildInfo.graalVmAarch64, + layout.buildDirectory.file("executable/pkl-linux-aarch64"), +@@ -369,7 +365,6 @@ val linuxExecutableAarch64: TaskProvider by + */ + val alpineExecutableAmd64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAmd64") + configureExecutable( + buildInfo.graalVmAmd64, + layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"), +@@ -379,7 +374,6 @@ val alpineExecutableAmd64: TaskProvider by + + val windowsExecutableAmd64: TaskProvider by + tasks.registering(Exec::class) { +- dependsOn(":installGraalVmAmd64") + configureExecutable( + buildInfo.graalVmAmd64, + layout.buildDirectory.file("executable/pkl-windows-amd64"),