mediapipe: Failing to build macos dylib

System information (Please provide as much relevant information as possible)

  • OS Platform and Distribution (e.g. Linux Ubuntu 16.04, Android 11, iOS 14.4): MacOS 11.4
  • Compiler version (e.g. gcc/g++ 8 /Apple clang version 12.0.0): XCode 12.3
  • Programming Language and version ( e.g. C++ 14, Python 3.6, Java ): bazel
  • Installed using virtualenv? pip? Conda? (if python): 3.9.1
  • MediaPipe version: top of tree or 0.8.3.1 (for 0.8.3.1 you need to modify WORKSPACE rules urls because they dead)
  • Bazel version: bazel 3.7.2-homebrew
  • XCode and Tulsi versions (if iOS): 12.3

Describe the problem: I am trying to build a dylib of mediapipe for external use on MacOS platform. I am trying to build the framework and a cpu calculator from tensorflow, you can see my BUILD snippet below

load("@build_bazel_rules_apple//apple:macos.bzl", "macos_dylib")
macos_dylib (
  name = "mediapipe_framework.dylib",
    minimum_os_version = "10.3",
  deps = [
     ":mediapipe_framework",
     "@macos_opencv//:opencv",
  ],
)

cc_library(
    name = "mediapipe_framework",
    linkopts = select({
        "//conditions:default": [],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//mediapipe/framework:calculator_framework",
        "//mediapipe/framework/tool:calculator_graph_template_cc_proto",
        "//mediapipe/framework/port:logging",
        "//mediapipe/framework/formats:classification_cc_proto",
        "//mediapipe/framework/formats:landmark_cc_proto",
        "//mediapipe/framework/formats:detection_cc_proto",
        "//mediapipe/framework/formats:rect_cc_proto",

    ]  + select({
        "//conditions:default": [
            "//mediapipe/graphs/hand_tracking:mobile_calculators",
           "//mediapipe/graphs/object_detection:mobile_calculators",
        ],
    
        "//mediapipe/gpu:disable_gpu": [
            "//mediapipe/graphs/hand_tracking:desktop_tflite_calculators",
            "//mediapipe/graphs/object_detection:desktop_tflite_calculators",
        ],
    }),
    alwayslink = 1,
)

I am not sure why it doesnt work but then i get a message on top of tree master when building

DEBUG: Rule 'rules_foreign_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "c2cdcf55ffaf49366725639e45dedd449b8c3fe22b54e31625eb80ce3a240f1e"
DEBUG: Repository rules_foreign_cc instantiated at:
  /mediapipe/WORKSPACE:42:13: in <toplevel>
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
WARNING: Download from http://mirror.tensorflow.org/github.com/tensorflow/runtime/archive/44c890cd46fd9aad2b3bf4b13c5f36d8cff795c3.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'bazel_skylib' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/org_tensorflow/third_party/repo.bzl:108:14:
Warning: skipping import of repository 'pybind11' because it already exists.
DEBUG: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/tf_runtime/third_party/cuda/dependencies.bzl:51:10: The following command will download NVIDIA proprietary software. By using the software you agree to comply with the terms of the license agreement that accompanies the software. If you do not agree to the terms of the license agreement, do not use the software.
DEBUG: Rule 'rules_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "02413e4a077107711ecc21458432e7c9ba63e75e63f3fa84ae4da2d6b2c82700"
DEBUG: Repository rules_cc instantiated at:
mediapipe/WORKSPACE:36:13: in <toplevel>
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
ERROR: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/cpuinfo/BUILD.bazel:100:11: Configurable attribute "srcs" doesn't match this configuration (would a default condition help?).
Conditions checked:
 @cpuinfo//:linux_x86_64
 @cpuinfo//:linux_arm
 @cpuinfo//:linux_armhf
 @cpuinfo//:linux_armv7a
 @cpuinfo//:linux_armeabi
 @cpuinfo//:linux_aarch64
 @cpuinfo//:linux_mips64
 @cpuinfo//:linux_riscv64
 @cpuinfo//:linux_s390x
 @cpuinfo//:macos_x86_64
 @cpuinfo//:macos_arm64
 @cpuinfo//:windows_x86_64
 @cpuinfo//:android_armv7
 @cpuinfo//:android_arm64
 @cpuinfo//:android_x86
 @cpuinfo//:android_x86_64
 @cpuinfo//:ios_x86_64
 @cpuinfo//:ios_x86
 @cpuinfo//:ios_armv7
 @cpuinfo//:ios_arm64
 @cpuinfo//:ios_arm64e
 @cpuinfo//:watchos_x86_64
 @cpuinfo//:watchos_x86
 @cpuinfo//:watchos_armv7k
 @cpuinfo//:watchos_arm64_32
 @cpuinfo//:tvos_x86_64
 @cpuinfo//:tvos_arm64
 @cpuinfo//:emscripten_wasm
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/ruy/archive/d37128311b445e758136b8602d1bbd2a755e115d.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
ERROR: Analysis of target '//mediapipe/external:mediapipe_framework.dylib2' failed; build aborted: /private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/cpuinfo/BUILD.bazel:100:11: Configurable attribute "srcs" doesn't match this configuration (would a default condition help?).
Conditions checked:
 @cpuinfo//:linux_x86_64
 @cpuinfo//:linux_arm
 @cpuinfo//:linux_armhf
 @cpuinfo//:linux_armv7a
 @cpuinfo//:linux_armeabi
 @cpuinfo//:linux_aarch64
 @cpuinfo//:linux_mips64
 @cpuinfo//:linux_riscv64
 @cpuinfo//:linux_s390x
 @cpuinfo//:macos_x86_64
 @cpuinfo//:macos_arm64
 @cpuinfo//:windows_x86_64
 @cpuinfo//:android_armv7
 @cpuinfo//:android_arm64
 @cpuinfo//:android_x86
 @cpuinfo//:android_x86_64
 @cpuinfo//:ios_x86_64
 @cpuinfo//:ios_x86
 @cpuinfo//:ios_armv7
 @cpuinfo//:ios_arm64
 @cpuinfo//:ios_arm64e
 @cpuinfo//:watchos_x86_64
 @cpuinfo//:watchos_x86
 @cpuinfo//:watchos_armv7k
 @cpuinfo//:watchos_arm64_32
 @cpuinfo//:tvos_x86_64
 @cpuinfo//:tvos_arm64
 @cpuinfo//:emscripten_wasm
INFO: Elapsed time: 0.179s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
    Fetching @clog; fetching
    Fetching @XNNPACK; fetching

I have also tried https://github.com/tensorflow/tensorflow/issues/41039 to change the darwin value. Sometimes if i modify the cpuinfo bazel file I get errors to XNNPack not having dependencies on line 4278.

/private/var/tmp/_bazel_me/b39a9c2497bafb052e53d56396554a9a/external/XNNPACK/BUILD.bazel:4278:26: Configurable attribute "deps" doesn't match this configuration (would a default condition help?).

I believe it has something to do with XNNPack. I dont think I need XNNPack (or is it even supported?) on MacOS. This might be an issue with TensorFlow trying to build MacOS with XNNPack.

I also tried to change the macos_dylib to cc_binary to build a “.dylib” and it builts but I cannot test it because I built with a newer version of MacOS and I get linking issues related to using this library built with the newest version of MacOS (not even sure it works anyways) because I cannot set the minimum macos version unless I use macos_dylib or even apple_binary.

Any reason why this doesn’t work?

**[Provide the exact sequence of commands / steps that you executed before running into the problem]

  1. Clone mediapipe
  2. Create an external folder in the root after mediapipe
  3. Add the BUILD file with above build settings
  4. Run command bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --copt -fvisibility=hidden --linkopt -s --strip always --cxxopt=-std=c++17 --apple_platform_type=macos mediapipe/external:mediapipe_framework.dylib

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

Hello @matthewn4444, We are upgrading the MediaPipe Legacy Solutions to new MediaPipe solutions However, the libraries, documentation, and source code for all the MediaPipe Legacy Solutions will continue to be available in our GitHub repository and through library distribution services, such as Maven and NPM.

You can continue to use those legacy solutions in your applications if you choose. Though, we would request you to check new MediaPipe solutions which can help you more easily build and customize ML solutions for your applications. These new solutions will provide a superset of capabilities available in the legacy solutions.

@JacobMuchow I had met the same problem…I try to modify the --cpu option to darwin/darwin_x86_64 but still same error occur