Commit bc1bc1aa authored by Pavel Shirshov's avatar Pavel Shirshov Committed by Thiago Kenji Okada
Browse files

graalvm-ce: fix native-image standalone usage by wrapping Nix env variables

Closes #350909.
parent 5bc90efc
Loading
Loading
Loading
Loading
+39 −24
Original line number Diff line number Diff line
@@ -120,7 +120,24 @@ let
      xorg.libXtst
    ];

    postInstall = ''
    postInstall =
      let
        cLibsAsFlags = (map (l: "--add-flags '-H:CLibraryPath=${l}/lib'") cLibs);
        preservedNixVariables = [
          "-ELOCALE_ARCHIVE"
          "-ENIX_BINTOOLS"
          "-ENIX_BINTOOLS_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}"
          "-ENIX_BUILD_CORES"
          "-ENIX_BUILD_TOP"
          "-ENIX_CC"
          "-ENIX_CC_WRAPPER_TARGET_HOST_${stdenv.cc.suffixSalt}"
          "-ENIX_CFLAGS_COMPILE"
          "-ENIX_HARDENING_ENABLE"
          "-ENIX_LDFLAGS"
        ];
        preservedNixVariablesAsFlags = (map (f: "--add-flags '${f}'") preservedNixVariables);
      in
      ''
        # jni.h expects jni_md.h to be in the header search path.
        ln -sf $out/include/linux/*_md.h $out/include/

@@ -139,7 +156,7 @@ let

        wrapProgram $out/bin/native-image \
          --prefix PATH : ${binPath} \
        ${toString (map (l: "--add-flags '-H:CLibraryPath=${l}/lib'") cLibs)}
          ${toString (cLibsAsFlags ++ preservedNixVariablesAsFlags)}
      '';

    preFixup = lib.optionalString (stdenv.hostPlatform.isLinux) ''
@@ -171,10 +188,8 @@ let
      echo "Testing GraalVM"
      $out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'

      extraNativeImageArgs="$(export -p | sed -n 's/^declare -x \([^=]\+\)=.*$/ -E\1/p' | tr -d \\n)"

      echo "Ahead-Of-Time compilation"
      $out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces -march=compatibility $extraNativeImageArgs HelloWorld
      $out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces -march=compatibility HelloWorld
      ./helloworld | fgrep 'Hello World'

      ${# -H:+StaticExecutableWithDynamicLibC is only available in Linux