From c80372681c5ec87087ed1368bd58b82547e93fca Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 16 Jan 2024 16:35:17 -0800 Subject: [PATCH] Clean up BUILD file duplication in java/.../tasks/.../jni directory PiperOrigin-RevId: 598994968 --- .../com/google/mediapipe/tasks/core/jni/BUILD | 31 +++++++- .../mediapipe/tasks/core/jni/BUILD.bazel | 72 ------------------- 2 files changed, 28 insertions(+), 75 deletions(-) delete mode 100644 mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD.bazel diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD b/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD index 3c755ce02c..8bca172f65 100644 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD +++ b/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD @@ -25,16 +25,24 @@ cc_library_with_tflite( ], hdrs = [ "model_resources_cache_jni.h", - ], + ] + select({ + "//conditions:default": [ + ":jni.h", + ":jni_md.h", + ], + # The Android toolchain makes "jni.h" available in the include path. + # For non-Android toolchains, generate jni.h and jni_md.h. + "//mediapipe:android": [], + }), tflite_deps = [ "//mediapipe/tasks/cc/core:model_resources_cache", - "@org_tensorflow//tensorflow/lite/kernels:builtin_ops", ], deps = [ "//mediapipe/java/com/google/mediapipe/framework/jni:mediapipe_framework_jni", "//mediapipe/tasks/cc/core:mediapipe_builtin_op_resolver", ] + select({ - "//conditions:default": ["//third_party/java/jdk:jni"], + "//conditions:default": [ + ], "//mediapipe:android": [], }), alwayslink = 1, @@ -67,3 +75,20 @@ cc_binary( linkshared = 1, deps = [":llm"], ) + +genrule( + name = "copy_jni_h", + srcs = ["@bazel_tools//tools/jdk:jni_header"], + outs = ["jni.h"], + cmd = "cp -f $< $@", +) + +genrule( + name = "copy_jni_md_h", + srcs = select({ + "//mediapipe:macos": ["@bazel_tools//tools/jdk:jni_md_header-darwin"], + "//conditions:default": ["@bazel_tools//tools/jdk:jni_md_header-linux"], + }), + outs = ["jni_md.h"], + cmd = "cp -f $< $@", +) diff --git a/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD.bazel b/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD.bazel deleted file mode 100644 index 4a82352005..0000000000 --- a/mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/BUILD.bazel +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2022 The MediaPipe Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@org_tensorflow//tensorflow/lite/core/shims:cc_library_with_tflite.bzl", "cc_library_with_tflite") - -package(default_visibility = ["//mediapipe/tasks:internal"]) - -cc_library_with_tflite( - name = "model_resources_cache_jni", - srcs = [ - "model_resources_cache_jni.cc", - ], - hdrs = [ - "model_resources_cache_jni.h", - ] + select({ - # The Android toolchain makes "jni.h" available in the include path. - # For non-Android toolchains, generate jni.h and jni_md.h. - "//mediapipe:android": [], - "//conditions:default": [ - ":jni.h", - ":jni_md.h", - ], - }), - tflite_deps = [ - "//mediapipe/tasks/cc/core:model_resources_cache", - ], - deps = [ - "//mediapipe/java/com/google/mediapipe/framework/jni:mediapipe_framework_jni", - "//mediapipe/tasks/cc/core:mediapipe_builtin_op_resolver", - ] + select({ - "//conditions:default": [], - "//mediapipe:android": [], - }), - alwayslink = 1, -) - -# Silly rules to make -# #include -# in the source headers work -# (in combination with the "includes" attribute of the tf_cuda_library rule -# above. Not needed when using the Android toolchain). -# -# Inspired from: -# https://github.com/bazelbuild/bazel/blob/f99a0543f8d97339d32075c7176b79f35be84606/src/main/native/BUILD -# but hopefully there is a simpler alternative to this. -genrule( - name = "copy_jni_h", - srcs = ["@bazel_tools//tools/jdk:jni_header"], - outs = ["jni.h"], - cmd = "cp -f $< $@", -) - -genrule( - name = "copy_jni_md_h", - srcs = select({ - "//mediapipe:macos": ["@bazel_tools//tools/jdk:jni_md_header-darwin"], - "//conditions:default": ["@bazel_tools//tools/jdk:jni_md_header-linux"], - }), - outs = ["jni_md.h"], - cmd = "cp -f $< $@", -)