oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.99k stars 1.6k forks source link

[native-image driver] need a (documented) way to do variable substitution in `native-image.properties` file #7447

Open revintec opened 9 months ago

revintec commented 9 months ago

running GraalVM 23.0 with native-image, should be a relatively new version as of writing also no relevant feature seems present in github master source branch, nor documentation can be found

Is your feature request related to a problem? Please describe. native-image driver provides a way to customize build arguments, using META-INF/native-image/native-image.properties resource files. however there seems no (easy) way to do variable substitution in this file. namely, I'd like using sth. like: JavaArgs = --patch-module java.base=$HOME/shade.jar // or ${HOME}

Describe the solution you'd like. provide a way to do property file variable substitution, e.g.: -VHOME=xxx + JavaArgs = $HOME/abc = JavaArgs = xxx/abc HOME=xxx + -EHOME + JavaArgs = $HOME/abc = JavaArgs = xxx/abc

  1. I've tried using -VHOME=... and -EHOME to no avail
  2. I've tried to debug the driver using native-image --debug-attach ... but this can only debug the build process, not the native-image bootstrap driver itself(GvmEE-Java20-23.0/lib/svm/bin/native-image: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked)

Describe who do you think will benefit the most. all GraalVM contributors, developers of libraries and frameworks which depend on GraalVM, could benefit from this as build argument is now more flexible. previously the embedded build argument in property file is rigid, but now it can be treated as a template, thus can be further augmented using -V, -E or some other flags/environment variables

Describe alternatives you've considered. write the relevant argument each and every time in command line fully or inside a bash.sh script, not ideal

Additional context. as I'm unable to debug the code, I can only statically analyze the source file :( it seems the relevant feature already exists(-V and -Es), but I'm unable to grasp the usage, nor find the documentation https://github.com/oracle/graal/blob/ff84a77e57a4692b65680aa0a6a1afad79b2c035/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java#L169

image

https://github.com/oracle/graal/blob/ff84a77e57a4692b65680aa0a6a1afad79b2c035/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java#L678

image

Express whether you'd like to help contributing this feature this feature should require minimal/no code change, or simply a documentation update, thus I'd like not to open a code PR

revintec commented 9 months ago

also, can I debug the native-image driver itself? ideally not have to use gdb maybe debug a java version of it(not the aot compiled version)?

petermz commented 9 months ago

You can: run native-image --debug-attach[=port] and attach your IDE

revintec commented 9 months ago

@petermz maybe I didn't do it correctly? but that seems only able to debug the child build process, not the native-image bootstrap driver itself. as cited from my original post:

2. I've tried to debug the driver using native-image --debug-attach ... but this can only debug the build process, not the native-image bootstrap driver itself(GvmEE-Java20-23.0/lib/svm/bin/native-image: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked)

oubidar-Abderrahim commented 9 months ago

Hi Thank you for your suggestion, I shared it with the Dev team and we'll take a look into it whenever possible. Tracked internally at GR 48898

revintec commented 7 months ago

@oubidar-Abderrahim Hi, is there any update on this?

oubidar-Abderrahim commented 7 months ago

We don't have this implemented right now, it seems like a nice feature but it's very unlikely that we will find time to implement that at the moment. We've added this feature to our backlog for future releases.