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.

@chrisnovakovic
Copy link
Contributor Author

(This is a mirror of thought-machine/please#2525.)

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 4f503e8 to 8565012 Compare August 9, 2022 13:27

def _jni_header_outputs(name, output):
for hdr_path in output:
if hdr_path != "":
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 is just to guard against the command outputting \n when no headers are generated.

},
cmd = " && ".join([
"mkdir -p _jni",
f"{javac_cmd} -h _jni >/dev/null 2>&1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Silencing the output of javac here as a precaution because it's possible to instruct javac to output to stdout instead of stderr using a command line option (i.e. via javac_flags) - it's an edge case, but one that'll break this target if it's used. The main target will still show compilation errors for the class files.

@chrisnovakovic chrisnovakovic marked this pull request as ready for review August 9, 2022 13:43
@chrisnovakovic chrisnovakovic marked this pull request as draft August 9, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant