Skip to content

Conversation

@chrisnovakovic
Copy link
Contributor

The Java compiler outputs header files for Java sources that use the Java Native Interface (JNI), but there's currently no way for them to be consumed by the native-code components that depend on them, preventing them from being built.

Provide the JNI headers as outputs of java_library when cc_hdrs is required. This allows native-code JNI components written in C/C++ to be built by including the java_library target as a dependency.

javac_flags = CONFIG.JAVAC_TEST_FLAGS if test_only else CONFIG.JAVAC_FLAGS
javac_flags = '-g -encoding utf8 ' + javac_flags
javac_flags = '-h _jni -g -encoding utf8 ' + javac_flags
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be any significant overhead in invoking the compiler with -h even when the JNI headers aren't needed (at least not compared with the time it takes to generate the class files).

Comment on lines 102 to 105
javac_cmd,
"find _jni -type f -name '*.h' | sort",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be safe because javac only ever outputs on stderr by default, so it shouldn't mess up the post-build output collection.

@peterebden
Copy link
Collaborator

Thanks! Would you mind please opening this against https://github.com/please-build/java-rules instead? Those plugin repos are where future development of language-specific rules will happen.

I have a couple of comments too but let's pick the conversation up there :)

@chrisnovakovic chrisnovakovic force-pushed the java_library-jni-headers branch from 4377be5 to e44cd56 Compare August 8, 2022 15:39
@chrisnovakovic
Copy link
Contributor Author

Thanks! Would you mind please opening this against https://github.com/please-build/java-rules instead? Those plugin repos are where future development of language-specific rules will happen.

I have a couple of comments too but let's pick the conversation up there :)

Will do - I noticed a couple of CI failures in here that I didn't see over there, so I'll fix those, then force-push equivalent changes to please-build/java-rules#13.

@chrisnovakovic chrisnovakovic force-pushed the java_library-jni-headers branch from e44cd56 to bc14739 Compare August 8, 2022 15:50
The Java compiler outputs header files for Java sources that use the
Java Native Interface (JNI), but there's currently no way for them to be
consumed by the native-code components that depend on them, preventing
them from being built.

Provide the JNI headers as outputs of `java_library` when `cc_hdrs` is
required. This allows native-code JNI components written in C/C++ to be
built by including the `java_library` target as a dependency.
@chrisnovakovic chrisnovakovic force-pushed the java_library-jni-headers branch from b2a6703 to 4d0a354 Compare August 8, 2022 18:19
@stale
Copy link

stale bot commented Nov 9, 2022

This issue has been automatically marked as stale because it has not had any recent activity in the past 90 days. It will be closed if no further activity occurs. If you require additional support, please reply to this message. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 9, 2022
@stale stale bot closed this Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants