Dynamically load libjvm rather than requiring it at build time#8
Merged
ktoso merged 8 commits intoswiftlang:mainfrom Mar 11, 2026
Merged
Dynamically load libjvm rather than requiring it at build time#8ktoso merged 8 commits intoswiftlang:mainfrom
ktoso merged 8 commits intoswiftlang:mainfrom
Conversation
ktoso
reviewed
Mar 11, 2026
Collaborator
ktoso
left a comment
There was a problem hiding this comment.
That's an interesting idea, I think this might work? Thanks for looking into it Marc
Collaborator
|
Refs #3 |
Collaborator
|
I think we're happy with this, as this is derived from the spec and we don't copy the actual jni.h anywhere this makes sense we think. Thanks for pouring in the work and idea @marcprux ! |
ktoso
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR removes the build/link time requirement for
libjvmand moves it intodlload/dlsymcalls fromJavaVirtualMachine.shared(). This greatly simplifies thePackage.swiftbuild by eliminating all the tool calls and path searching, and enablesswift-java-jni-coreto be a build dependency in environments that do not have any JVM installed. For example, it can be a transitive dependency for iOS libraries, where it won't actually work if you tried to use it, but it will build.Since
<jni.h>is no longer needed, we declare a minimal subset of the function table and types described in the JNI specification right intoCSwiftJavaJNI.h. The only symbols we need to dynamically load and invoke areJNI_GetCreatedJavaVMsandJNI_CreateJavaVM; everything else falls out of the function tables.Tested on macOS (with
swift test) and an Android 28 emulator (withskip android test).