Skip to content

Commit

Permalink
Move TextGenerator Java build rules
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599623956
  • Loading branch information
schmidt-sebastian authored and copybara-github committed Jan 18, 2024
1 parent 0f1112f commit 0aaf40f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cc_library(
"//mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/proto:llm_options_cc_proto",
"//mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/proto:llm_response_context_cc_proto",
"@com_google_absl//absl/status",
"@odml//infra/genai/inference/c:libllm_inference_engine",
"@odml//odml/infra/genai/inference/c:libllm_inference_engine",
] + select({
"//mediapipe:android": [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "mediapipe/java/com/google/mediapipe/framework/jni/jni_util.h"
#include "mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/proto/llm_options.pb.h"
#include "mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/proto/llm_response_context.pb.h"
#include "third_party/odml/infra/genai/inference/c/llm_inference_engine.h"
#include "odml/infra/genai/inference/c/llm_inference_engine.h"

namespace {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

"""Building MediaPipe Tasks AARs."""

load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_build_aar_with_jni", "mediapipe_java_proto_src_extractor", "mediapipe_java_proto_srcs", "mediapipe_logging_java_proto_srcs")
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("//mediapipe/java/com/google/mediapipe:mediapipe_aar.bzl", "mediapipe_build_aar_with_jni", "mediapipe_java_proto_src_extractor", "mediapipe_java_proto_srcs", "mediapipe_logging_java_proto_srcs")

_CORE_TASKS_JAVA_PROTO_LITE_TARGETS = [
"//mediapipe/gpu:gpu_origin_java_proto_lite",
Expand Down Expand Up @@ -93,6 +93,10 @@ _TEXT_TASKS_JAVA_PROTO_LITE_TARGETS = [
"//mediapipe/tasks/cc/text/text_embedder/proto:text_embedder_graph_options_java_proto_lite",
]

_TEXT_TASKS_TEXT_GENERATOR_JAVA_PROTO_LITE_TARGETS = [
"//mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni/proto:llm_options_java_proto_lite",
]

def mediapipe_tasks_core_aar(name, srcs, manifest):
"""Builds medaipipe tasks core AAR.
Expand Down Expand Up @@ -354,6 +358,39 @@ EOF
native_library = native_library,
)

def mediapipe_tasks_text_text_generator_aar(name, srcs, native_library):
"""Builds medaipipe tasks text text generator AAR.
Args:
name: The bazel target name.
srcs: MediaPipe Text Generator Tasks' source files.
native_library: The native library that contains text generator task's graph and calculators.
"""

native.genrule(
name = name + "tasks_manifest_generator",
outs = ["AndroidManifest.xml"],
cmd = """
cat > $(OUTS) <<EOF
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.mediapipe.tasks.text.textgenerator">
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="30" />
</manifest>
EOF
""",
)

_mediapipe_tasks_aar(
name = name,
srcs = srcs,
manifest = "AndroidManifest.xml",
java_proto_lite_targets = _CORE_TASKS_JAVA_PROTO_LITE_TARGETS + _TEXT_TASKS_TEXT_GENERATOR_JAVA_PROTO_LITE_TARGETS,
native_library = native_library,
)

def _mediapipe_tasks_aar(name, srcs, manifest, java_proto_lite_targets, native_library):
"""Builds medaipipe tasks AAR."""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

cc_binary(
name = "libllm_inference_engine_jni.so",
linkopts = [
"-Wl,-soname=libllm_inference_engine_jni.so",
"-fvisibility=hidden",
],
linkshared = 1,
deps = ["//mediapipe/tasks/java/com/google/mediapipe/tasks/core/jni:llm"],
)

cc_library(
name = "libllm_inference_engine_jni_lib",
srcs = [":libllm_inference_engine_jni.so"],
alwayslink = 1,
)

load("//mediapipe/tasks/java/com/google/mediapipe/tasks:mediapipe_tasks_aar.bzl", "mediapipe_tasks_text_text_generator_aar")

mediapipe_tasks_text_text_generator_aar(
name = "tasks_text_text_generator",
srcs = glob(["*.java"]),
native_library = ":libllm_inference_engine_jni_lib",
)

0 comments on commit 0aaf40f

Please sign in to comment.