google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.56k stars 5.16k forks source link

build_ios_framework.sh cannot build framework #5491

Closed uranus0206 closed 4 months ago

uranus0206 commented 4 months ago

OS Platform and Distribution

macOS 14.4.1

Compiler version

No response

Programming Language and version

Python3.11.9

Installed using virtualenv? pip? Conda?(if python)

pyenv

MediaPipe version

commit "6c463513"

Bazel version

6.1.1

XCode and Tulsi versions (if iOS)

Xcode 15.3

Android SDK and NDK versions (if android)

No response

Android AAR (if android)

No

OpenCV version (if running on desktop)

No response

Describe the problem

Framework build fail

Complete Logs

mediapipe % FRAMEWORK_NAME=MediaPipeTasksCommon ./mediapipe/tasks/ios/build_ios_framework.sh

++ uname
+ [[ Darwin != \D\a\r\w\i\n ]]
++ which bazel
+ BAZEL=/opt/homebrew/bin/bazel
+ MPP_BUILD_VERSION=0.0.1-dev
++ git rev-parse --show-toplevel
+ MPP_ROOT_DIR=/Users/chung-iwu/codeBase/tensorflow/mediaPipe/mediapipe
+ ARCHIVE_FRAMEWORK=true
+ IS_RELEASE_BUILD=false
+ DEST_DIR=/Users/chung-iwu
+ echo Destination
Destination
+ echo /Users/chung-iwu
/Users/chung-iwu
+ [[ ! -x /opt/homebrew/bin/bazel ]]
+ '[' -z x ']'
+ case $FRAMEWORK_NAME in
+ [[ -z x ]]
+ [[ /Users/chung-iwu == /Users/chung-iwu/codeBase/tensorflow/mediaPipe/mediapipe* ]]
+ cd /Users/chung-iwu/codeBase/tensorflow/mediaPipe/mediapipe
+ build_ios_frameworks_and_libraries
+ local TARGET_PREFIX=//mediapipe/tasks/ios
+ FULL_FRAMEWORK_TARGET=//mediapipe/tasks/ios:MediaPipeTasksCommon_framework
+ local 'FRAMEWORK_CQUERY_COMMAND=-c opt --config=ios_sim_device_fat --apple_generate_dsym=false --define OPENCV=source //mediapipe/tasks/ios:MediaPipeTasksCommon_framework'
+ /opt/homebrew/bin/bazel build -c opt --config=ios_sim_device_fat --apple_generate_dsym=false --define OPENCV=source //mediapipe/tasks/ios:MediaPipeTasksCommon_framework
INFO: Build options --apple_generate_dsym, --apple_platform_type, --compilation_mode, and 4 more have changed, discarding analysis cache.
WARNING: /Users/chung-iwu/codeBase/tensorflow/mediaPipe/mediapipe/mediapipe/framework/tool/BUILD:201:24: in cc_library rule //mediapipe/framework/tool:field_data_cc_proto: target '//mediapip
e/framework/tool:field_data_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
WARNING: /Users/chung-iwu/codeBase/tensorflow/mediaPipe/mediapipe/mediapipe/framework/BUILD:69:24: in cc_library rule //mediapipe/framework:calculator_cc_proto: target '//mediapipe/framework
:calculator_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
INFO: Analyzed target //mediapipe/tasks/ios:MediaPipeTasksCommon_framework (0 packages loaded, 16018 targets configured).
INFO: Found 1 target...
[5,803 / 5,818] 3 actions running
    Executing genrule @ios_opencv_source//:build_opencv_xcframework; 132s darwin-sandbox
    Executing genrule @ios_opencv_source//:build_opencv_xcframework; 132s darwin-sandbox
    Executing genrule @ios_opencv_source//:build_opencv_xcframework; 132s darwin-sandbox

