buildGraalvm: use NATIVE_IMAGE_DEPRECATED_BUILDER_SANITATION instead of CC wrapper

Instead of using a hacky CC wrapper to re-inject the environment
variables needed to build, we set the
NATIVE_IMAGE_DEPRECATED_BUILDER_SANITATION=true that is in 21.0.0
release changelog:
489611a304/substratevm/CHANGELOG.md (L48)

This is deprecated behavior for now, and will be removed in future, but
this will allow us more time until we figure a proper solution.

See:
- https://github.com/oracle/graal/issues/7502
- https://github.com/oracle/graal/issues/7981
- https://github.com/oracle/graal/pull/6095
This commit is contained in:
Thiago Kenji Okada 2023-12-13 11:52:44 +00:00
parent 14c5d38b53
commit a92e6068b4

View File

@ -63,22 +63,7 @@ let
mkdir -p $out/bin
ln -s ${lib.getDev musl}/bin/musl-gcc $out/bin/${stdenv.hostPlatform.system}-musl-gcc
'');
# GraalVM 23.0.0+ (i.e.: JDK 21.0.0+) clean-up the environment inside darwin
# So we need to re-added some env vars to make everything work correctly again
darwin-cc = (runCommandCC "darwin-cc"
{
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ darwin.apple_sdk.frameworks.Foundation zlib ];
} ''
makeWrapper ${stdenv.cc}/bin/cc $out/bin/cc \
--prefix NIX_CFLAGS_COMPILE_${stdenv.cc.suffixSalt} : "$NIX_CFLAGS_COMPILE" \
--prefix NIX_LDFLAGS_${stdenv.cc.suffixSalt} : "$NIX_LDFLAGS"
'');
binPath = lib.makeBinPath (
lib.optionals stdenv.isDarwin [ darwin-cc ]
++ lib.optionals useMusl [ musl-gcc ]
++ [ stdenv.cc ]
);
binPath = lib.makeBinPath (lib.optionals useMusl [ musl-gcc ] ++ [ stdenv.cc ]);
runtimeLibraryPath = lib.makeLibraryPath
([ cups ] ++ lib.optionals gtkSupport [ cairo glib gtk3 ]);
@ -180,6 +165,14 @@ let
echo "Testing GraalVM"
$out/bin/java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler HelloWorld | fgrep 'Hello World'
# Workaround GraalVM issue where the builder does not have access to the
# environment variables since 21.0.0
# Only needed for native-image tests
# https://github.com/oracle/graal/pull/6095
# https://github.com/oracle/graal/pull/6095
# https://github.com/oracle/graal/issues/7502
export NATIVE_IMAGE_DEPRECATED_BUILDER_SANITATION="true";
echo "Ahead-Of-Time compilation"
$out/bin/native-image -H:+UnlockExperimentalVMOptions -H:-CheckToolchain -H:+ReportExceptionStackTraces HelloWorld
./helloworld | fgrep 'Hello World'