Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to build for macOS x86_64 from M1 #3932

Closed
joliveraortega opened this issue Dec 15, 2022 · 6 comments
Closed

How to build for macOS x86_64 from M1 #3932

joliveraortega opened this issue Dec 15, 2022 · 6 comments
Assignees
Labels
platform:apple silicon apple silicon chip platform:c++ Issues specific to C++ framework in mediapipe task::all All tasks of MediaPipe type:build/install For Build and Installation issues

Comments

@joliveraortega
Copy link

joliveraortega commented Dec 15, 2022

Hi there!

I am sorry I am asking this here this silly question but I am new to Bazel and how Bazel works when building Mediapipe. I have a M1 so any sample gets build for arm64. I wonder how to build for x86_64 from M1. I have tried a bunch of command line combinations and read here and there but I am not able to see the final binary built for x86_64. I am not actually interested on building samples but a library in a form of a universal binary for macOS.

Looking forward to hear from you guys. Thanks in advance.

@joliveraortega joliveraortega added the type:others issues not falling in bug, perfromance, support, build and install or feature label Dec 15, 2022
@kuaashish kuaashish self-assigned this Dec 16, 2022
@kuaashish kuaashish added type:build/install For Build and Installation issues platform:apple silicon apple silicon chip task::all All tasks of MediaPipe and removed type:others issues not falling in bug, perfromance, support, build and install or feature labels Dec 16, 2022
@kuaashish
Copy link
Collaborator

Hi @joliveraortega,
Would you please let us know the complete steps followed to address the issue better from our end.

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Dec 16, 2022
@joliveraortega
Copy link
Author

I finally managed to build for the two macOS archs (x86_64 and arm64) from my M1. Not sure the way I did is the correct one (or the one you should follow when trying this).

Long story short; I used --macos_cpus=x86_64,arm64 flag for my Bazel build command line.

Some context; I am building Mediapipe v0.8.11 with GPU support enabled as a static library for macOS. For the build to build successfully for the two macOS archs I have to patch two things (the patches are needed when building for x86_64 from M1 actually, there is no need for them for the arm64 build to finish successfully).

  • Patch bazel-mediapipe/external/XNNPACK/BUILD.bazel:
diff --git a/BUILD.bazel b/BUILD.bazel
index 2e71597..1c0e2e2 100755
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -13979,7 +13979,7 @@ config_setting(
     name = "macos_x86_64",
     values = {
         "apple_platform_type": "macos",
-        "cpu": "darwin",
+        "cpu": "darwin_x86_64",
     },
 )
  • Patch bazel-mediapipe/external/cpuinfo: Same change line 240.

Without these patches you get the "Configurable attribute "srcs" doesn't match this configuration (would a default condition help?)." error.

I would love to hear from you guys what's the "official" way to build for the two macOS archs from a M1. IMO the way I managed to build them is a bit tricky and guess there has to be another straightforward way.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Dec 16, 2022
@kuaashish
Copy link
Collaborator

Hi @joliveraortega,
There is no official support to build macOS x86_64 yet. Since this solution works for you, this will help our larger community to build the mediapipe on two archs.(Tip: You can refer this closed issue #2798(comment) and workaround if helps)

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Dec 16, 2022
@joliveraortega
Copy link
Author

I guess you mean it is not officially supported building for macOS x86_64 from M1. If anyone follows https://google.github.io/mediapipe/getting_started/install.html#installing-on-macos the build process has no problems for M1 as a host/execution/target platform. Glad this could help others. Thanks for following up on this with me. I appreciate it. You can close the issue. I will reopen it in case it is needed because any other issue from my end about this. Cheers.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Dec 16, 2022
@google-ml-butler
Copy link

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

@kuaashish kuaashish added the platform:c++ Issues specific to C++ framework in mediapipe label Dec 29, 2022
@zahidiOS
Copy link

I finally managed to build for the two macOS archs (x86_64 and arm64) from my M1. Not sure the way I did is the correct one (or the one you should follow when trying this).

Long story short; I used --macos_cpus=x86_64,arm64 flag for my Bazel build command line.

Some context; I am building Mediapipe v0.8.11 with GPU support enabled as a static library for macOS. For the build to build successfully for the two macOS archs I have to patch two things (the patches are needed when building for x86_64 from M1 actually, there is no need for them for the arm64 build to finish successfully).

  • Patch bazel-mediapipe/external/XNNPACK/BUILD.bazel:
diff --git a/BUILD.bazel b/BUILD.bazel
index 2e71597..1c0e2e2 100755
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -13979,7 +13979,7 @@ config_setting(
     name = "macos_x86_64",
     values = {
         "apple_platform_type": "macos",
-        "cpu": "darwin",
+        "cpu": "darwin_x86_64",
     },
 )
  • Patch bazel-mediapipe/external/cpuinfo: Same change line 240.

Without these patches you get the "Configurable attribute "srcs" doesn't match this configuration (would a default condition help?)." error.

I would love to hear from you guys what's the "official" way to build for the two macOS archs from a M1. IMO the way I managed to build them is a bit tricky and guess there has to be another straightforward way.

Congratulations!!! Could you tell us details how you did this? Eg: What was the command? How did you extract the library & use it to Xcode macOS project? It'll be helpful for us. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:apple silicon apple silicon chip platform:c++ Issues specific to C++ framework in mediapipe task::all All tasks of MediaPipe type:build/install For Build and Installation issues
Projects
None yet
Development

No branches or pull requests

3 participants