Skip to content

GraalVM

hrothwell edited this page Feb 21, 2023 · 3 revisions

Building a native image using GraalVM

This process is mostly outdated!! Folder paths/command inputs have slightly changed. Keeping this as a record. See build-native-image-windows.bat for my current build process (minus vs code script part)

  • Pre req:
  • After all the pre-req, I had a hard time finding what exactly would work, what commands to run with what parameters, etc. The exact process character for character that I did is as follows:
    • Open CMD as administrator, run the necessary VS code script: "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
      • replace path with wherever your bat file is located
    • Starting in project root:
      • .\gradlew clean build
      • cd build\libs
      • mkdir META-INF\native-image
      • java -agentlib:native-image-agent=config-output-dir=META-INF\native-image -jar mal-cli-1.0-SNAPSHOT-all.jar
        • 10-05-22: it is beneficial to run the application with several other inputs as well as specify config-merge-dir instead of config-output-dir, see build-native-image-windows.bat for examples and #15 for explanation
      • native-image --no-fallback --report-unsupported-elements-at-runtime -H:ConfigurationFileDirectories=META-INF\native-image -jar mal-cli-1.0-SNAPSHOT-all.jar mal --enable-url-protocols=https --no-server
        • Specifying the config directory META-INF\native-image was crucial for me, I saw some examples online stating META-INF\native-image was automatically seen/pulled in when using native-image, but it didn't work for me. Likely user error :P
      • run the cli! mal
    • After this process, .\build\libs\mal.exe should be present, from here I just copied it out as this build folder is constantly overwritten by gradle
    • I may potentially write a script to automate this whole process, would be fairly specific to this application as I have several flags I am using for the native-image calls and what not already wrote one
    • tl;dr for Windows
      • open cmd as admin
      • run VS code script
      • run build-native-image-windows.bat
      • if all goes well, exe file present in .\native-image-result
Clone this wiki locally