OS / architecture dependent conditions for resources
Hello,
I have a library which uses JNA to call native libraries (.dll on windows, .so on linux, .dylib on macos). At the moment I have to include all libraries in every native-image, because there is no condition on the resource. It would be nicer if I could specify that the .dll is only needed when the native image is built for windows, the .so only for linux, etc. This would improve native image size quite a bit.
The libraries are dependent on the OS and on the architecture of the OS. There are libraries for Windows x86, x64, Linux x86, x64, arm, aarch64, etc. Therefore it would be great if the condition doesn't only take the OS into account, but also the architecture.
Thanks!
We may need support for this in JNI, reflection, and other metadata as well. An example are AWT applications, which require access to different, platform-specific library classes. Regarding this use case, are those libraries really embedded as a resource into the exectuable?
To avoid bloating image sizes, an hopefully easy workaround is to use platform-specific metadata files until this is implemented.
Yes, they are really embedded in the native image. The way JNA works is: it looks for the library in the system (libargon2 in this case). If the library isn't found, it is extracted from the resources to a temp folder and then loaded from there.
What do you mean with platform-specific metadata files? Use the build system to detect the OS and then only include the matching ones?
Yes, they are really embedded in the native image. The way JNA works is: it looks for the library in the system (libargon2 in this case). If the library isn't found, it is extracted from the resources to a temp folder and then loaded from there.
Interesting! We should also look into (optional?) compression for resources at some point.
What do you mean with platform-specific metadata files? Use the build system to detect the OS and then only include the matching ones?
I meant something as simple as providing different, platform-specific config files, such as darwin-x86-64/resource-config.json and linux-x86-64/resource-config.json. You'd then pass in a different config folder depending on the platform.