From a7743996303b87c9754cf5fffd58381b451e096b Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:02:16 +0530 Subject: [PATCH 01/20] Added targets for iOS text frameworks --- mediapipe/tasks/ios/BUILD | 100 ++++++++++++++++++ mediapipe/tasks/ios/ios.bzl | 37 +++++++ .../tasks/ios/text/text_classifier/BUILD | 8 +- mediapipe/tasks/ios/text/text_embedder/BUILD | 8 +- 4 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 mediapipe/tasks/ios/BUILD diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD new file mode 100644 index 000000000..8786ed49f --- /dev/null +++ b/mediapipe/tasks/ios/BUILD @@ -0,0 +1,100 @@ +# Copyright 2023 The MediaPipe Authors. All Rights Reserved. +# +# 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( + "//mediapipe/tasks/ios:ios.bzl", + "MPP_TASK_MINIMUM_OS_VERSION", + "strip_api_include_path_prefix", +) +load( + "@build_bazel_rules_apple//apple:apple.bzl", + "apple_static_xcframework", + "apple_static_library", +) + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +config_setting( + name = "avoid_linking_graphs", + define_values = { + "MEDIAPIPE_AVOID_LINKING_GRAPHS": "1", + }, + visibility = ["//visibility:public"], +) + +strip_api_include_path_prefix( + name = "strip_api_include_path", + hdr_labels = [ + "//mediapipe/tasks/ios/common:sources/MPPCommon.h", + "//mediapipe/tasks/ios/components/containers:sources/MPPCategory.h", + "//mediapipe/tasks/ios/components/containers:sources/MPPClassificationResult.h", + "//mediapipe/tasks/ios/components/containers:sources/MPPEmbedding.h", + "//mediapipe/tasks/ios/components/containers:sources/MPPEmbeddingResult.h", + "//mediapipe/tasks/ios/core:sources/MPPBaseOptions.h", + "//mediapipe/tasks/ios/core:sources/MPPTaskOptions.h", + "//mediapipe/tasks/ios/core:sources/MPPTaskResult.h", + "//mediapipe/tasks/ios/text/text_classifier:sources/MPPTextClassifier.h", + "//mediapipe/tasks/ios/text/text_classifier:sources/MPPTextClassifierOptions.h", + "//mediapipe/tasks/ios/text/text_classifier:sources/MPPTextClassifierResult.h", + "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedder.h", + "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedderOptions.h", + "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedderResult.h", + ], +) + +apple_static_xcframework( + name = "MediaPipeTaskText_framework", + public_hdrs = [ + ":MPPBaseOptions.h", + ":MPPCategory.h", + ":MPPClassificationResult.h", + ":MPPEmbedding.h", + ":MPPEmbeddingResult.h", + ":MPPCommon.h", + ":MPPTaskOptions.h", + ":MPPTaskResult.h", + ":MPPTextClassifier.h", + ":MPPTextClassifierOptions.h", + ":MPPTextClassifierResult.h", + ":MPPTextEmbedder.h", + ":MPPTextEmbedderOptions.h", + ":MPPTextEmbedderResult.h", + ], + bundle_name = "MediaPipeTaskText", + ios = { + "simulator" : ["arm64", "x86_64"], + "device" : ["arm64"], + }, + minimum_os_versions = { + "ios": MPP_TASK_MINIMUM_OS_VERSION, + }, + deps = [ + "//mediapipe/tasks/ios/text/text_classifier:MPPTextClassifier", + "//mediapipe/tasks/ios/text/text_embedder:MPPTextEmbedder", + "@org_tensorflow//third_party/icu/data:conversion_data", + ], +) + +apple_static_library( + name = "MediaPipeTaskText_GraphLibrary", + platform_type = "ios", + minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION, + deps = [ + "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", + "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", + "@org_tensorflow//third_party/icu/data:conversion_data", + ], +) \ No newline at end of file diff --git a/mediapipe/tasks/ios/ios.bzl b/mediapipe/tasks/ios/ios.bzl index 8fe2a24a1..fdfc85d5f 100644 --- a/mediapipe/tasks/ios/ios.bzl +++ b/mediapipe/tasks/ios/ios.bzl @@ -1,3 +1,40 @@ """MediaPipe Task Library Helper Rules for iOS""" MPP_TASK_MINIMUM_OS_VERSION = "11.0" + +# When the static framework is built with bazel, the all header files are moved +# to the "Headers" directory with no header path prefixes. This auxiliary rule +# is used for stripping the path prefix to the C/iOS API header files included by +# other C/iOS API header files. +# In case of C header files includes start with a keyword of "#include'. +# Imports in iOS header files start with a keyword of '#import'. +def strip_api_include_path_prefix(name, hdr_labels, prefix = ""): + """Create modified header files with the import path stripped out. + + Args: + name: The name to be used as a prefix to the generated genrules. + hdr_labels: List of header labels to strip out the include path. Each + label must end with a colon followed by the header file name. + prefix: Optional prefix path to prepend to the header inclusion path. + """ + for hdr_label in hdr_labels: + hdr_filename = hdr_label.split(":")[-1] + + # The last path component of iOS header files is sources/some_file.h + # Hence it wiill contain a '/'. So the string can be split at '/' to get + # the header file name. + if "/" in hdr_filename: + hdr_filename = hdr_filename.split("/")[-1] + + hdr_basename = hdr_filename.split(".")[0] + native.genrule( + name = "{}_{}".format(name, hdr_basename), + srcs = [hdr_label], + outs = [hdr_filename], + cmd = """ + sed 's|#\\([a-z]*\\) ".*/\\([^/]\\{{1,\\}}\\.h\\)"|#\\1 "{}\\2"|'\ + "$(location {})"\ + > "$@" + """.format(prefix, hdr_label), + ) + diff --git a/mediapipe/tasks/ios/text/text_classifier/BUILD b/mediapipe/tasks/ios/text/text_classifier/BUILD index 7913340ac..97cf27677 100644 --- a/mediapipe/tasks/ios/text/text_classifier/BUILD +++ b/mediapipe/tasks/ios/text/text_classifier/BUILD @@ -49,7 +49,6 @@ objc_library( ":MPPTextClassifierOptions", ":MPPTextClassifierResult", "//mediapipe/tasks/cc/components/containers/proto:classifications_cc_proto", - "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/common/utils:NSStringHelpers", "//mediapipe/tasks/ios/core:MPPTaskInfo", @@ -58,5 +57,10 @@ objc_library( "//mediapipe/tasks/ios/text/core:MPPTextTaskRunner", "//mediapipe/tasks/ios/text/text_classifier/utils:MPPTextClassifierOptionsHelpers", "//mediapipe/tasks/ios/text/text_classifier/utils:MPPTextClassifierResultHelpers", - ], + ] + select({ + "//mediapipe/tasks/ios:avoid_linking_graphs": [], + "//conditions:default": [ + "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", + ], + }), ) diff --git a/mediapipe/tasks/ios/text/text_embedder/BUILD b/mediapipe/tasks/ios/text/text_embedder/BUILD index a600d5366..a2edd8a2a 100644 --- a/mediapipe/tasks/ios/text/text_embedder/BUILD +++ b/mediapipe/tasks/ios/text/text_embedder/BUILD @@ -48,7 +48,6 @@ objc_library( deps = [ ":MPPTextEmbedderOptions", ":MPPTextEmbedderResult", - "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/common/utils:NSStringHelpers", "//mediapipe/tasks/ios/components/utils:MPPCosineSimilarity", @@ -58,5 +57,10 @@ objc_library( "//mediapipe/tasks/ios/text/core:MPPTextTaskRunner", "//mediapipe/tasks/ios/text/text_embedder/utils:MPPTextEmbedderOptionsHelpers", "//mediapipe/tasks/ios/text/text_embedder/utils:MPPTextEmbedderResultHelpers", - ], + ] + select({ + "//mediapipe/tasks/ios:avoid_linking_graphs": [], + "//conditions:default": [ + "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", + ], + }), ) From 7ad2b7b32f205a4e715fa3fc7caaf34a55373544 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:02:35 +0530 Subject: [PATCH 02/20] Added shell script for building cocoapods archive --- mediapipe/tasks/ios/build_ios_framework.sh | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100755 mediapipe/tasks/ios/build_ios_framework.sh diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh new file mode 100755 index 000000000..c27a578aa --- /dev/null +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -0,0 +1,184 @@ +#!/usr/bin/env bash +# Copyright 2023 The MediaPipe Authors. All Rights Reserved. +# +# 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. + +# Set the following variables as appropriate. +# * BAZEL: path to bazel. defaults to the first one available in PATH +# * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the +# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. +# * MPP_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev +# * IS_RELEASE_BUILD: set as true if this build should be a release build +# * ARCHIVE_FRAMEWORK: set as true if the framework should be archived +# * DEST_DIR: destination directory to which the framework will be copied + +set -ex + +if [[ "$(uname)" != "Darwin" ]]; then + echo "This build script only works on macOS." + exit 1 +fi + +BAZEL="${BAZEL:-$(which bazel)}" +MPP_BUILD_VERSION=${MPP_BUILD_VERSION:-0.0.1-dev} +MPP_ROOT_DIR=$(git rev-parse --show-toplevel) +MPP_DISABLE_GPU=true + +if [[ ! -x "${BAZEL}" ]]; then + echo "bazel executable is not found." + exit 1 +fi + +if [ -z ${FRAMEWORK_NAME+x} ]; then + echo "Name of the iOS framework, which is to be built, must be set." + exit 1 +fi + +case $FRAMEWORK_NAME in + "MediaPipeTaskText") + ;; + *) + echo "Wrong framework name. The following framework names are allowed: MediaPipeTaskText" + exit 1 + ;; +esac + +if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${MPP_ROOT_DIR}* ]]; then + echo "DEST_DIR variable must be set and not be under the repository root." + exit 1 +fi + +# get_output_file_path takes one bazel target label as an argument, and prints +# the path of the first output file of the specified target. +function get_output_file_path { + local STARLARK_OUTPUT_TMPDIR="$(mktemp -d)" + + local STARLARK_FILE="${STARLARK_OUTPUT_TMPDIR}/print_output_file.starlark" + cat > "${STARLARK_FILE}" << EOF +def format(target): + return target.files.to_list()[0].path +EOF + + local OUTPUT_PATH=$(bazel cquery $1 --output=starlark --starlark:file="${STARLARK_FILE}" 2> /dev/null) + + rm -rf "${STARLARK_OUTPUT_TMPDIR}" + + echo ${OUTPUT_PATH} +} + +# build_target builds a target using the command passed in as argument and +# uses cquery to find the path to the output of the target. +function build_target { + # Build using the command passed as argument. + "${BAZEL}" build $1 + + # Get the path to the output file of the target. + local OUTPUT_PATH=$(get_output_file_path "$1") + + echo ${OUTPUT_PATH} +} + +# build_ios_frameworks_and_libraries builds 3 targets: +# 1. The ios task library xcframework +# 2. Fat static library including graphs needed for the xcframework for all simulator archs (x86_64, arm64). +# 2. Static library including graphs needed for the xcframework for all iOS device archs (arm64). +function build_ios_frameworks_and_libraries { + local TARGET_PREFIX="//mediapipe/tasks/ios" + FULL_FRAMEWORK_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" + FULL_GRAPH_LIBRARY_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_GraphLibrary" + + local FRAMEWORK_CQUERY_COMMAND="-c opt --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --define MEDIAPIPE_AVOID_LINKING_GRAPHS=1 \ + --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" + IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" + + local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ + --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" + IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" + + local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ + --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" + IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" +} + +function create_framework_archive { + # Change to the Bazel iOS output directory. + pushd "${BAZEL_IOS_OUTDIR}" + + # Create the temporary directory for the given framework. + local ARCHIVE_NAME="${FRAMEWORK_NAME}-${MPP_BUILD_VERSION}" + local MPP_TMPDIR="$(mktemp -d)" + + # Copy the license file to MPP_TMPDIR + cp "LICENSE" ${MPP_TMPDIR} + + # Unzip the iOS framework zip generated by bazel to MPP_TMPDIR + local FRAMEWORKS_DIR="${MPP_TMPDIR}/frameworks" + + echo ${IOS_FRAMEWORK_PATH} + unzip "${IOS_FRAMEWORK_PATH}" -d "${FRAMEWORKS_DIR}" + + local GRAPH_LIBRARIES_DIR="graph_libraries" + + # Create the parent folder which will hold the graph libraries of all architectures. + mkdir -p "${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}" + + local SIMULATOR_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_simulator_graph.a" + + # Copy ios simulator fat library into a separate directory. + echo ${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH} + cp "${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH}" "${SIMULATOR_GRAPH_LIBRARY_PATH}" + + + local IOS_DEVICE_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_device_graph.a" + + # Copy ios device library into a separate directory. + echo ${IOS_GRAPHS_DEVICE_LIBRARY_PATH} + cp "${IOS_GRAPHS_DEVICE_LIBRARY_PATH}" "${IOS_DEVICE_GRAPH_LIBRARY_PATH}" + + #----- (3) Move the framework to the destination ----- + if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then + local TARGET_DIR="$(realpath "${FRAMEWORK_NAME}")" + + # Create the framework archive directory. + + local FRAMEWORK_ARCHIVE_DIR + if [[ "${IS_RELEASE_BUILD}" == true ]]; then + # Get the first 16 bytes of the sha256 checksum of the root directory. + local SHA256_CHECKSUM=$(find "${MPP_TMPDIR}" -type f -print0 | xargs -0 shasum -a 256 | sort | shasum -a 256 | cut -c1-16) + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${MPP_BUILD_VERSION}/${SHA256_CHECKSUM}" + else + FRAMEWORK_ARCHIVE_DIR="${TARGET_DIR}/${MPP_BUILD_VERSION}" + fi + mkdir -p "${FRAMEWORK_ARCHIVE_DIR}" + + # Zip up the framework and move to the archive directory. + pushd "${MPP_TMPDIR}" + local MPP_ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz" + tar -cvzf "${MPP_ARCHIVE_FILE}" . + mv "${MPP_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}" + popd + + # Move the target directory to the Kokoro artifacts directory. + mv "${TARGET_DIR}" "$(realpath "${DEST_DIR}")"/ + else + rsync -r "${MPP_TMPDIR}/" "$(realpath "${DEST_DIR}")/" + fi + + # Clean up the temporary directory for the framework. + rm -rf "${MPP_TMPDIR}" + echo ${MPP_TMPDIR} +} + +cd "${MPP_ROOT_DIR}" +build_ios_frameworks_and_libraries +create_framework_archive \ No newline at end of file From 49b2c7c2cc2d3fc8ea6b77f9c5168f7658de7fff Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:02:58 +0530 Subject: [PATCH 03/20] Added iOS task text cocoapods podspec --- .../ios/MediaPipeTaskText.podspec.template | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 mediapipe/tasks/ios/MediaPipeTaskText.podspec.template diff --git a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template new file mode 100644 index 000000000..ddc9a2b01 --- /dev/null +++ b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template @@ -0,0 +1,23 @@ +Pod::Spec.new do |s| + s.name = 'MediaPipeTaskText' + s.version = '${MPP_BUILD_VERSION}' + s.authors = 'Google Inc.' + s.license = { :type => 'Apache',:file => "LICENSE" } + s.homepage = 'https://github.com/google/mediapipe' + s.source = { :http => '${MPP_DOWNLOAD_URL}' } + s.summary = 'MediaPipe Task Library - Text' + s.description = 'The Natural Language APIs of the MediaPipe Task Library' + + s.ios.deployment_target = '11.0' + + s.module_name = 'MediaPipeTaskText' + s.static_framework = true + s.user_target_xcconfig = { + 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskText/frameworks/graph_libraries/libMediaPipeTaskText_simulator_graph.a"', + 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskText/frameworks/graph_libraries/libMediaPipeTaskText_device_graph.a"', + 'STRIP_INSTALLED_PRODUCT' => 'NO' + } + s.library = 'c++' + s.preserve_paths = 'frameworks/graph_libraries/*.a' + s.vendored_frameworks = 'frameworks/MediaPipeTaskText.xcframework' +end \ No newline at end of file From d7c96dea6a9dda2f26506adf0149a442431502b0 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:10:47 +0530 Subject: [PATCH 04/20] Updated formatting of files --- mediapipe/tasks/ios/BUILD | 2 +- mediapipe/tasks/ios/MediaPipeTaskText.podspec.template | 2 +- mediapipe/tasks/ios/build_ios_framework.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index 8786ed49f..175d674a8 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -97,4 +97,4 @@ apple_static_library( "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", "@org_tensorflow//third_party/icu/data:conversion_data", ], -) \ No newline at end of file +) diff --git a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template index ddc9a2b01..88ec4d989 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template @@ -20,4 +20,4 @@ Pod::Spec.new do |s| s.library = 'c++' s.preserve_paths = 'frameworks/graph_libraries/*.a' s.vendored_frameworks = 'frameworks/MediaPipeTaskText.xcframework' -end \ No newline at end of file +end diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index c27a578aa..00eab9280 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -181,4 +181,4 @@ function create_framework_archive { cd "${MPP_ROOT_DIR}" build_ios_frameworks_and_libraries -create_framework_archive \ No newline at end of file +create_framework_archive From eb0aa5056ae9361c9605e96a77719972465caeb9 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:20:11 +0530 Subject: [PATCH 05/20] Updated documentation --- mediapipe/tasks/ios/build_ios_framework.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 00eab9280..c0f0f5f1c 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -58,7 +58,7 @@ if [[ -z "${DEST_DIR+x}" || "${DEST_DIR}" == ${MPP_ROOT_DIR}* ]]; then exit 1 fi -# get_output_file_path takes one bazel target label as an argument, and prints +# This function takes one bazel target label as an argument, and prints # the path of the first output file of the specified target. function get_output_file_path { local STARLARK_OUTPUT_TMPDIR="$(mktemp -d)" @@ -76,7 +76,7 @@ EOF echo ${OUTPUT_PATH} } -# build_target builds a target using the command passed in as argument and +# This function builds a target using the command passed in as argument and # uses cquery to find the path to the output of the target. function build_target { # Build using the command passed as argument. @@ -88,23 +88,30 @@ function build_target { echo ${OUTPUT_PATH} } -# build_ios_frameworks_and_libraries builds 3 targets: +# This function builds 3 targets: # 1. The ios task library xcframework -# 2. Fat static library including graphs needed for the xcframework for all simulator archs (x86_64, arm64). +# 2. Fat static library including graphs needed for tasks in xcframework, for all simulator archs (x86_64, arm64). # 2. Static library including graphs needed for the xcframework for all iOS device archs (arm64). function build_ios_frameworks_and_libraries { local TARGET_PREFIX="//mediapipe/tasks/ios" FULL_FRAMEWORK_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" FULL_GRAPH_LIBRARY_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_GraphLibrary" + + # .bazelrc sets --apple_generate_dsym=true by default which bloats the libraries to sizes of the order of GBs. + # All iOS framework and library build commands for distribution via CocoaPods must set + # --apple_generate_dsym=false inorder to shave down the binary size to the order of a few MBs. + # Build Text Task Library xcframework without the graph dependencies. local FRAMEWORK_CQUERY_COMMAND="-c opt --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --define MEDIAPIPE_AVOID_LINKING_GRAPHS=1 \ --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" + # Build fat static library for text task graphs for simulator archs. local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" - + + # Build static library for text task graphs for simulator archs. local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" From 0c4d40547927a2cf0fc48761796ec35520b1da19 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:21:14 +0530 Subject: [PATCH 06/20] Updated bazelrc with required config --- .bazelrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.bazelrc b/.bazelrc index 724dd23fd..44bc3d0a1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -87,6 +87,9 @@ build:ios_fat --config=ios build:ios_fat --ios_multi_cpus=armv7,arm64 build:ios_fat --watchos_cpus=armv7k +build:ios_sim_fat --config=ios +build:ios_sim_fat --ios_multi_cpus=x86_64,sim_arm64 + build:darwin_x86_64 --apple_platform_type=macos build:darwin_x86_64 --macos_minimum_os=10.12 build:darwin_x86_64 --cpu=darwin_x86_64 From f75eb5795658ba9b8806b344da11256321c79e1b Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 18 Apr 2023 23:46:05 +0530 Subject: [PATCH 07/20] Update build_ios_framework.sh --- mediapipe/tasks/ios/build_ios_framework.sh | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index c0f0f5f1c..ecc1acfb4 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -16,11 +16,11 @@ # Set the following variables as appropriate. # * BAZEL: path to bazel. defaults to the first one available in PATH # * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the -# * accepted values are TensorFlowLiteTaskVision, TensorFlowLiteTaskText. +# * accepted values are MediaPipeTaskText. # * MPP_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev # * IS_RELEASE_BUILD: set as true if this build should be a release build # * ARCHIVE_FRAMEWORK: set as true if the framework should be archived -# * DEST_DIR: destination directory to which the framework will be copied +# * DEST_DIR: destination directory to which the framework will be copied. set -ex @@ -32,7 +32,7 @@ fi BAZEL="${BAZEL:-$(which bazel)}" MPP_BUILD_VERSION=${MPP_BUILD_VERSION:-0.0.1-dev} MPP_ROOT_DIR=$(git rev-parse --show-toplevel) -MPP_DISABLE_GPU=true +MPP_DISABLE_GPU=1 if [[ ! -x "${BAZEL}" ]]; then echo "bazel executable is not found." @@ -97,23 +97,25 @@ function build_ios_frameworks_and_libraries { FULL_FRAMEWORK_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" FULL_GRAPH_LIBRARY_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_GraphLibrary" - # .bazelrc sets --apple_generate_dsym=true by default which bloats the libraries to sizes of the order of GBs. - # All iOS framework and library build commands for distribution via CocoaPods must set - # --apple_generate_dsym=false inorder to shave down the binary size to the order of a few MBs. + # .bazelrc sets --apple_generate_dsym=true by default which bloats the libraries to sizes of + # the order of GBs. All iOS framework and library build commands for distribution via + # CocoaPods must set --apple_generate_dsym=false inorder to shave down the binary size to + # the order of a few MBs. # Build Text Task Library xcframework without the graph dependencies. - local FRAMEWORK_CQUERY_COMMAND="-c opt --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --define MEDIAPIPE_AVOID_LINKING_GRAPHS=1 \ - --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" + local FRAMEWORK_CQUERY_COMMAND="-c opt --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ + --define MEDIAPIPE_AVOID_LINKING_GRAPHS=1 --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" # Build fat static library for text task graphs for simulator archs. - local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ - --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" + local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --define \ + MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" - # Build static library for text task graphs for simulator archs. - local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ - --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" + # Build static library for iOS devices with arch ios_arm64. We don't need to build for armv7 since + # our deployment target is iOS 11.0. iOS 11.0 d anupwards is not supported by old armv7 devices. + local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --define \ + MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" } From 99420d35f397a1e3c79cee5c6d29a0ae40432ba1 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Wed, 19 Apr 2023 00:25:10 +0530 Subject: [PATCH 08/20] Update build_ios_framework.sh --- mediapipe/tasks/ios/build_ios_framework.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index ecc1acfb4..48bc0419c 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -90,8 +90,10 @@ function build_target { # This function builds 3 targets: # 1. The ios task library xcframework -# 2. Fat static library including graphs needed for tasks in xcframework, for all simulator archs (x86_64, arm64). -# 2. Static library including graphs needed for the xcframework for all iOS device archs (arm64). +# 2. Fat static library including graphs needed for tasks in xcframework, for all +# simulator archs (x86_64, arm64). +# 3. Static library including graphs needed for the xcframework for all iOS device +# archs (arm64). function build_ios_frameworks_and_libraries { local TARGET_PREFIX="//mediapipe/tasks/ios" FULL_FRAMEWORK_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" From 6eee726025025827dfd64d92caa83daa292ed6d1 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 04:21:41 +0530 Subject: [PATCH 09/20] Updated build rules for iOS frameworks to duplicate symbols --- mediapipe/tasks/ios/BUILD | 117 ++++++++++++++++-- .../tasks/ios/text/text_classifier/BUILD | 8 +- mediapipe/tasks/ios/text/text_embedder/BUILD | 8 +- 3 files changed, 112 insertions(+), 21 deletions(-) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index 175d674a8..c94d1b48e 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -27,13 +27,30 @@ package(default_visibility = ["//visibility:public"]) licenses(["notice"]) -config_setting( - name = "avoid_linking_graphs", - define_values = { - "MEDIAPIPE_AVOID_LINKING_GRAPHS": "1", - }, - visibility = ["//visibility:public"], -) +# list of targets to be added in avoid_deps of ":MediaPipeTaskVision_framework" +# and ":MediaPipeTaskText_framework". +# The transitive closure of the following targets are used for building the +# frameworks but are avoided from the framework binaries to avoid duplicate symbols +# error when included in an xcode project: +# 1. iOS classes shared amongst the various vision and text tasks. These classes +# will be built with ":MediaPipeTaskCommonObjects_framework" +# 2. Task graphs. These will be built with ":MediaPipeTaskGraphs_library". +# 3. gpu targets which will be built with the ":MediaPipeTaskGraphs_library". +OBJC_COMMON_DEPS = [ + "//mediapipe/tasks/ios/core:MPPBaseOptions", + "//mediapipe/tasks/ios/core:MPPTaskInfo", + "//mediapipe/tasks/ios/core:MPPTaskOptions", + "//mediapipe/tasks/ios/core:MPPTaskResult", + "//mediapipe/tasks/ios/core:MPPTaskRunner", + "//mediapipe/tasks/ios/components/containers:MPPClassificationResult", + "//mediapipe/tasks/ios/components/containers:MPPCategory", + "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", + "//mediapipe/tasks/cc/vision/image_classifier:image_classifier_graph", + "//mediapipe/tasks/cc/vision/object_detector:object_detector_graph", + "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", + "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", + "//mediapipe/gpu:metal_shared_resources", +] strip_api_include_path_prefix( name = "strip_api_include_path", @@ -84,17 +101,99 @@ apple_static_xcframework( deps = [ "//mediapipe/tasks/ios/text/text_classifier:MPPTextClassifier", "//mediapipe/tasks/ios/text/text_embedder:MPPTextEmbedder", - "@org_tensorflow//third_party/icu/data:conversion_data", + ], + # avoid dependencies of ":MediaPipeCommonObjects_framework" and + # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error + # when the frameworks are imported in iOS projects. + avoid_deps = OBJC_COMMON_DEPS +) + +apple_static_xcframework( + name = "MediaPipeTaskVision_framework", + public_hdrs = [ + ":MPPBaseOptions.h", + ":MPPCategory.h", + ":MPPClassificationResult.h", + ":MPPDetection.h", + ":MPPCommon.h", + ":MPPTaskOptions.h", + ":MPPTaskResult.h", + ":MPPImage.h", + ":MPPRunningMode.h", + ":MPPImageClassifier.h", + ":MPPImageClassifierOptions.h", + ":MPPImageClassifierResult.h", + ":MPPObjectDetector.h", + ":MPPObjectDetectorOptions.h", + ":MPPObjectDetectionResult.h", + ], + bundle_name = "MediaPipeTaskVision", + ios = { + "simulator" : ["arm64", "x86_64"], + "device" : ["arm64"], + }, + minimum_os_versions = { + "ios": MPP_TASK_MINIMUM_OS_VERSION, + }, + deps = [ + "//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier", + "//mediapipe/tasks/ios/vision/object_detector:MPPObjectDetector", + ], + # Avoids dependencies of ":MediaPipeCommonObjects_framework" and + # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error + # when the frameworks are imported in iOS projects. + # Also avoids opencv since it will be built with + # ":MediaPipeTaskGraphs_library". + avoid_deps = OBJC_COMMON_DEPS + [ + "@ios_opencv//:OpencvFramework" ], ) apple_static_library( - name = "MediaPipeTaskText_GraphLibrary", + name = "MediaPipeTaskGraphs_library", + minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION, platform_type = "ios", minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION, deps = [ + "//mediapipe/tasks/cc/vision/image_classifier:image_classifier_graph", + "//mediapipe/tasks/cc/vision/object_detector:object_detector_graph", "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", "@org_tensorflow//third_party/icu/data:conversion_data", + "@ios_opencv//:OpencvFramework" + ], + # There is no way to turn off zlib dependency in custom opencv builds. + # Hence zlib is avoided to prevent duplicate symbols because of conflicts + # between opencv's zlib and "@zlib//:zlib" + avoid_deps = [ + "@zlib//:zlib", + ], +) + +apple_static_xcframework( + name = "MediaPipeTaskCommonObjects_framework", + bundle_name = "MediaPipeTaskCommon", + ios = { + "simulator" : ["arm64", "x86_64"], + "device" : ["arm64"], + }, + minimum_os_versions = { + "ios": MPP_TASK_MINIMUM_OS_VERSION, + }, + # avoids gpu targets since they will be built with + # ":MediaPipeTaskGraphs_library". Otherwise it will result in + # duplicate symbols error when the frameworks are imported in iOS. + avoid_deps = [ + "//mediapipe/gpu:metal_shared_resources", + ], + deps = [ + "//mediapipe/tasks/ios/core:MPPBaseOptions", + "//mediapipe/tasks/ios/core:MPPTaskInfo", + "//mediapipe/tasks/ios/core:MPPTaskOptions", + "//mediapipe/tasks/ios/core:MPPTaskResult", + "//mediapipe/tasks/ios/core:MPPTaskRunner", + "//mediapipe/tasks/ios/components/containers:MPPClassificationResult", + "//mediapipe/tasks/ios/components/containers:MPPCategory", + "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", ], ) diff --git a/mediapipe/tasks/ios/text/text_classifier/BUILD b/mediapipe/tasks/ios/text/text_classifier/BUILD index 97cf27677..7913340ac 100644 --- a/mediapipe/tasks/ios/text/text_classifier/BUILD +++ b/mediapipe/tasks/ios/text/text_classifier/BUILD @@ -49,6 +49,7 @@ objc_library( ":MPPTextClassifierOptions", ":MPPTextClassifierResult", "//mediapipe/tasks/cc/components/containers/proto:classifications_cc_proto", + "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/common/utils:NSStringHelpers", "//mediapipe/tasks/ios/core:MPPTaskInfo", @@ -57,10 +58,5 @@ objc_library( "//mediapipe/tasks/ios/text/core:MPPTextTaskRunner", "//mediapipe/tasks/ios/text/text_classifier/utils:MPPTextClassifierOptionsHelpers", "//mediapipe/tasks/ios/text/text_classifier/utils:MPPTextClassifierResultHelpers", - ] + select({ - "//mediapipe/tasks/ios:avoid_linking_graphs": [], - "//conditions:default": [ - "//mediapipe/tasks/cc/text/text_classifier:text_classifier_graph", - ], - }), + ], ) diff --git a/mediapipe/tasks/ios/text/text_embedder/BUILD b/mediapipe/tasks/ios/text/text_embedder/BUILD index a2edd8a2a..a600d5366 100644 --- a/mediapipe/tasks/ios/text/text_embedder/BUILD +++ b/mediapipe/tasks/ios/text/text_embedder/BUILD @@ -48,6 +48,7 @@ objc_library( deps = [ ":MPPTextEmbedderOptions", ":MPPTextEmbedderResult", + "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", "//mediapipe/tasks/ios/common/utils:MPPCommonUtils", "//mediapipe/tasks/ios/common/utils:NSStringHelpers", "//mediapipe/tasks/ios/components/utils:MPPCosineSimilarity", @@ -57,10 +58,5 @@ objc_library( "//mediapipe/tasks/ios/text/core:MPPTextTaskRunner", "//mediapipe/tasks/ios/text/text_embedder/utils:MPPTextEmbedderOptionsHelpers", "//mediapipe/tasks/ios/text/text_embedder/utils:MPPTextEmbedderResultHelpers", - ] + select({ - "//mediapipe/tasks/ios:avoid_linking_graphs": [], - "//conditions:default": [ - "//mediapipe/tasks/cc/text/text_embedder:text_embedder_graph", - ], - }), + ], ) From 472947818e25450823160aa3db1e09be6afce0fb Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 04:22:03 +0530 Subject: [PATCH 10/20] Updated ios cocoapods build script --- mediapipe/tasks/ios/build_ios_framework.sh | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 48bc0419c..6d59a9ac9 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -32,7 +32,9 @@ fi BAZEL="${BAZEL:-$(which bazel)}" MPP_BUILD_VERSION=${MPP_BUILD_VERSION:-0.0.1-dev} MPP_ROOT_DIR=$(git rev-parse --show-toplevel) -MPP_DISABLE_GPU=1 +ARCHIVE_FRAMEWORK=true +IS_RELEASE_BUILD=false +DEST_DIR=$HOME if [[ ! -x "${BAZEL}" ]]; then echo "bazel executable is not found." @@ -88,12 +90,8 @@ function build_target { echo ${OUTPUT_PATH} } -# This function builds 3 targets: -# 1. The ios task library xcframework -# 2. Fat static library including graphs needed for tasks in xcframework, for all -# simulator archs (x86_64, arm64). -# 3. Static library including graphs needed for the xcframework for all iOS device -# archs (arm64). +# This function builds 3 the xcframework and associated graph libraries if any +# for a given framework name. function build_ios_frameworks_and_libraries { local TARGET_PREFIX="//mediapipe/tasks/ios" FULL_FRAMEWORK_TARGET="${TARGET_PREFIX}:${FRAMEWORK_NAME}_framework" @@ -104,21 +102,26 @@ function build_ios_frameworks_and_libraries { # CocoaPods must set --apple_generate_dsym=false inorder to shave down the binary size to # the order of a few MBs. - # Build Text Task Library xcframework without the graph dependencies. - local FRAMEWORK_CQUERY_COMMAND="-c opt --define MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} \ - --define MEDIAPIPE_AVOID_LINKING_GRAPHS=1 --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" + # Build Task Library xcframework. + local FRAMEWORK_CQUERY_COMMAND="-c opt --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" - # Build fat static library for text task graphs for simulator archs. - local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --define \ - MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" - IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" + # `MediaPipeTaskCommonObjects`` pods must also include the task graph libraries which + # are to be force loaded. Hence the graph libraies are only built if the framework + # name is `MediaPipeTaskCommonObjects`.` + case $FRAMEWORK_NAME in + "MediaPipeTaskCommonObjects") + local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library" + IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" - # Build static library for iOS devices with arch ios_arm64. We don't need to build for armv7 since - # our deployment target is iOS 11.0. iOS 11.0 d anupwards is not supported by old armv7 devices. - local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --define \ - MEDIAPIPE_DISABLE_GPU=${MPP_DISABLE_GPU} --apple_generate_dsym=false ${FULL_GRAPH_LIBRARY_TARGET}" - IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" + # Build static library for iOS devices with arch ios_arm64. We don't need to build for armv7 since + # our deployment target is iOS 11.0. iOS 11.0 and upwards is not supported by old armv7 devices. + local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library" + IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" + ;; + *) + ;; + esac } function create_framework_archive { @@ -137,6 +140,13 @@ function create_framework_archive { echo ${IOS_FRAMEWORK_PATH} unzip "${IOS_FRAMEWORK_PATH}" -d "${FRAMEWORKS_DIR}" + + # If the framwork being built is `MediaPipeTaskCommonObjects`, the built graph + # libraries should be copied to the output directory which is to be archived. + case $FRAMEWORK_NAME in + "MediaPipeTaskCommonObjects") + + local GRAPH_LIBRARIES_DIR="graph_libraries" local GRAPH_LIBRARIES_DIR="graph_libraries" From 8b44a7f181fef78a1f068741308a423b1f90e1dc Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 04:22:18 +0530 Subject: [PATCH 11/20] Updated text podspec --- mediapipe/tasks/ios/MediaPipeTaskText.podspec.template | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template index 88ec4d989..e84779ae8 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template @@ -12,12 +12,7 @@ Pod::Spec.new do |s| s.module_name = 'MediaPipeTaskText' s.static_framework = true - s.user_target_xcconfig = { - 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskText/frameworks/graph_libraries/libMediaPipeTaskText_simulator_graph.a"', - 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskText/frameworks/graph_libraries/libMediaPipeTaskText_device_graph.a"', - 'STRIP_INSTALLED_PRODUCT' => 'NO' - } + s.dependency 'MediaPipeTaskCommonObjects' s.library = 'c++' - s.preserve_paths = 'frameworks/graph_libraries/*.a' s.vendored_frameworks = 'frameworks/MediaPipeTaskText.xcframework' end From d63d3f61d76e71eac8422ee86421443add61e1f3 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 04:22:40 +0530 Subject: [PATCH 12/20] Added podspec for CommonObjects and Vision tasks --- ...ediaPipeTaskCommonObjects.podspec.template | 23 +++++++++++++++++++ .../ios/MediaPipeTaskVision.podspec.template | 18 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template create mode 100644 mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template diff --git a/mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template new file mode 100644 index 000000000..a58d0b262 --- /dev/null +++ b/mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template @@ -0,0 +1,23 @@ +Pod::Spec.new do |s| + s.name = 'MediaPipeTaskCommonObjects' + s.version = '${MPP_BUILD_VERSION}' + s.authors = 'Google Inc.' + s.license = { :type => 'Apache',:file => "LICENSE" } + s.homepage = 'https://github.com/google/mediapipe' + s.source = { :http => '${MPP_DOWNLOAD_URL}' } + s.summary = 'MediaPipe Task Library - Text' + s.description = 'The Natural Language APIs of the MediaPipe Task Library' + + s.ios.deployment_target = '11.0' + + s.module_name = 'MediaPipeTaskCommonObjects' + s.static_framework = true + s.user_target_xcconfig = { + 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "${PODS_ROOT}/MediaPipeTaskCommonObjects/frameworks/graph_libraries/libMediaPipeTaskCommonObjects_simulator_graph.a"', + 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskCommonObjects/frameworks/graph_libraries/libMediaPipeTaskCommonObjects_device_graph.a"', + } + s.frameworks = 'Accelerate', 'CoreMedia', 'AssetsLibrary', 'CoreFoundation', 'CoreGraphics', 'CoreImage', 'QuartzCore', 'AVFoundation', 'CoreVideo' + s.preserve_paths ='frameworks/graph_libraries/*.a' + s.library = 'c++' + s.vendored_frameworks = 'frameworks/MediaPipeTaskCommon.xcframework' +end diff --git a/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template new file mode 100644 index 000000000..0d530e4cf --- /dev/null +++ b/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template @@ -0,0 +1,18 @@ +Pod::Spec.new do |s| + s.name = 'MediaPipeTaskVision' + s.version = '${MPP_BUILD_VERSION}' + s.authors = 'Google Inc.' + s.license = { :type => 'Apache',:file => "LICENSE" } + s.homepage = 'https://github.com/google/mediapipe' + s.source = { :http => '${MPP_DOWNLOAD_URL}' } + s.summary = 'MediaPipe Task Library - Vision' + s.description = 'The Vision APIs of the MediaPipe Task Library' + + s.ios.deployment_target = '11.0' + + s.module_name = 'MediaPipeTaskVision' + s.static_framework = true + s.dependency 'MediaPipeTaskCommonObjects' + s.library = 'c++' + s.vendored_frameworks = 'frameworks/MediaPipeTaskVision.xcframework' +end From 6ac39c9b93df23a5004ea13032f81a969591f2bf Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 04:26:13 +0530 Subject: [PATCH 13/20] Updated name of common objects pod --- mediapipe/tasks/ios/BUILD | 8 ++++---- ...template => MediaPipeTaskCommon.podspec.template} | 8 ++++---- mediapipe/tasks/ios/build_ios_framework.sh | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) rename mediapipe/tasks/ios/{MediaPipeTaskCommonObjects.podspec.template => MediaPipeTaskCommon.podspec.template} (73%) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index c94d1b48e..25b7ab9ce 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -33,7 +33,7 @@ licenses(["notice"]) # frameworks but are avoided from the framework binaries to avoid duplicate symbols # error when included in an xcode project: # 1. iOS classes shared amongst the various vision and text tasks. These classes -# will be built with ":MediaPipeTaskCommonObjects_framework" +# will be built with ":MediaPipeTaskCommon_framework" # 2. Task graphs. These will be built with ":MediaPipeTaskGraphs_library". # 3. gpu targets which will be built with the ":MediaPipeTaskGraphs_library". OBJC_COMMON_DEPS = [ @@ -102,7 +102,7 @@ apple_static_xcframework( "//mediapipe/tasks/ios/text/text_classifier:MPPTextClassifier", "//mediapipe/tasks/ios/text/text_embedder:MPPTextEmbedder", ], - # avoid dependencies of ":MediaPipeCommonObjects_framework" and + # avoid dependencies of ":MediaPipeCommon_framework" and # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error # when the frameworks are imported in iOS projects. avoid_deps = OBJC_COMMON_DEPS @@ -139,7 +139,7 @@ apple_static_xcframework( "//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier", "//mediapipe/tasks/ios/vision/object_detector:MPPObjectDetector", ], - # Avoids dependencies of ":MediaPipeCommonObjects_framework" and + # Avoids dependencies of ":MediaPipeCommon_framework" and # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error # when the frameworks are imported in iOS projects. # Also avoids opencv since it will be built with @@ -171,7 +171,7 @@ apple_static_library( ) apple_static_xcframework( - name = "MediaPipeTaskCommonObjects_framework", + name = "MediaPipeTaskCommon_framework", bundle_name = "MediaPipeTaskCommon", ios = { "simulator" : ["arm64", "x86_64"], diff --git a/mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template similarity index 73% rename from mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template rename to mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template index a58d0b262..52dc73b3a 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskCommonObjects.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template @@ -1,5 +1,5 @@ Pod::Spec.new do |s| - s.name = 'MediaPipeTaskCommonObjects' + s.name = 'MediaPipeTaskCommon' s.version = '${MPP_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } @@ -10,11 +10,11 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' - s.module_name = 'MediaPipeTaskCommonObjects' + s.module_name = 'MediaPipeTaskCommon' s.static_framework = true s.user_target_xcconfig = { - 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "${PODS_ROOT}/MediaPipeTaskCommonObjects/frameworks/graph_libraries/libMediaPipeTaskCommonObjects_simulator_graph.a"', - 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskCommonObjects/frameworks/graph_libraries/libMediaPipeTaskCommonObjects_device_graph.a"', + 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "${PODS_ROOT}/MediaPipeTaskCommon/frameworks/graph_libraries/libMediaPipeTaskCommon_simulator_graph.a"', + 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskCommon/frameworks/graph_libraries/libMediaPipeTaskCommon_device_graph.a"', } s.frameworks = 'Accelerate', 'CoreMedia', 'AssetsLibrary', 'CoreFoundation', 'CoreGraphics', 'CoreImage', 'QuartzCore', 'AVFoundation', 'CoreVideo' s.preserve_paths ='frameworks/graph_libraries/*.a' diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 6d59a9ac9..7ebbedca0 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -16,7 +16,7 @@ # Set the following variables as appropriate. # * BAZEL: path to bazel. defaults to the first one available in PATH # * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the -# * accepted values are MediaPipeTaskText. +# * accepted values are MediaPipeTaskCommon, MediaPipeTaskText, MediaPipeTaskVision. # * MPP_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev # * IS_RELEASE_BUILD: set as true if this build should be a release build # * ARCHIVE_FRAMEWORK: set as true if the framework should be archived @@ -106,11 +106,11 @@ function build_ios_frameworks_and_libraries { local FRAMEWORK_CQUERY_COMMAND="-c opt --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" - # `MediaPipeTaskCommonObjects`` pods must also include the task graph libraries which + # `MediaPipeTaskCommon`` pods must also include the task graph libraries which # are to be force loaded. Hence the graph libraies are only built if the framework - # name is `MediaPipeTaskCommonObjects`.` + # name is `MediaPipeTaskCommon`.` case $FRAMEWORK_NAME in - "MediaPipeTaskCommonObjects") + "MediaPipeTaskCommon") local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library" IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" @@ -141,10 +141,10 @@ function create_framework_archive { echo ${IOS_FRAMEWORK_PATH} unzip "${IOS_FRAMEWORK_PATH}" -d "${FRAMEWORKS_DIR}" - # If the framwork being built is `MediaPipeTaskCommonObjects`, the built graph + # If the framwork being built is `MediaPipeTaskCommon`, the built graph # libraries should be copied to the output directory which is to be archived. case $FRAMEWORK_NAME in - "MediaPipeTaskCommonObjects") + "MediaPipeTaskCommon") local GRAPH_LIBRARIES_DIR="graph_libraries" From 33903252505c6863d3e97f957ea11a4e79440dbd Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Tue, 25 Apr 2023 11:23:38 +0530 Subject: [PATCH 14/20] Updated documentation --- mediapipe/tasks/ios/ios.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediapipe/tasks/ios/ios.bzl b/mediapipe/tasks/ios/ios.bzl index fdfc85d5f..e4cdeb503 100644 --- a/mediapipe/tasks/ios/ios.bzl +++ b/mediapipe/tasks/ios/ios.bzl @@ -6,7 +6,7 @@ MPP_TASK_MINIMUM_OS_VERSION = "11.0" # to the "Headers" directory with no header path prefixes. This auxiliary rule # is used for stripping the path prefix to the C/iOS API header files included by # other C/iOS API header files. -# In case of C header files includes start with a keyword of "#include'. +# In case of C header files, includes start with a keyword of "#include'. # Imports in iOS header files start with a keyword of '#import'. def strip_api_include_path_prefix(name, hdr_labels, prefix = ""): """Create modified header files with the import path stripped out. From 9c98435027bd88c041f88f6aba1e61d7b31ef4d5 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:15:16 +0530 Subject: [PATCH 15/20] Updated iOS framework names --- mediapipe/tasks/ios/BUILD | 22 +++++++++---------- .../ios/MediaPipeTaskCommon.podspec.template | 10 ++++----- .../ios/MediaPipeTaskText.podspec.template | 8 +++---- .../ios/MediaPipeTaskVision.podspec.template | 8 +++---- mediapipe/tasks/ios/build_ios_framework.sh | 20 ++++++++++------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index 25b7ab9ce..a1292373c 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -27,13 +27,13 @@ package(default_visibility = ["//visibility:public"]) licenses(["notice"]) -# list of targets to be added in avoid_deps of ":MediaPipeTaskVision_framework" -# and ":MediaPipeTaskText_framework". +# list of targets to be added in avoid_deps of ":MediaPipeTasksVision_framework" +# and ":MediaPipeTasksText_framework". # The transitive closure of the following targets are used for building the # frameworks but are avoided from the framework binaries to avoid duplicate symbols # error when included in an xcode project: # 1. iOS classes shared amongst the various vision and text tasks. These classes -# will be built with ":MediaPipeTaskCommon_framework" +# will be built with ":MediaPipeTasksCommon_framework" # 2. Task graphs. These will be built with ":MediaPipeTaskGraphs_library". # 3. gpu targets which will be built with the ":MediaPipeTaskGraphs_library". OBJC_COMMON_DEPS = [ @@ -73,7 +73,7 @@ strip_api_include_path_prefix( ) apple_static_xcframework( - name = "MediaPipeTaskText_framework", + name = "MediaPipeTasksText_framework", public_hdrs = [ ":MPPBaseOptions.h", ":MPPCategory.h", @@ -90,7 +90,7 @@ apple_static_xcframework( ":MPPTextEmbedderOptions.h", ":MPPTextEmbedderResult.h", ], - bundle_name = "MediaPipeTaskText", + bundle_name = "MediaPipeTasksText", ios = { "simulator" : ["arm64", "x86_64"], "device" : ["arm64"], @@ -102,14 +102,14 @@ apple_static_xcframework( "//mediapipe/tasks/ios/text/text_classifier:MPPTextClassifier", "//mediapipe/tasks/ios/text/text_embedder:MPPTextEmbedder", ], - # avoid dependencies of ":MediaPipeCommon_framework" and + # avoid dependencies of ":MediaPipeTasksCommon_framework" and # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error # when the frameworks are imported in iOS projects. avoid_deps = OBJC_COMMON_DEPS ) apple_static_xcframework( - name = "MediaPipeTaskVision_framework", + name = "MediaPipeTasksVision_framework", public_hdrs = [ ":MPPBaseOptions.h", ":MPPCategory.h", @@ -127,7 +127,7 @@ apple_static_xcframework( ":MPPObjectDetectorOptions.h", ":MPPObjectDetectionResult.h", ], - bundle_name = "MediaPipeTaskVision", + bundle_name = "MediaPipeTasksVision", ios = { "simulator" : ["arm64", "x86_64"], "device" : ["arm64"], @@ -139,7 +139,7 @@ apple_static_xcframework( "//mediapipe/tasks/ios/vision/image_classifier:MPPImageClassifier", "//mediapipe/tasks/ios/vision/object_detector:MPPObjectDetector", ], - # Avoids dependencies of ":MediaPipeCommon_framework" and + # Avoids dependencies of ":MediaPipeTasksCommon_framework" and # ":MediaPipeTaskGraphs_library in order to prevent duplicate symbols error # when the frameworks are imported in iOS projects. # Also avoids opencv since it will be built with @@ -171,8 +171,8 @@ apple_static_library( ) apple_static_xcframework( - name = "MediaPipeTaskCommon_framework", - bundle_name = "MediaPipeTaskCommon", + name = "MediaPipeTasksCommon_framework", + bundle_name = "MediaPipeTasksCommon", ios = { "simulator" : ["arm64", "x86_64"], "device" : ["arm64"], diff --git a/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template index 52dc73b3a..de9a3fa26 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskCommon.podspec.template @@ -1,5 +1,5 @@ Pod::Spec.new do |s| - s.name = 'MediaPipeTaskCommon' + s.name = 'MediaPipeTasksCommon' s.version = '${MPP_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } @@ -10,14 +10,14 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' - s.module_name = 'MediaPipeTaskCommon' + s.module_name = 'MediaPipeTasksCommon' s.static_framework = true s.user_target_xcconfig = { - 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "${PODS_ROOT}/MediaPipeTaskCommon/frameworks/graph_libraries/libMediaPipeTaskCommon_simulator_graph.a"', - 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTaskCommon/frameworks/graph_libraries/libMediaPipeTaskCommon_device_graph.a"', + 'OTHER_LDFLAGS[sdk=iphonesimulator*]' => '$(inherited) -force_load "${PODS_ROOT}/MediaPipeTasksCommon/frameworks/graph_libraries/libMediaPipeTasksCommon_simulator_graph.a"', + 'OTHER_LDFLAGS[sdk=iphoneos*]' => '$(inherited) -force_load "$(PODS_ROOT)/MediaPipeTasksCommon/frameworks/graph_libraries/libMediaPipeTasksCommon_device_graph.a"', } s.frameworks = 'Accelerate', 'CoreMedia', 'AssetsLibrary', 'CoreFoundation', 'CoreGraphics', 'CoreImage', 'QuartzCore', 'AVFoundation', 'CoreVideo' s.preserve_paths ='frameworks/graph_libraries/*.a' s.library = 'c++' - s.vendored_frameworks = 'frameworks/MediaPipeTaskCommon.xcframework' + s.vendored_frameworks = 'frameworks/MediaPipeTasksCommon.xcframework' end diff --git a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template index e84779ae8..144d36f88 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskText.podspec.template @@ -1,5 +1,5 @@ Pod::Spec.new do |s| - s.name = 'MediaPipeTaskText' + s.name = 'MediaPipeTasksText' s.version = '${MPP_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } @@ -10,9 +10,9 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' - s.module_name = 'MediaPipeTaskText' + s.module_name = 'MediaPipeTasksText' s.static_framework = true - s.dependency 'MediaPipeTaskCommonObjects' + s.dependency 'MediaPipeTasksCommon' s.library = 'c++' - s.vendored_frameworks = 'frameworks/MediaPipeTaskText.xcframework' + s.vendored_frameworks = 'frameworks/MediaPipeTasksText.xcframework' end diff --git a/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template b/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template index 0d530e4cf..373c1768b 100644 --- a/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template +++ b/mediapipe/tasks/ios/MediaPipeTaskVision.podspec.template @@ -1,5 +1,5 @@ Pod::Spec.new do |s| - s.name = 'MediaPipeTaskVision' + s.name = 'MediaPipeTasksVision' s.version = '${MPP_BUILD_VERSION}' s.authors = 'Google Inc.' s.license = { :type => 'Apache',:file => "LICENSE" } @@ -10,9 +10,9 @@ Pod::Spec.new do |s| s.ios.deployment_target = '11.0' - s.module_name = 'MediaPipeTaskVision' + s.module_name = 'MediaPipeTasksVision' s.static_framework = true - s.dependency 'MediaPipeTaskCommonObjects' + s.dependency 'MediaPipeTasksCommon' s.library = 'c++' - s.vendored_frameworks = 'frameworks/MediaPipeTaskVision.xcframework' + s.vendored_frameworks = 'frameworks/MediaPipeTasksVision.xcframework' end diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 7ebbedca0..744c49852 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -16,7 +16,7 @@ # Set the following variables as appropriate. # * BAZEL: path to bazel. defaults to the first one available in PATH # * FRAMEWORK_NAME: name of the iOS framework to be built. Currently the -# * accepted values are MediaPipeTaskCommon, MediaPipeTaskText, MediaPipeTaskVision. +# * accepted values are MediaPipeTasksCommon, MediaPipeTasksText, MediaPipeTasksVision. # * MPP_BUILD_VERSION: to specify the release version. defaults to 0.0.1-dev # * IS_RELEASE_BUILD: set as true if this build should be a release build # * ARCHIVE_FRAMEWORK: set as true if the framework should be archived @@ -47,10 +47,14 @@ if [ -z ${FRAMEWORK_NAME+x} ]; then fi case $FRAMEWORK_NAME in - "MediaPipeTaskText") + "MediaPipeTasksText") + ;; + "MediaPipeTasksVision") + ;; + "MediaPipeTasksCommon") ;; *) - echo "Wrong framework name. The following framework names are allowed: MediaPipeTaskText" + echo "Wrong framework name. The following framework names are allowed: MediaPipeTasksText, MediaPipeTasksVision, MediaPipeTasksCommon" exit 1 ;; esac @@ -106,11 +110,11 @@ function build_ios_frameworks_and_libraries { local FRAMEWORK_CQUERY_COMMAND="-c opt --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" - # `MediaPipeTaskCommon`` pods must also include the task graph libraries which + # `MediaPipeTasksCommon`` pods must also include the task graph libraries which # are to be force loaded. Hence the graph libraies are only built if the framework - # name is `MediaPipeTaskCommon`.` + # name is `MediaPipeTasksCommon`.` case $FRAMEWORK_NAME in - "MediaPipeTaskCommon") + "MediaPipeTasksCommon") local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library" IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(build_target "${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}")" @@ -141,10 +145,10 @@ function create_framework_archive { echo ${IOS_FRAMEWORK_PATH} unzip "${IOS_FRAMEWORK_PATH}" -d "${FRAMEWORKS_DIR}" - # If the framwork being built is `MediaPipeTaskCommon`, the built graph + # If the framwork being built is `MediaPipeTasksCommon`, the built graph # libraries should be copied to the output directory which is to be archived. case $FRAMEWORK_NAME in - "MediaPipeTaskCommon") + "MediaPipeTasksCommon") local GRAPH_LIBRARIES_DIR="graph_libraries" From 1e776e8e015db0de99a071ff301cd5e8c1b90230 Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:31:30 +0530 Subject: [PATCH 16/20] Fixed indendation issues --- mediapipe/tasks/ios/BUILD | 1 - mediapipe/tasks/ios/build_ios_framework.sh | 35 +++++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index a1292373c..e40b5339b 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -153,7 +153,6 @@ apple_static_library( name = "MediaPipeTaskGraphs_library", minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION, platform_type = "ios", - minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION, deps = [ "//mediapipe/tasks/cc/vision/image_classifier:image_classifier_graph", "//mediapipe/tasks/cc/vision/object_detector:object_detector_graph", diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 744c49852..6351a4d4d 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -47,7 +47,7 @@ if [ -z ${FRAMEWORK_NAME+x} ]; then fi case $FRAMEWORK_NAME in - "MediaPipeTasksText") + "MediaPipeTasksCommon") ;; "MediaPipeTasksVision") ;; @@ -123,8 +123,8 @@ function build_ios_frameworks_and_libraries { local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library" IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(build_target "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")" ;; - *) - ;; + *) + ;; esac } @@ -149,26 +149,25 @@ function create_framework_archive { # libraries should be copied to the output directory which is to be archived. case $FRAMEWORK_NAME in "MediaPipeTasksCommon") - local GRAPH_LIBRARIES_DIR="graph_libraries" - - local GRAPH_LIBRARIES_DIR="graph_libraries" - - # Create the parent folder which will hold the graph libraries of all architectures. - mkdir -p "${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}" + # Create the parent folder which will hold the graph libraries of all architectures. + mkdir -p "${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}" - local SIMULATOR_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_simulator_graph.a" + local SIMULATOR_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_simulator_graph.a" - # Copy ios simulator fat library into a separate directory. - echo ${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH} - cp "${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH}" "${SIMULATOR_GRAPH_LIBRARY_PATH}" - + # Copy ios simulator fat library into a separate directory. + echo ${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH} + cp "${IOS_GRAPHS_SIMULATOR_LIBRARY_PATH}" "${SIMULATOR_GRAPH_LIBRARY_PATH}" - local IOS_DEVICE_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_device_graph.a" + local IOS_DEVICE_GRAPH_LIBRARY_PATH="${FRAMEWORKS_DIR}/${GRAPH_LIBRARIES_DIR}/lib${FRAMEWORK_NAME}_device_graph.a" - # Copy ios device library into a separate directory. - echo ${IOS_GRAPHS_DEVICE_LIBRARY_PATH} - cp "${IOS_GRAPHS_DEVICE_LIBRARY_PATH}" "${IOS_DEVICE_GRAPH_LIBRARY_PATH}" + # Copy ios device library into a separate directory. + echo ${IOS_GRAPHS_DEVICE_LIBRARY_PATH} + cp "${IOS_GRAPHS_DEVICE_LIBRARY_PATH}" "${IOS_DEVICE_GRAPH_LIBRARY_PATH}" + ;; + *) + ;; + esac #----- (3) Move the framework to the destination ----- if [[ "${ARCHIVE_FRAMEWORK}" == true ]]; then From a8cb1f1dad62144481e25759bcc63fabb7365b4a Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:47:19 +0530 Subject: [PATCH 17/20] Updated default values --- mediapipe/tasks/ios/build_ios_framework.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 6351a4d4d..f75e0db7a 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -32,9 +32,12 @@ fi BAZEL="${BAZEL:-$(which bazel)}" MPP_BUILD_VERSION=${MPP_BUILD_VERSION:-0.0.1-dev} MPP_ROOT_DIR=$(git rev-parse --show-toplevel) -ARCHIVE_FRAMEWORK=true -IS_RELEASE_BUILD=false -DEST_DIR=$HOME +ARCHIVE_FRAMEWORK=${ARCHIVE_FRAMEWORK:-true} +IS_RELEASE_BUILD=${IS_RELEASE_BUILD:-false} +DEST_DIR=${DEST_DIR:-$HOME} + +echo "Destination" +echo "${DEST_DIR}" if [[ ! -x "${BAZEL}" ]]; then echo "bazel executable is not found." From 1d8e24b9aa79864016b2004c4d81134637029c9e Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:47:52 +0530 Subject: [PATCH 18/20] Updated documentation --- mediapipe/tasks/ios/build_ios_framework.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index f75e0db7a..3df9f1eac 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -113,7 +113,7 @@ function build_ios_frameworks_and_libraries { local FRAMEWORK_CQUERY_COMMAND="-c opt --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}" IOS_FRAMEWORK_PATH="$(build_target "${FRAMEWORK_CQUERY_COMMAND}")" - # `MediaPipeTasksCommon`` pods must also include the task graph libraries which + # `MediaPipeTasksCommon` pods must also include the task graph libraries which # are to be force loaded. Hence the graph libraies are only built if the framework # name is `MediaPipeTasksCommon`.` case $FRAMEWORK_NAME in From ee2665ad13512c118b4475a4d42263116a1c36db Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:54:50 +0530 Subject: [PATCH 19/20] Added missing input files in vision library --- mediapipe/tasks/ios/BUILD | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mediapipe/tasks/ios/BUILD b/mediapipe/tasks/ios/BUILD index e40b5339b..f06344c88 100644 --- a/mediapipe/tasks/ios/BUILD +++ b/mediapipe/tasks/ios/BUILD @@ -60,6 +60,7 @@ strip_api_include_path_prefix( "//mediapipe/tasks/ios/components/containers:sources/MPPClassificationResult.h", "//mediapipe/tasks/ios/components/containers:sources/MPPEmbedding.h", "//mediapipe/tasks/ios/components/containers:sources/MPPEmbeddingResult.h", + "//mediapipe/tasks/ios/components/containers:sources/MPPDetection.h", "//mediapipe/tasks/ios/core:sources/MPPBaseOptions.h", "//mediapipe/tasks/ios/core:sources/MPPTaskOptions.h", "//mediapipe/tasks/ios/core:sources/MPPTaskResult.h", @@ -69,6 +70,14 @@ strip_api_include_path_prefix( "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedder.h", "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedderOptions.h", "//mediapipe/tasks/ios/text/text_embedder:sources/MPPTextEmbedderResult.h", + "//mediapipe/tasks/ios/vision/core:sources/MPPRunningMode.h", + "//mediapipe/tasks/ios/vision/core:sources/MPPImage.h", + "//mediapipe/tasks/ios/vision/image_classifier:sources/MPPImageClassifier.h", + "//mediapipe/tasks/ios/vision/image_classifier:sources/MPPImageClassifierOptions.h", + "//mediapipe/tasks/ios/vision/image_classifier:sources/MPPImageClassifierResult.h", + "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetector.h", + "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetectorOptions.h", + "//mediapipe/tasks/ios/vision/object_detector:sources/MPPObjectDetectionResult.h", ], ) From 261e02e491929e4ebc153336075aad1de60c28fb Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 27 Apr 2023 02:55:58 +0530 Subject: [PATCH 20/20] Fixed case name --- mediapipe/tasks/ios/build_ios_framework.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediapipe/tasks/ios/build_ios_framework.sh b/mediapipe/tasks/ios/build_ios_framework.sh index 3df9f1eac..8cc1747da 100755 --- a/mediapipe/tasks/ios/build_ios_framework.sh +++ b/mediapipe/tasks/ios/build_ios_framework.sh @@ -54,7 +54,7 @@ case $FRAMEWORK_NAME in ;; "MediaPipeTasksVision") ;; - "MediaPipeTasksCommon") + "MediaPipeTasksText") ;; *) echo "Wrong framework name. The following framework names are allowed: MediaPipeTasksText, MediaPipeTasksVision, MediaPipeTasksCommon"