From 006ab01d64a708cd1c9c30454b1a4a002ab77b72 Mon Sep 17 00:00:00 2001 From: Rowenna Emma Date: Thu, 25 Sep 2025 21:30:11 -0700 Subject: [PATCH] buildGraalvm: fix native-image on darwin On Darwin, it is apparently Oracle's intention to be hostile towards builds of Clang which are not by Apple. see https://github.com/oracle/graal/issues/12041 If you want native-image to both work on Darwin and use the nix-provided CC then you must pass it the flags to disable toolchain checking entirely. Since the flags are mandatory for functionality, they should be part of the wrapper. --- .../compilers/graalvm/community-edition/buildGraalvm.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix b/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix index 13c9ff105e91..5b4821bf63df 100644 --- a/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix +++ b/pkgs/development/compilers/graalvm/community-edition/buildGraalvm.nix @@ -161,6 +161,10 @@ let "-EMACOSX_DEPLOYMENT_TARGET_FOR_TARGET" "-ENIX_APPLE_SDK_VERSION" ]; + checkToolchainFlags = lib.optionals stdenv.hostPlatform.isDarwin [ + "-H:+UnlockExperimentalVMOptions" + "-H:-CheckToolchain" + ]; in '' # jni.h expects jni_md.h to be in the header search path. @@ -181,7 +185,7 @@ let wrapProgram $out/bin/native-image \ --prefix PATH : ${binPath} \ - --add-flags "${toString (cLibsFlags ++ preservedNixVarFlags)}" + --add-flags "${toString (cLibsFlags ++ preservedNixVarFlags ++ checkToolchainFlags)}" ''; preFixup = lib.optionalString (stdenv.hostPlatform.isLinux) '' @@ -216,7 +220,7 @@ let $out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World' echo "Ahead-Of-Time compilation" - $out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces -march=compatibility HelloWorld + $out/bin/native-image -H:+ReportExceptionStackTraces -march=compatibility HelloWorld ./helloworld | fgrep 'Hello World' ${