-
Notifications
You must be signed in to change notification settings - Fork 157
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
Remove default search paths for Unix systems #264
base: master
Are you sure you want to change the base?
Conversation
The JDK already includes the default search paths for Unix/Linux through it's system property `java.library.path` You can see the default path set by the JDK for Unix/Linux here: https://github.com/AdoptOpenJDK/openjdk-jdk8u/blob/master/hotspot/src/os/linux/vm/os_linux.cpp#L371 In an effort to enforce reproducibility for the NixOS project, we've recently patched the JDK8 to clear out the default java.library.path NixOS/nixpkgs#123708 Unfortunately, this does not bubble up to the Jnr-FFI since they additionally hardcode the values. This commit removes that hardcoded list.
I added this because macOS didn't include these paths by default or even any reasonable Unix lib paths at all. I retried this today with different JDKs (adoptopenjdk 8,11 and 16) to similar results. I believe those paths that are returned from I agree with you that hard-coding them probably wasn't the right solution, at least for GNU/Linux. I think the better solution might be to change: if (Platform.getNativePlatform().isUnix()) to: if (Platform.getNativePlatform().getOS() == Platform.OS.DARWIN) Removing the hard-coded values from macOS means consumers have to manually add them which might not be a good idea? I don't know, it's annoying that macOS doesn't have an elegant solution to custom lib paths like GNU/Linux does. This is honestly more of a macOS problem than a Unix one because even the system dylibs are in obscure places that are not easy to deterministically get. I can always check if What's your opinion on this? Pinging @headius as well for his opionion |
@basshelal I'm not on Darwin so I can't test but the source code looks like it has similar default paths.
Hardcoding paths cannot be the answer here. I am in full support of this change and disagree that it should be kept even for Darwin. |
I never got these no matter what I tried, only paths relating to the jvm dylib locations. I must be doing something wrong. Even then though, If I'm not doing anything wrong then there is no elegant solution. Hardcoding is wrong but macOS is just stupid if this is the case, consumers have to be aware that macOS does not provide you with system-wide default locations and you have to add them yourself, even for a simple search. So if you have We need to make sure consumers aware of this in case they waste time like I did wondering why JNR-FFI can't find their newly installed |
I would like to spin some JNR releases today in advance of the JRuby 9.3 release, but I think this PR still has some open questions at least on Darwin. @basshelal @fzakaria did you have any other conversations about this? |
I still don't believe the approach taken earlier was correct -- the search paths added aren't even idiomatic in MacOS as places to search. I will fork it for our own needs to maintain hermeticity for the work we are doing but wanted to contribute the work upstream. Thank you for your time reviewing it. I don't think there's a rush to get it approved (although I would be in favor of it). |
I confirmed locally what @basshelal pointed out: Darwin OpenJDK/Hotspot does not include any of the standard lib paths in
This is confirmed on 11 and 17. Interestingly, OpenJ9 does include one standard path:
So we at least have one proven case where the default (i.e. unmodified) |
At least one other JDK hacker, @shipilev, believes this may be a bug, so I have filed an issue with OpenJDK: https://bugs.openjdk.java.net/browse/JDK-8273222 |
Can the default lib paths be configurable via a system property or environment variable before falling back to the hard-coded values? |
The JDK already includes the default search paths for Unix/Linux through it's system property
java.library.path
You can see the default path set by the JDK for Unix/Linux here
In an effort to enforce reproducibility for the NixOS project, we've recently patched the JDK8 to clear out the default
java.library.path
- NixOS/nixpkgs#123708Unfortunately, this does not bubble up to thejnr-ffi gem since they additionally hardcode the values.
This contribution removes that hardcoded list. In the normal case, the list remains the same since it will get the default list through
java.library.path
however now it can be cleared out appropriately.