-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Copyright 2023 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. | ||
|
||
# CHANGES: | ||
# - OpenCV 4.5.3 -> 4.5.5 | ||
|
||
# Description: | ||
# OpenCV xcframework for video/image processing on iOS. | ||
|
||
load( | ||
"@mediapipe//third_party:opencv_ios_source.bzl", | ||
"select_headers", | ||
"unzip_opencv_xcframework", | ||
) | ||
load( | ||
"@build_bazel_rules_apple//apple:apple.bzl", | ||
"apple_static_xcframework_import", | ||
) | ||
|
||
licenses(["notice"]) # BSD license | ||
|
||
exports_files(["LICENSE"]) | ||
|
||
# Build opencv2.xcframework from source using a convenience script provided in | ||
# OPENCV sources and zip the xcframework. We only build the modules required by MediaPipe by specifying | ||
# the modules to be ignored as command line arguments. | ||
# We also specify the simulator and device architectures we are building for. | ||
# Currently we only support iOS arm64 (M1 Macs) and x86_64(Intel Macs) simulators | ||
# and arm64 iOS devices. | ||
# Bitcode and Swift support. Swift support will be added in when the final binary | ||
# for MediaPipe iOS Task libraries are built. Shipping with OPENCV built with | ||
# Swift support throws linker errors when the MediaPipe framework is used from | ||
# an iOS project. | ||
# When building on M1 Macs, cmake version cannot be higher than 3.24.0. This is | ||
# is mentioned in an open issue in the opencv github repo. | ||
genrule( | ||
name = "build_opencv_xcframework", | ||
srcs = glob(["opencv-4.5.5/**"]), | ||
outs = ["opencv2.xcframework.zip"], | ||
cmd = "&&".join([ | ||
"$(location opencv-4.5.5/platforms/apple/build_xcframework.py) \ | ||
--iphonesimulator_archs arm64,x86_64 \ | ||
--iphoneos_archs arm64 \ | ||
--without dnn \ | ||
--without ml \ | ||
--without stitching \ | ||
--without photo \ | ||
--without objdetect \ | ||
--without gapi \ | ||
--without flann \ | ||
--without highgui \ | ||
--without videoio \ | ||
--disable PROTOBUF \ | ||
--disable-bitcode \ | ||
--disable-swift \ | ||
--build_only_specified_archs \ | ||
--out $(@D)", | ||
"cd $(@D)", | ||
"zip --symlinks -r opencv2.xcframework.zip opencv2.xcframework", | ||
]), | ||
) | ||
|
||
# Unzips `opencv2.xcframework.zip` built from source by `build_opencv_xcframework` | ||
# genrule and returns an exhaustive list of all its files including symlinks. | ||
unzip_opencv_xcframework( | ||
name = "opencv2_unzipped_xcframework_files", | ||
zip_file = "opencv2.xcframework.zip", | ||
) | ||
|
||
# Imports the files of the unzipped `opencv2.xcframework` as an apple static | ||
# framework which can be linked to iOS targets. | ||
apple_static_xcframework_import( | ||
name = "opencv_xcframework", | ||
visibility = ["//visibility:public"], | ||
xcframework_imports = [":opencv2_unzipped_xcframework_files"], | ||
) | ||
|
||
# Filters the headers for each platform in `opencv2.xcframework` which will be | ||
# used as headers in a `cc_library` that can be linked to C++ targets. | ||
select_headers( | ||
name = "opencv_xcframework_device_headers", | ||
srcs = [":opencv_xcframework"], | ||
platform = "ios-arm64", | ||
) | ||
|
||
select_headers( | ||
name = "opencv_xcframework_simulator_headers", | ||
srcs = [":opencv_xcframework"], | ||
platform = "ios-arm64_x86_64-simulator", | ||
) | ||
|
||
# `cc_library` that can be linked to C++ targets to import opencv headers. | ||
cc_library( | ||
name = "opencv", | ||
hdrs = select({ | ||
"@//mediapipe:ios_x86_64": [ | ||
":opencv_xcframework_simulator_headers", | ||
], | ||
"@//mediapipe:ios_sim_arm64": [ | ||
":opencv_xcframework_simulator_headers", | ||
], | ||
"@//mediapipe:ios_arm64": [ | ||
":opencv_xcframework_device_headers", | ||
], | ||
# A value from above is chosen arbitarily. | ||
"//conditions:default": [ | ||
":opencv_xcframework_simulator_headers", | ||
], | ||
}), | ||
copts = [ | ||
"-std=c++11", | ||
"-x objective-c++", | ||
], | ||
include_prefix = "opencv2", | ||
linkopts = [ | ||
"-framework AssetsLibrary", | ||
"-framework CoreFoundation", | ||
"-framework CoreGraphics", | ||
"-framework CoreMedia", | ||
"-framework Accelerate", | ||
"-framework CoreImage", | ||
"-framework AVFoundation", | ||
"-framework CoreVideo", | ||
"-framework QuartzCore", | ||
], | ||
strip_include_prefix = select({ | ||
"@//mediapipe:ios_x86_64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers", | ||
"@//mediapipe:ios_sim_arm64": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers", | ||
"@//mediapipe:ios_arm64": "opencv2.xcframework/ios-arm64/opencv2.framework/Versions/A/Headers", | ||
# Random value is selected for default cases. | ||
"//conditions:default": "opencv2.xcframework/ios-arm64_x86_64-simulator/opencv2.framework/Versions/A/Headers", | ||
}), | ||
visibility = ["//visibility:public"], | ||
deps = [":opencv_xcframework"], | ||
) |