graal
graal copied to clipboard
[GR-53064] Require to explicitly specify all substitutions that are used in the Native Image build
TL;DR
The Native Image substitutions are currently applied if they are found on the image-builder class path. This is problematic for the following reasons:
- The class-path scanning is necessary making the image build longer. Class-path scanning needs to be removed in the future.
- Users can not disable incorrect substitutions in third-party projects.
- Users and Native Image developers are not aware of substitutions that are applied to the project and substitutions can unexpectedly affect the semantics.
We need to make the usage of all substitutions explicit. This can be done via a new value Substitutions
in the native-image.properties
file. The value Substitutions
would be a coma-separated list of all fully-qualified classes annotated with @TargetClass
.
The explicitly specified values are susceptible to the --exclude-config
flag. This will make it possible for people to disable third-party substitutions of a library. In conjuction to --exclude-config
, we will provide -H:DisableSubstitutions=<fully-qualified-name-CSV>
to disable individual substitutions as excluding the whole config of a library requires re-introducing the library configuration that is not related to substitutions.
The image build output will be modified to show the number of all user-space substitutions. The full list of classes will also be included into the crash reports for easier debugging.
Goals
- Make it possible to disable erroneous third-party substitutions.
- Make the class-path scanning unnecessary to find substitutions.
- Make users aware of the substitutions that were used in the image build and consequences of their usage.
- Provide a guide that explains how to avoid substitution usage.
Non-Goals
- Make abrupt breaking changes for existing code in the community.
- Disallow usage of substitutions in Native Image.
Migration
In the first step, the substitutions that are discovered on the class path but that are not specified in the Substitutions
value would be output in a warning message:
Warning: The following substitutions were discovered on the class path but were not specified explicitly in the `native-image.properties` file. Please add the following entries to the class path:
'Substitutions=<C1>,..,<C2>' in <cp-entry-1>/META-INF/native-image/<artifact-id>/native-image.properties
...
'Substitutions=<C3>,..,<C4>' in <cp-entry-n>/META-INF/native-image/<artifact-id>/native-image.properties
In case these files are not under your control please open a ticket for the library authors to include those entries or simply submit a PR.
Note that the usage of substitutions is unlikely necessary and the substitutions will likely not work well with layered native images. Please consult the following link to see how the substitutions can be removed: <link>
In the next step we would convert the warning into an error message with a possibility to disable the error via a flag.
In the third step there would not even be an error anymore, but the substitutions would simply be ignored.
The time duration between steps 1, 2, and 3 is to be discussed as it depends on the number of substitutions used in the community.