Commit 006ab01d authored by Rowenna Emma's avatar Rowenna Emma
Browse files

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.
parent 727a5522
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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'

        ${