xref: /aosp_15_r20/external/bazelbuild-kotlin-rules/tests/jvm/java/jni/BUILD (revision 3a22c0a33dd99bcca39a024d43e6fbcc55c2806e)
1# Copyright 2022 Google LLC. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the License);
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("//kotlin:rules.bzl", "kt_jvm_library", "kt_jvm_test")
16
17package(
18    default_testonly = 1,
19)
20
21licenses(["notice"])
22
23kt_jvm_library(
24    name = "NativeApiKt",
25    srcs = ["NativeApi.kt"],
26    visibility = ["//tests:__subpackages__"],
27    runtime_deps = [":jni_NativeApi"],
28)
29
30java_library(
31    name = "NativeApiJava",
32    srcs = ["NativeApi.java"],
33    deps = [":libNativeApi.so"],
34)
35
36java_library(
37    name = "NativeApiJava-through_cc_lib",
38    srcs = ["NativeApi.java"],
39    deps = [":native_api_so"],
40)
41
42kt_jvm_library(
43    name = "NativeApiKt-through_cc_lib",
44    srcs = ["NativeApi.kt"],
45    runtime_deps = [":native_api_so"],
46)
47
48cc_library(
49    name = "native_api_so",
50    srcs = [":libNativeApi.so"],
51)
52
53cc_binary(
54    name = "libNativeApi.so",
55    linkshared = 1,
56    linkstatic = 1,
57    deps = [":jni_NativeApi"],
58)
59
60cc_library(
61    name = "jni_NativeApi",
62    srcs = ["jni_NativeApi.cc"],
63    hdrs = ["jni_NativeApi.h"],  # manually generated with "javac -h NativeApi.java"
64    deps = ["@bazel_tools//tools/jdk:jni"],
65    alwayslink = 1,
66)
67
68[
69    kt_jvm_test(
70        name = "NativeApiTest_" + native_loader,
71        srcs = ["NativeApiTest.kt"],
72        args = args,
73        main_class = "jni.NativeApiTestKt",
74        deps = [
75            native_loader,
76            "@maven//:com_google_truth_truth",
77            "@maven//:junit_junit",
78        ],
79    )
80    for native_loader, args in {
81        "NativeApiJava": ["--load"],
82        "NativeApiJava-through_cc_lib": ["--load"],
83        "NativeApiKt-through_cc_lib": ["--load"],
84    }.items()
85]
86
87sh_test(
88    name = "jdk_check",
89    srcs = ["jdk_check.sh"],
90)
91