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( 16 "//kotlin:rules.bzl", 17 "kt_jvm_library", 18 "kt_jvm_test", 19) 20 21package(default_testonly = 1) 22 23licenses(["notice"]) 24 25kt_jvm_library( 26 name = "NativeApiKt", 27 srcs = ["NativeApi.kt"], 28 visibility = ["//tests:__subpackages__"], 29 runtime_deps = [":jni_NativeApi"], 30) 31 32java_library( 33 name = "NativeApiJava", 34 srcs = ["NativeApi.java"], 35 deps = [":libNativeApi.so"], 36) 37 38java_library( 39 name = "NativeApiJava-through_cc_lib", 40 srcs = ["NativeApi.java"], 41 deps = [":native_api_so"], 42) 43 44kt_jvm_library( 45 name = "NativeApiKt-through_cc_lib", 46 srcs = ["NativeApi.kt"], 47 runtime_deps = [":native_api_so"], 48) 49 50cc_library( 51 name = "native_api_so", 52 srcs = [":libNativeApi.so"], 53) 54 55cc_binary( 56 name = "libNativeApi.so", 57 linkshared = 1, 58 linkstatic = 1, 59 deps = [":jni_NativeApi"], 60) 61 62cc_library( 63 name = "jni_NativeApi", 64 srcs = ["jni_NativeApi.cc"], 65 hdrs = ["jni_NativeApi.h"], # manually generated with "javac -h NativeApi.java" 66 deps = ["@bazel_tools//tools/jdk:jni"], 67 alwayslink = 1, 68) 69 70[ 71 kt_jvm_test( 72 name = "NativeApiTest_" + native_loader, 73 srcs = ["NativeApiTest.kt"], 74 args = args, 75 main_class = "jni.NativeApiTestKt", 76 deps = [ 77 native_loader, 78 "@maven//:com_google_truth_truth", 79 "@maven//:junit_junit", 80 ], 81 ) 82 for native_loader, args in { 83 "NativeApiJava": ["--load"], 84 "NativeApiJava-through_cc_lib": ["--load"], 85 "NativeApiKt-through_cc_lib": ["--load"], 86 }.items() 87] 88 89sh_test( 90 name = "jdk_check", 91 srcs = ["jdk_check.sh"], 92) 93