Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --exclude-config arguments to be specified inside jar #196

Closed
philwebb opened this issue Oct 7, 2022 · 4 comments
Closed

Allow --exclude-config arguments to be specified inside jar #196

philwebb opened this issue Oct 7, 2022 · 4 comments

Comments

@philwebb
Copy link

philwebb commented Oct 7, 2022

Describe the Enhancement

Currently --exclude-config arguments can be specified in BP_NATIVE_IMAGE_BUILD_ARGUMENTS in order to pass a list of configurations that should be excluded during native image creation. Spring Boot is working on native image support and would like a way to define --exclude-config arguments inside the JAR file. This will allow a jar file to describe completely how it should be converted into a native image.

Possible Solution

During creation of the JAR file, Spring Boot can add a META-INF/native-image/exclude-config-args file containing the --exclude-config arguments that it would like added. For example:

\Qfirst-library.jar\E ^/META-INF/native-image/.*
\Qsecond-library.jar\E ^/META-INF/native-image/.*

The file would consist of one line per --exclude-config argument. The example above would result in the following being passed to the native-image command line:

--exclude-config \Qfirst-library.jar\E ^/META-INF/native-image/.* --exclude-config \Qsecond-library.jar\E ^/META-INF/native-image/.*

Motivation

Graal provides a reachability-metadata repository that contains JSON files that allow third-party libraries to work. Spring Boot is looking to use this repository to bundle appropriate JSON files from the repository into the fat jar that it creates. We hope to achieve this by configuring the native-build-tools plugin so that it directly packages the appropriate JSON files. An enhancement request for native-build-tools is currently under review.

For most libraries, adding the metadata will be enough to create a fully functioning native image, however, some need to use "overrides". The override flag allows the metadata repository to override hints that are packaged inside the library jar itself. It can be used when a library ships incorrect meta-data that later needs to be corrected.

When the native-build-tools plugin is being used directly to create the image it is able to construct appropriate --exclude-config arguments. For example, this is how the Maven plugin generates the arguments. We need an equivalent option for use with buildpacks and unfortunately we can use --exclude-config in the Args property under META-INF/native-image/native-image.properties.

For more background and discussion please see spring-projects/spring-boot#31782

@sdeleuze
Copy link

sdeleuze commented Oct 13, 2022

@philwebb After discussing with @pivotal-david-osullivan this morning, we agreed that the easiest path from a Buildpacks perspective would be for Spring Boot to generate a META-INF/native-image/argfile file that would directly contain the arguments to pass to the native-image like --exclude-config \Qfirst-library.jar\E ^/META-INF/native-image/.* --exclude-config \Qsecond-library.jar\E ^/META-INF/native-image/.*.

On buildpack side, it would then just be about detecting this well-known file and pass it to the native image compiler via native-image @/path/to/META-INF/native-image/argfile. That would also make this mechanism suitable for other arguments that need to be passed directly to the compiler.

Would you be ok with that solution?

@philwebb
Copy link
Author

@sdeleuze Yes, sound good to me. I've opened spring-projects/spring-boot#32738 and pushed a commit that should generate that file. We can't yet do an end-to-end test because we're waiting on an NBT release.

@sdeleuze
Copy link

As discussed today, end to end testing with Buildpacks should now be possible with NBT 0.9.15, even if we will need to release 0.9.16 to fix this regression that should impact only local NBT usage.

@sdeleuze
Copy link

sdeleuze commented Nov 6, 2022

Works as expected, this issue can now be closed.

@dmikusa dmikusa closed this as completed Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants