-
Notifications
You must be signed in to change notification settings - Fork 7
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
fix: JAVA_HOME points to JRE directory on OpenJDK8, should instead point to JDK directory #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
I will take a look at it, but after briefly checking the changes, I guess there is at least a small typo to fix.
.github/workflows/ci-workflow.yml
Outdated
distribution: 'temurin' | ||
- name: Test Rust with Cargo | ||
run: JAVAM_HOME="" cargo test --features=legacy-java-compat --verbose -- --nocapture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be JAVA_HOME
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, thank you!
The way I see it, a directory like Having the env var
The system uses the JRE instead of the JDK and thus, there are no headers, similarly, there is no
If the user wants to use the JDK instead, they need to set the
Is there a reason why not to set the |
You are describing the issue precisely, I think the only thing missing is that JAVA_HOME is a variable that should point to the JDK directory, not the JRE directory, this just means that the locate_java_home function returns an invalid value for JDK8, and while indeed setting JAVA_HOME manually fixes this, this crate does expose locate_java_home() to the user, meaning(in my opinion only, ofc) it should guarantee a valid JAVA_HOME value, not just a valid dyn library The way I encountered the issue, for example:
Up until now I've resolved it by setting JAVA_HOME manually, but this is really something I'd rather not do system-wide, and doing it per project requires me to modify the IDE settings both for the Rust build, the Terminal I use to run tests manually, and for the Run settings, which becomes an annoyance. If you feel like this is something you don't want to get into that's fine as well, this PR is just a suggestion^ |
I understand. However, when the system is actually configured in a way to give the path The best solution IMO, would be to configure the system to use the
Now you should get:
And if you execute
However, I believe it is much easier if you just pass the
How does it sound? |
Thinking it twice, we could maybe add a feature like "locate-jdks-only". This way, we could change the implementation of do_locate_java_home to use Doing so, the Would you care implementing this? |
I've moved to your suggestion implementation, let me know if this approach suffices, and on a sidenote thank you for being so responsive! |
Thanks for taking the time to implement this. As you see, some tests failed. I was thinking of a much simpler solution, with no fallbacks: If the feature It is better to be explicit and for example fail if JDK is not installed in the system, while the user explicitly wants a JDK (by enabling the feature). |
…eflect the new approach.
Sorry, missed the specific macos test, updated to use a feature gate for the binary name, with no fallback |
Looks good! Let's merge this, even if the new feature does not have impact for macos. We can take care about this in documentation for now. Thanks once again. |
This is in regards to the fact that in Java 8, the directory structure was such that the actual
java
binary, was in${JAVA_HOME}/jre/bin/java
instead of${JAVA_HOME}/bin/java
, which was instead just a symlink.Due to the way we recursively follow the symlinks, we'd end up in the wrong directory for Java 8.
This is ok for locating
libjvm.so
, as it is found using glob and it is within thejre
directory, but causes issues with other expected JDK files, such as headers etc.I propose in this PR to just add a "legacy-java-compat" feature, which when enabled, will let us check if the final result is the "jre" directory, if it is - we'll just traverse one directory up.
This is feature-gated in case other projects using Java 8 have already made their own workarounds, so we don't make a breaking change.
I've added a test using the Temurin 8 release + clearing the automatic JAVA_HOME env, to ensure the behaviour is fixed.
(Note that this entire problem is only relevant on Java installation methods that don't set JAVA_HOME, such as, when installing openjdk8 using apt)
I've also updated the github actions for checkout and setup-java, but that is not mandatory at all and I can revert that if you prefer