Skip to content

Commit 254e907

Browse files
java_toolchain: expose JNI headers to C/C++ targets (#17)
* java_toolchain: expose JNI headers to C/C++ targets If the toolchain is a JDK, this allows the `c_shared_object` and `cc_shared_object` rules to find the necessary JDK headers when compiling JNI sources simply by adding the toolchain target to `hdrs`. * Address comments
1 parent 5fb54f6 commit 254e907

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

build_defs/java.build_defs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,16 @@ def _java_toolchain(name : str, jdk_url : str|dict='', jdk:str='', visibility:li
539539
hashes = hashes,
540540
)
541541

542+
if CONFIG.OS == "linux" or CONFIG.OS == "darwin" or CONFIG.OS == "freebsd" or CONFIG.OS == "openbsd" or CONFIG.OS == "solaris":
543+
java_platform = CONFIG.OS
544+
elif CONFIG.OS == "windows":
545+
java_platform = "win32"
546+
547+
include_root = join_path(subrepo_name(), package_name(), name, "include")
548+
labels = ["cc:inc:" + include_root]
549+
if java_platform:
550+
labels += ["cc:inc:" + join_path(include_root, java_platform)]
551+
542552
return build_rule(
543553
name = name,
544554
srcs = [jdk],
@@ -555,6 +565,7 @@ def _java_toolchain(name : str, jdk_url : str|dict='', jdk:str='', visibility:li
555565
"java": f"{name}/bin/java",
556566
"javac": f"{name}/bin/javac",
557567
},
568+
labels = labels,
558569
visibility = visibility,
559570
)
560571

0 commit comments

Comments
 (0)