Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# The bazelrc file for MediaPipe OSS.

# Python version set to 12
common --repo_env=HERMETIC_PYTHON_VERSION=3.12

# Tensorflow needs remote repo
common --experimental_repo_remote_exec

Expand Down Expand Up @@ -79,6 +82,7 @@ build:android_arm64 --platforms=@//third_party/android:arm64-v8a
# iOS configs.
build:ios --apple_platform_type=ios
build:ios --copt=-fno-aligned-allocation
build:ios --incompatible_enable_cc_toolchain_resolution

build:ios_i386 --config=ios
build:ios_i386 --cpu=ios_i386
Expand All @@ -87,7 +91,7 @@ build:ios_i386 --watchos_cpus=i386
build:ios_x86_64 --config=ios
build:ios_x86_64 --cpu=ios_x86_64
build:ios_x86_64 --watchos_cpus=i386
build:ios_x86_64 --platforms=@build_bazel_apple_support//configs/platforms:ios_x86_64
build:ios_x86_64 --platforms=@build_bazel_apple_support//platforms:ios_x86_64

build:ios_armv7 --config=ios
build:ios_armv7 --cpu=ios_armv7
Expand All @@ -97,12 +101,12 @@ build:ios_armv7 --platforms=@//third_party/ios:ios_armv7
build:ios_arm64 --config=ios
build:ios_arm64 --cpu=ios_arm64
build:ios_arm64 --watchos_cpus=armv7k
build:ios_arm64 --platforms=@build_bazel_apple_support//configs/platforms:ios_arm64
build:ios_arm64 --platforms=@build_bazel_apple_support//platforms:ios_arm64

build:ios_arm64e --config=ios
build:ios_arm64e --cpu=ios_arm64e
build:ios_arm64e --watchos_cpus=armv7k
build:ios_arm64e --platforms=@build_bazel_apple_support//configs/platforms:ios_arm64e
build:ios_arm64e --platforms=@build_bazel_apple_support//platforms:ios_arm64e

build:ios_fat --config=ios
build:ios_fat --ios_multi_cpus=armv7,arm64
Expand Down
19 changes: 19 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Build and development files
.bazelrc export-ignore
.bazelversion export-ignore
WORKSPACE export-ignore
BUILD export-ignore
*.bzl export-ignore
*.bazel export-ignore

# Build scripts and tools
spm/ export-ignore
mediapipe/ export-ignore
third_party/ export-ignore
build_ios_framework.sh export-ignore

# Development files
.github/ export-ignore
.git/ export-ignore
docs/ export-ignore
*.sh export-ignore
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ mediapipe/provisioning_profile.mobileprovision
node_modules/
.configure.bazelrc
.user.bazelrc
.build

# SPM build outputs
spm/output/
spm/.build

# Temporary build artifacts
*.xcarchive
*.framework
*.xcframework

# macOS
.DS_Store
78 changes: 78 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "MediaPipe",
platforms: [
.iOS(.v15)
],
products: [
// Main products - these are what users will import
.library(
name: "MediaPipeTasksCommon",
targets: ["MediaPipeTasksCommon", "MediaPipeTasksCommonWrapper"]),
.library(
name: "MediaPipeTasksVision",
targets: ["MediaPipeTasksVision"]),
.library(
name: "MediaPipeTasksText",
targets: ["MediaPipeTasksText"]),
.library(
name: "MediaPipeTasksAudio",
targets: ["MediaPipeTasksAudio"]),
],
targets: [
// MediaPipeTasksCommon - Base framework
// Contains core functionality shared across all task types
.binaryTarget(
name: "MediaPipeTasksCommon",
url: "https://github.com/mihaidimoiu/mediapipe/releases/download/v0.10.33/MediaPipeTasksCommon.xcframework.zip",
checksum: "1eef9602c00b903f11d5b4e302854ff9b245792867232db0347069b9defd293f"
),

// Wrapper target for MediaPipeTasksCommon to add system framework dependencies
.target(
name: "MediaPipeTasksCommonWrapper",
dependencies: ["MediaPipeTasksCommon"],
path: "Sources/MediaPipeTasksCommonWrapper",
linkerSettings: [
.linkedFramework("Accelerate"),
.linkedFramework("CoreMedia"),
.linkedFramework("AssetsLibrary"),
.linkedFramework("CoreFoundation"),
.linkedFramework("CoreGraphics"),
.linkedFramework("CoreImage"),
.linkedFramework("QuartzCore"),
.linkedFramework("AVFoundation"),
.linkedFramework("CoreVideo"),
.linkedLibrary("c++")
]
),

// MediaPipeTasksVision - Vision task APIs
// Includes: object detection, image classification, face detection, etc.
.binaryTarget(
name: "MediaPipeTasksVision",
url: "https://github.com/mihaidimoiu/mediapipe/releases/download/v0.10.33/MediaPipeTasksVision.xcframework.zip",
checksum: "f3e50572a668db4e8e9dabd9785061aa67257412d3af94d08ddb8593c49b765e"
),

// MediaPipeTasksText - Text task APIs
// Includes: text classification, text embedding, etc.
.binaryTarget(
name: "MediaPipeTasksText",
url: "https://github.com/mihaidimoiu/mediapipe/releases/download/v0.10.33/MediaPipeTasksText.xcframework.zip",
checksum: "4c71d65eacffaccf10dc8ef55891c80269c7c7b3ca30d12bd8eb13e46093db84"
),

// MediaPipeTasksAudio - Audio task APIs
// Includes: audio classification, etc.
.binaryTarget(
name: "MediaPipeTasksAudio",
url: "https://github.com/mihaidimoiu/mediapipe/releases/download/v0.10.33/MediaPipeTasksAudio.xcframework.zip",
checksum: "eccd58048487989ab1c1207d94c778058f77278144fa8515d453dbc8771dd5c6"
),
]
)
3 changes: 3 additions & 0 deletions Sources/MediaPipeTasksCommonWrapper/dummy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is required for SPM to recognize this as a valid target.
// The actual functionality is provided by the MediaPipeTasksCommon binary target.
// This wrapper exists solely to attach linker settings for system frameworks.
72 changes: 47 additions & 25 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ load("@bazel_skylib//lib:versions.bzl", "versions")

