Unverified Commit f5534781 authored by jade's avatar jade Committed by GitHub
Browse files

buildGraalvm: fix native-image on darwin (#448389)

parents 4db8283e 006ab01d
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -137,8 +137,8 @@ let

      postInstall =
        let
          cLibsAsFlags = (map (l: "--add-flags '-H:CLibraryPath=${l}/lib'") cLibs);
          preservedNixVariables = [
          cLibsFlags = (map (l: "-H:CLibraryPath=${l}/lib") cLibs);
          preservedNixVarFlags = [
            "-ENIX_BINTOOLS"
            "-ENIX_BINTOOLS_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}"
            "-ENIX_BUILD_CORES"
@@ -161,7 +161,10 @@ let
            "-EMACOSX_DEPLOYMENT_TARGET_FOR_TARGET"
            "-ENIX_APPLE_SDK_VERSION"
          ];
          preservedNixVariablesAsFlags = (map (f: "--add-flags '${f}'") preservedNixVariables);
          checkToolchainFlags = lib.optionals stdenv.hostPlatform.isDarwin [
            "-H:+UnlockExperimentalVMOptions"
            "-H:-CheckToolchain"
          ];
        in
        ''
          # jni.h expects jni_md.h to be in the header search path.
@@ -182,7 +185,7 @@ let

          wrapProgram $out/bin/native-image \
            --prefix PATH : ${binPath} \
            ${toString (cLibsAsFlags ++ preservedNixVariablesAsFlags)}
            --add-flags "${toString (cLibsFlags ++ preservedNixVarFlags ++ checkToolchainFlags)}"
        '';

      preFixup = lib.optionalString (stdenv.hostPlatform.isLinux) ''
@@ -217,14 +220,14 @@ 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'

        ${
          # -H:+StaticExecutableWithDynamicLibC is only available in Linux
          lib.optionalString (stdenv.hostPlatform.isLinux && !useMusl) ''
            echo "Ahead-Of-Time compilation with -H:+StaticExecutableWithDynamicLibC"
            $out/bin/native-image -H:+UnlockExperimentalVMOptions -H:+StaticExecutableWithDynamicLibC -march=compatibility $extraNativeImageArgs HelloWorld
            $out/bin/native-image -H:+UnlockExperimentalVMOptions -H:+StaticExecutableWithDynamicLibC -march=compatibility HelloWorld
            ./helloworld | fgrep 'Hello World'
          ''
        }
@@ -233,7 +236,7 @@ let
          # --static is only available in x86_64 Linux
          lib.optionalString (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64 && useMusl) ''
            echo "Ahead-Of-Time compilation with --static and --libc=musl"
            $out/bin/native-image $extraNativeImageArgs -march=compatibility --libc=musl --static HelloWorld
            $out/bin/native-image -march=compatibility --libc=musl --static HelloWorld
            ./helloworld | fgrep 'Hello World'
          ''
        }