...
ERROR: /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/external/ios_opencv_source/BUILD.bazel:30:8: Executing genrule @ios_opencv_source//:build_opencv_xcframework failed:
 (Exit 1): bash failed: error executing command (from target @ios_opencv_source//:build_opencv_xcframework) /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Executing: ['python3', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/i
os/build_framework.py', 'bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos', '--iphoneos_archs', 'arm64', '--framework_na
me', 'opencv2', '--build_only_specified_archs', '--without', 'dnn', '--without', 'ml', '--without', 'stitching', '--without', 'photo', '--without', 'objdetect', '--without', 'gapi', '--witho
ut', 'flann', '--without', 'highgui', '--without', 'videoio', '--disable', 'PROTOBUF', '--disable-bitcode', '--disable-swift'] in /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bce
c0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe
Executing: ['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DOPENCV_INCLUDE_INSTALL_PATH=include', '-DOPENCV_3P_LIB_INSTALL_PATH
=lib/3rdparty', '-DFRAMEWORK_NAME=opencv2', '-DBUILD_opencv_dnn=OFF', '-DBUILD_opencv_ml=OFF', '-DBUILD_opencv_stitching=OFF', '-DBUILD_opencv_photo=OFF', '-DBUILD_opencv_objdetect=OFF', '-D
BUILD_opencv_gapi=OFF', '-DBUILD_opencv_flann=OFF', '-DBUILD_opencv_highgui=OFF', '-DBUILD_opencv_videoio=OFF', '-DWITH_PROTOBUF=OFF', '-DIOS_ARCH=arm64', '-DCMAKE_TOOLCHAIN_FILE=/private/va
r/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/cmake/Toolchains/Toolchain-iPhon
eOS_Xcode.cmake', '-DCPU_BASELINE=DETECT', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/open
cv-4.5.3'] in /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-op
t-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos/build/build-arm64-iphoneos
CMake Error at /opt/homebrew/Cellar/cmake/3.29.6/share/cmake/Modules/CheckTypeSize.cmake:146 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-9169
1cd96131/bin/external/ios_opencv_source/iphoneos/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_SIZE_T.bin'

  because:

    No such file or directory (input)

  Recorded try_compile output location doesn't exist:

    /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691
cd96131/bin/external/ios_opencv_source/iphoneos/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-A2NFGW/Release/cmTC_27d47.app/cmTC_27d47

Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.29.6/share/cmake/Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
  3rdparty/libjpeg-turbo/CMakeLists.txt:25 (check_type_size)

CMake Error at /opt/homebrew/Cellar/cmake/3.29.6/share/cmake/Modules/CheckTypeSize.cmake:146 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-9169
1cd96131/bin/external/ios_opencv_source/iphoneos/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_UNSIGNED_LONG.bin'

  because:

    No such file or directory (input)

  Recorded try_compile output location doesn't exist:

    /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691
cd96131/bin/external/ios_opencv_source/iphoneos/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-xX07c7/Release/cmTC_1c3f5.app/cmTC_1c3f5

Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.29.6/share/cmake/Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
  3rdparty/libjpeg-turbo/CMakeLists.txt:26 (check_type_size)

============================================================
ERROR: Command '['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DOPENCV_INCLUDE_INSTALL_PATH=include', '-DOPENCV_3P_LIB_INSTALL
_PATH=lib/3rdparty', '-DFRAMEWORK_NAME=opencv2', '-DBUILD_opencv_dnn=OFF', '-DBUILD_opencv_ml=OFF', '-DBUILD_opencv_stitching=OFF', '-DBUILD_opencv_photo=OFF', '-DBUILD_opencv_objdetect=OFF'
, '-DBUILD_opencv_gapi=OFF', '-DBUILD_opencv_flann=OFF', '-DBUILD_opencv_highgui=OFF', '-DBUILD_opencv_videoio=OFF', '-DWITH_PROTOBUF=OFF', '-DIOS_ARCH=arm64', '-DCMAKE_TOOLCHAIN_FILE=/priva
te/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/cmake/Toolchains/Toolchain-
iPhoneOS_Xcode.cmake', '-DCPU_BASELINE=DETECT', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source
/opencv-4.5.3']' returned non-zero exit status 1.
============================================================
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/build_framewo
rk.py", line 176, in build
    self._build(outdir)
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/build_framewo
rk.py", line 134, in _build
    self.buildOne(target[0], target[1], main_build_dir, cmake_flags)
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/build_framewo
rk.py", line 301, in buildOne
    execute(cmakecmd, cwd = builddir)
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/apple/cv_build_ut
ils.py", line 13, in execute
    retcode = check_call(cmd, cwd = cwd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/chung-iwu/.pyenv/versions/3.11.9/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DOPENCV_INCLUDE_INSTALL_PATH=include', 
'-DOPENCV_3P_LIB_INSTALL_PATH=lib/3rdparty', '-DFRAMEWORK_NAME=opencv2', '-DBUILD_opencv_dnn=OFF', '-DBUILD_opencv_ml=OFF', '-DBUILD_opencv_stitching=OFF', '-DBUILD_opencv_photo=OFF', '-DBUI
LD_opencv_objdetect=OFF', '-DBUILD_opencv_gapi=OFF', '-DBUILD_opencv_flann=OFF', '-DBUILD_opencv_highgui=OFF', '-DBUILD_opencv_videoio=OFF', '-DWITH_PROTOBUF=OFF', '-DIOS_ARCH=arm64', '-DCMA
KE_TOOLCHAIN_FILE=/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/cma
ke/Toolchains/Toolchain-iPhoneOS_Xcode.cmake', '-DCPU_BASELINE=DETECT', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/ex
ternal/ios_opencv_source/opencv-4.5.3']' returned non-zero exit status 1.
============================================================
ERROR: Command '['python3', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platfo
rms/ios/build_framework.py', 'bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos', '--iphoneos_archs', 'arm64', '--framewo
rk_name', 'opencv2', '--build_only_specified_archs', '--without', 'dnn', '--without', 'ml', '--without', 'stitching', '--without', 'photo', '--without', 'objdetect', '--without', 'gapi', '--
without', 'flann', '--without', 'highgui', '--without', 'videoio', '--disable', 'PROTOBUF', '--disable-bitcode', '--disable-swift']' returned non-zero exit status 1.
============================================================
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/apple/build_xcfra
mework.py", line 87, in <module>
    execute(command, cwd=os.getcwd())
  File "/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/external/ios_opencv_source/opencv-4.5.3/platforms/apple/cv_build_utils.py", line 13, in execute
    retcode = check_call(cmd, cwd = cwd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/chung-iwu/.pyenv/versions/3.11.9/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['python3', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_so
urce/opencv-4.5.3/platforms/ios/build_framework.py', 'bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos', '--iphoneos_arc
hs', 'arm64', '--framework_name', 'opencv2', '--build_only_specified_archs', '--without', 'dnn', '--without', 'ml', '--without', 'stitching', '--without', 'photo', '--without', 'objdetect', 
'--without', 'gapi', '--without', 'flann', '--without', 'highgui', '--without', 'videoio', '--disable', 'PROTOBUF', '--disable-bitcode', '--disable-swift']' returned non-zero exit status 1.
...

['python3', '/private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/build_fr
amework.py', 'bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos', '--iphoneos_archs', 'arm64', '--framework_name', 'openc
v2', '--build_only_specified_archs', '--without', 'dnn', '--without', 'ml', '--without', 'stitching', '--without', 'photo', '--without', 'objdetect', '--without', 'gapi', '--without', 'flann
', '--without', 'highgui', '--without', 'videoio', '--disable', 'PROTOBUF', '--disable-bitcode', '--disable-swift']
Executing: python3 /private/var/tmp/_bazel_chung-iwu/c2178a5056d454cfecc79a5bcec0a30a/sandbox/darwin-sandbox/11682/execroot/mediapipe/external/ios_opencv_source/opencv-4.5.3/platforms/ios/bu
ild_framework.py bazel-out/ios-sim_arm64-min12.0-applebin_ios-ios_sim_arm64-opt-ST-91691cd96131/bin/external/ios_opencv_source/iphoneos --iphoneos_archs arm64 --framework_name opencv2 --buil
d_only_specified_archs --without dnn --without ml --without stitching --without photo --without objdetect --without gapi --without flann --without highgui --without videoio --disable PROTOBU
F --disable-bitcode --disable-swift
Target //mediapipe/tasks/ios:MediaPipeTasksCommon_framework failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 162.157s, Critical Path: 160.75s
INFO: 9 processes: 8 internal, 1 darwin-sandbox.
FAILED: Build did NOT complete successfully

I am trying to build ios framework from source code. I found there's a script in mediapipe/tasks/ios/build_ios_framework.sh. I thought it's the script ot build mediapipe xcframework for ios platform.

Then i try to build "MediaPipaTasksCommon" by the script. First i have encountered some python check error for external library org_tensorflow. I fix the issue by coping python env related parameters to .bazelrc as below.

build --action_env PYTHON_BIN_PATH="/Users/chung-iwu/.pyenv/versions/3.11.9/bin/python3"
build --action_env PYTHON_LIB_PATH="/Users/chung-iwu/.pyenv/versions/3.11.9/lib/python3.11/site-packages"
build --python_path="/Users/chung-iwu/.pyenv/versions/3.11.9/bin/python3"
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-Wno-sign-compare
test --test_size_filters=small,medium
test:v1 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-nomac,-no_mac,-mac_excluded,-oss_serial
test:v1 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-nomac,-no_mac,-mac_excluded
test:v2 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-nomac,-no_mac,-mac_excluded,-oss_serial,-v1only
test:v2 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-gpu,-nomac,-no_mac,-mac_excluded,-v1only

Then i run the script again. However i got some error related to opencv.

According to errors, it seems failed on build opencv by cmake. I have installed cmake by homebrew and the info version as below

brew info cmake
Warning: Treating cmake as a formula. For the cask, use homebrew/cask/cmake or specify the `--cask` flag.
==> cmake: stable 3.29.6 (bottled), HEAD
Cross-platform make
https://www.cmake.org/
Installed
/opt/homebrew/Cellar/cmake/3.29.6 (3,385 files, 55.5MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-06-19 at 14:44:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/c/cmake.rb
License: BSD-3-Clause
==> Options
--HEAD
    Install HEAD version
==> Caveats
To install the CMake documentation, run:
  brew install cmake-docs

Emacs Lisp files have been installed to:
  /opt/homebrew/share/emacs/site-lisp/cmake
==> Analytics
install: 143,098 (30 days), 424,664 (90 days), 1,618,734 (365 days)
install-on-request: 111,710 (30 days), 332,483 (90 days), 1,271,332 (365 days)
build-error: 461 (30 days)

Also checked the suggestions to make sure xcode develop tools path https://github.com/google-ai-edge/mediapipe/issues/5221#issuecomment-1993658734

xcode-select -p
/Applications/Xcode.app/Contents/Developer

And from the suggestion about opencv source, i do not know what content i should change if i just want to build the xcframework same as cocoapods provided. https://github.com/google-ai-edge/mediapipe/issues/5143#issuecomment-1948598238

Is anyone try to build framework for ios too?

uranus0206 commented 4 months ago

Hi. I finally solve the issue by uninstall cmake from homebrew and downgrade cmake version to 3.24.4 by official installer.

Now i can build MediaPipeTasksCommon and MediaPipeTasksVision xcframework.

And i also confirm the frameworks which i built from mac can be used by my example app.

google-ml-butler[bot] commented 4 months ago

Are you satisfied with the resolution of your issue? Yes No