versions.check(minimum_bazel_version = "3.7.2")

http_archive(
name = "bazel_features",
sha256 = "07271d0f6b12633777b69020c4cb1eb67b1939c0cf84bb3944dc85cc250c0c01",
strip_prefix = "bazel_features-1.38.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.38.0/bazel_features-v1.38.0.tar.gz",
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

# ABSL on 2023-10-18
http_archive(
name = "com_google_absl",
Expand All @@ -41,13 +52,15 @@ http_archive(

http_archive(
name = "rules_cc",
patch_args = ["-p1"],
patches = ["@//third_party:rules_cc.diff"],
sha256 = "0d3b4f984c4c2e1acfd1378e0148d35caf2ef1d9eb95b688f8e19ce0c41bdf5b",
strip_prefix = "rules_cc-0.1.4",
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.1.4/rules_cc-0.1.4.tar.gz",
sha256 = "a2fdfde2ab9b2176bd6a33afca14458039023edb1dd2e73e6823810809df4027",
strip_prefix = "rules_cc-0.2.14",
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.14/rules_cc-0.2.14.tar.gz",
)

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

compatibility_proxy_repo()

http_archive(
name = "rules_java",
sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934",
Expand Down Expand Up @@ -89,19 +102,32 @@ rules_shell_toolchains()

load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") # @unused

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_swift",
sha256 = "13219bde174594c7af5403c7f3f41c37d1a62041294a0fd14c0834ca472fa8dc",
url = "https://github.com/bazelbuild/rules_swift/releases/download/3.4.0/rules_swift.3.4.0.tar.gz",
)

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)

swift_rules_dependencies()

load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

http_archive(
name = "build_bazel_rules_apple",
patch_args = [
"-p1",
],
patches = [
# Bypass checking ios unit test runner when building MP ios applications.
"@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff",
# https://github.com/bazelbuild/rules_apple/commit/95b1305255dc29874cacc3dc7fdc017f16d8dbe8
"@//third_party:build_bazel_rules_apple_multi_arch_split_with_new_transition.diff",
],
sha256 = "3e2c7ae0ddd181c4053b6491dad1d01ae29011bc322ca87eea45957c76d3a0c3",
url = "https://github.com/bazelbuild/rules_apple/releases/download/2.1.0/rules_apple.2.1.0.tar.gz",
sha256 = "f2b4117fe17b0f1f8a3769e6d760d433fcbf97a8b6ff1797077ec106ccfbe2f2",
url = "https://github.com/bazelbuild/rules_apple/releases/download/4.3.2/rules_apple.4.3.2.tar.gz",
)

# GoogleTest/GoogleMock framework. Used by most unit-tests.
Expand All @@ -124,9 +150,9 @@ http_archive(
patches = [
"@//third_party:zlib.diff",
],
sha256 = "b3a24de97a8fdbc835b9833169501030b8977031bcb54b3b3ac13740f846ab30",
strip_prefix = "zlib-1.2.13",
url = "http://zlib.net/fossils/zlib-1.2.13.tar.gz",
sha256 = "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23",
strip_prefix = "zlib-1.3.1",
url = "https://zlib.net/fossils/zlib-1.3.1.tar.gz",
)

# gflags needed by glog
Expand Down Expand Up @@ -434,10 +460,6 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende

rules_foreign_cc_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
Expand Down Expand Up @@ -628,10 +650,10 @@ new_local_repository(
new_local_repository(
name = "macos_opencv",
build_file = "@//third_party:opencv_macos.BUILD",
# For local MacOS builds, the path should point to an opencv@3 installation.
# For local MacOS builds, the path should point to an OpenCV installation.
# If you edit the path here, you will also need to update the corresponding
# prefix in "opencv_macos.BUILD".
path = "/usr/local", # e.g. /usr/local/Cellar for HomeBrew
path = "/opt/homebrew/Cellar", # e.g. /usr/local for v3
)

new_local_repository(
Expand Down
28 changes: 23 additions & 5 deletions mediapipe/tasks/ios/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@build_bazel_rules_apple//apple:apple_static_library.bzl", "apple_static_library")
load("@rules_cc//cc:objc_library.bzl", "objc_library")
load(
"//mediapipe/framework/tool:ios.bzl",
"MPP_TASK_MINIMUM_OS_VERSION",
"strip_api_include_path_prefix",
)
load(":ios_build_rules.bzl", "mediapipe_static_xcframework")
Expand Down Expand Up @@ -324,21 +326,37 @@ mediapipe_static_xcframework(
],
)

mediapipe_static_xcframework(
apple_static_library(
name = "MediaPipeTaskGraphs_library",
bundle_name = "MediaPipeTaskGraphs_library",
deps = [":MediaPipeTaskGraphs"],
avoid_deps = TENSORFLOW_LITE_C_DEPS + [
"@zlib//:zlib",
"//mediapipe/gpu:metal_shared_resources",
":OpenCV",
],
minimum_os_version = MPP_TASK_MINIMUM_OS_VERSION,
platform_type = "ios",
deps = CALCULATORS_AND_GRAPHS + [
"@org_tensorflow//third_party/icu/data:conversion_data",
":OpenCV",
],
)

mediapipe_static_xcframework(
name = "MediaPipeTasksCommon_framework",
avoid_deps = CALCULATORS_AND_GRAPHS,
avoid_deps = ["@zlib//:zlib"],
bundle_name = "MediaPipeTasksCommon",
# Including `OpenCV` and `TensorFlowLiteC` deps of the graphs here to avoid
# conflicts with `TensorFlowLiteSwift` and `OpenCV` frameworks as iOS
# `xcframeworks` handle duplicate dependencies with other iOS
# `xcframeworks`. Including them with task graphs causes duplicate symbols
# when installed alongside the respective frameworks since task graphs are
# built as static libraries and force loaded.
deps = MEDIAPIPE_TASKS_COMMON_DEPS,
#
# FOR SPM: Including CALCULATORS_AND_GRAPHS directly in MediaPipeTasksCommon
# to avoid undefined symbols. Vision/Audio/Text frameworks use avoid_deps
# to prevent duplicating these, so using multiple frameworks together is safe.
# NOTE: conversion_data is required for ICU symbols when using -all_load.
deps = MEDIAPIPE_TASKS_COMMON_DEPS + CALCULATORS_AND_GRAPHS + [
"@org_tensorflow//third_party/icu/data:conversion_data",
],
)
9 changes: 5 additions & 4 deletions mediapipe/tasks/ios/build_ios_framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function build_ios_frameworks_and_libraries {
# the order of a few MBs.

# Build Task Library xcframework.
local FRAMEWORK_CQUERY_COMMAND="-c opt --config=ios_sim_device_fat --apple_generate_dsym=false --define OPENCV=source ${FULL_FRAMEWORK_TARGET}"
local FRAMEWORK_CQUERY_COMMAND="-c opt --config=ios_sim_device_fat --apple_generate_dsym=false ${FULL_FRAMEWORK_TARGET}"

${BAZEL} build ${FRAMEWORK_CQUERY_COMMAND}
IOS_FRAMEWORK_PATH="$(get_output_file_path "${FRAMEWORK_CQUERY_COMMAND}")"
Expand All @@ -115,13 +115,13 @@ function build_ios_frameworks_and_libraries {
# are to be force loaded. Hence the graph libraies are only built if the framework
# name is `MediaPipeTasksCommon`.`
"MediaPipeTasksCommon")
local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --apple_generate_dsym=false --define OPENCV=source //mediapipe/tasks/ios:MediaPipeTaskGraphs_library"
local IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_sim_fat --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library"
${BAZEL} build ${IOS_SIM_FAT_LIBRARY_CQUERY_COMMAND}
IOS_GRAPHS_SIMULATOR_LIBRARY_PATH="$(get_output_file_path "${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 12.0. iOS 12.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 --define OPENCV=source //mediapipe/tasks/ios:MediaPipeTaskGraphs_library"
local IOS_DEVICE_LIBRARY_CQUERY_COMMAND="-c opt --config=ios_arm64 --apple_generate_dsym=false //mediapipe/tasks/ios:MediaPipeTaskGraphs_library"
${BAZEL} build ${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}
IOS_GRAPHS_DEVICE_LIBRARY_PATH="$(get_output_file_path "${IOS_DEVICE_LIBRARY_CQUERY_COMMAND}")"
;;
Expand Down Expand Up @@ -224,7 +224,8 @@ function create_framework_archive {
# 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}" .

tar -cvzf "${MPP_ARCHIVE_FILE}" --exclude="${MPP_ARCHIVE_FILE}" .
mv "${MPP_ARCHIVE_FILE}" "${FRAMEWORK_ARCHIVE_DIR}"
popd

Expand Down
Loading