Open BjoernAkAManf opened 2 years ago
Hi @BjoernAkAManf , thanks for your proposal!
Leaving the discussion of the API for a PR, I think providing a way to custom behavior around native library loading itself is fine as long as we have some expected use-cases. What is your concrete use case for the custom library loading?
A couple of things actually (at least visionary):
I'll try to prepare a Pull Request once i get the time.
I see, these requirements are reasonable I think.
So basically you want to put a custom (signed) native library to the location (application-local directory) through the build process and let the JVM to load native library from there without extracting an included build out of wasmtime-java jar?
If so, would it be doable just by using java.library.path
system property? JVM searches native library from the directory specified to the property, so by putting it into the .native
directory for example, you can just java ... -Djava.library.path=/path/to/.native
then tryLoadFromLibraryPath
loads from there without writing any to the disks.
Yes, agreed, that this is somewhat possible right now. However i disagree with the Solution:
java.library.path is read-only after JVM start though. Workarounds seem way to hacky (e.g. http://web.archive.org/web/20210614015640/http://fahdshariff.blogspot.com/2011/08/changing-java-library-path-at-runtime.html ). As such i would have either to:
Both of which seem quite counter-intuitive for a Cross Platform Language like java (albeit i agree this is somewhat of a standard). However all of those seem like a bad choice, if a "simple" Class (see my initial comment) can fix that. As such i still think my use-case is hardly covered by existing alternatives.
Also i think being able to initialize the application on any supported operating system "as-is" is quite the desireable Dev-Experience and i would therefore prefer being able to write the currently shipped binary to disk.
i would therefore prefer being able to write the currently shipped binary to disk.
So you want wasmtime-java to extract the pre-built jar out of it and use still, but you want control where it's stored temporary? I'm little bit confused because, the above requirement indeed fulfils use-case 2, (application local file creation) but doesn't sounds to help use-case 1 and 3 because in case of 1, the running jvm process can't write to disk (so I presume deployer builds and places native library manually), and for 3 you need to run your own build process to sign a build native library I guess?
I'm sorry, i feel like i'm being quite bad at explaining my use-case.
I enjoy being able to just add a maven dependency and "it just works" is great. During development i would want to be able to just download the source code, run maven and "it just works".
During deployment in production however, i would prefer the process to be slightly different with a read-only file system. As i have yet to write that code though, i would assume it would be done through an ansible role. The Native Library would be put there as well. The Signing Process is also still in development, but I'm looking into reproducible builds with a trusted Build Server signing the binary.
As such in development the binary is copied over and in production the binary is expected to be provisioned by external systems. In both cases the location of the binary needs to be predictable.
Ok, so in summary:
In development phase:
./gradlew build
<= This is also possibleIn deployment phase:
And at runtime:
java.library.path
but you want an alternative wayis this understanding correct? In case, I would still encourage to just go with java.library.path
because it's pretty standard for Java libraries, and the reason I put tryLoadFromLibraryPath
in prior to prebuilt library extraction is to let users use their own native library through java.library.path
.
But if that still doesn't satisfy your need, you can submit a PR with concrete code and we can discuss further. At least i'm not strongly against adding interface to let users inject arbitrary native library loading, as I assume it will be doable with a few simple and stable APIs.
Hi,
as a User of this Library i want to be able to control access of IO. In particular i want to be able to specify the path the native library is beeing written to.
For example i attached the following Class "Native" that emulates the behavior i want to implement. Unfortunately this requires alot of copy-paste and hackish workarounds.
I would propose extracting the necessary functionality into atleast two parts:
By default i suggest implementing the following Strategies:
Order is provided by each Strategy. As such tryLoadFromLibraryPath would return -1 and loadFromTempfile 1. Other Implementations can then use 0 easily. ServiceLoader would allow to reduce implementation.
The API should provide access to atleast fileName and extension in order to allow writing correctly.
I did not yet start working on a Pull Request, because i feel like this RfC is disruptive to the current implementation and as such I feel @kawamuray you as a Maintainer should first give your Opinion.
Alternatively one could use an Environment Variable, but i feel that is too restrictive for other use cases. Especially when one wants to validate DLL using an out of band signing process.