-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add GraalVM native-image configuration for LDIF file #135
Comments
Sorry. I somehow accidentally closed this issue with some mistaken key combination. Nevertheless, I'm confused by this. Are you saying that GraalVM's default assumption is that all non-class files in a jar file are completely superfluous and included for no good reason? That makes no sense whatsoever. Why would anyone include resources in a jar file if they weren't intended to be used in conjunction with the classes in that jar file? And are you also saying that there's no way of overriding this default behavior with a build flag to dissuade it of this idiotic assumption? As I understand it from the GraalVM documentation, this resource-config.json file isn't something that's supposed to be included in the jar file itself but rather provided as a companion to be targeted with a command-line option. Is that correct? If so, is there a simple resource-config.json file that tells it to actually take everything in the jar file because it actually is all important and really is there for a reason? Sorry for the argumentative tone, but I honestly can't understand why they would make that assumption. |
Hi! Quote from GraalVM docs, emphasis by me:
In order to build the native image, it processes all classes of an application and their dependencies, including those from the JDK. It statically analyzes these data to determine which classes and methods are reachable during the application execution. Then it ahead-of-time compiles that reachable code and data to a native executable for a specific operating system and architecture. During this static analysis, the native-image cannot detect reflective invocations or resources loaded by name, for example. You are not compelled to apply this change tho. There are 3 possibilities for libraries:
It's up to you to decide how you want to handle this. GraalVM proponents would prefer option 3, but option 2 would work too. I prefer the hints closer to the code which does the proxying / reflection etc. But don't feel bad closing the issue if you don't want to have this metadata in your code. |
I've done some looking into this, and I've not yet been able to reproduce the problem in which the in-memory directory server doesn't have access to the default standard schema when bundled into a native image. To test this, I created a very simple class that creates an in-memory directory server instance that uses the default standard schema, starts the server, and retrieves the schema from it. The code for that is:
I compiled that class with the command:
And then I verified that it works when running it using regular Java:
Next, I tried turning it into a native image using the command (using graalvm-ce-java17-linux-amd64-22.2.0.tar.gz, which is the latest build I found on their site):
That succeeded, and I ran the resulting command and verify that I got the same output when running the native image that I got when running it with the regular JVM:
Could you provide a simple standalone test case and instructions for demonstrating the problem? I'd prefer to not have to deal with Spring or any other framework if it can be reproduced in a more simple manner. |
You are right with your commands, there is just one thing that you need to do. You probably have a WARNING in your logs after generating the native-image:
So if you add the
Once you run the generated binary, you'll get the error.
|
I've just committed a change so that the LDAP SDK zip file now includes a resource/graalvm-native-image-resource-config.json file that is generated during the build process. The contents of that file are currently:
I've tested with providing this JSON file to the native-image tool and it seems to work properly. I did consider including it in the jar file manifest, which would eliminate the need to explicitly provide the file to the native-image tool, but I decided against that in case you want to customize what gets included. |
Great @dirmgr, it is so nice that we can have this config file in the library itself.
I don't think anyone would like to customize what's included in the native-image if the library already specified what should be included. It would be great if the config file could be added to the jar file so it can be picked up automatically by the native-image tool, if anyone wants to add something extra they can still use their own hints. There are some high-profile libraries like Netty and Tomcat which include GraalVM config in their JAR too. |
I went ahead and updated the build process so that the resource-config.json file is placed in the jar rather than packaged as a separate file. |
Great @dirmgr, thank you for adding this to the project, I can confirm that it is working. Do you have any schedule for the next release? I do not see any milestones. |
Unless there's a critical issue that needs to be addressed, releases of the LDAP SDK are generally tied to the development of the Ping Identity Directory Server. I don't have a specific date for the next release of the LDAP SDK, but I expect it to be pretty soon (likely within the next week or two, and possibly even within the next few days). |
Hi @dirmgr, thank you very much for adding this. I assume this issue can be closed now? |
If you believe this has been provided to satisfaction, then I'll go ahead and close it. |
Current behavior:
Spring Boot has support for an embedded LDAP server which allow us to specify a schema file in order to add initial data.
When building a native-image, the GraalVM needs hints in order to know which files it should consider when compiling natively.
This library uses the
standard-schema.ldif
but there is no hint for it.We are now adding the hint by ourselves, but it would be nice if the hint could be added to the library itself.
Expected behavior:
The library contains the
resource-config.json
file with thestandard-schema.ldif
resource as a hint.Sample PR in another project: brettwooldridge/HikariCP#1959
The text was updated successfully, but these errors were encountered: