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

On Apple M1, objc_library compiled with darwin_x86_64 but cc_library compiled with darwin_arm64, and failed at link time #14803

Closed
merckhung opened this issue Feb 12, 2022 · 3 comments
Labels
team-Rules-ObjC Issues for Objective-C maintainers type: bug untriaged

Comments

@merckhung
Copy link

Description of the problem / feature request:

I have a project uses both cc_library and objc_library to compile for MacOS X platform.
The project could compile and run properly until I switched to Apple M1 based MacOS X.

I discovered that on M1 MacOS X, Bazel compiles objc_library with darwin_x86_64 platform and compiles
cc_library/cc_binary with darwin_arm64 platform. Therefore, the project no longer links these two libraries successfully.
The compilation fails at link-time with this error message:

ld: warning: ignoring file bazel-out/applebin_macos-darwin_x86_64-dbg-ST-cfb676c6944e/bin/test/libmacfile.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I have a minimal example project to reproduce this problem, please find the attached file.

objc_apple_m1_linker.zip

unzip objc_apple_m1_linker.zip
cd objc_apple_m1_linker
bazel build -c dbg //test -s
ls -al bazel-out/

drwxr-xr-x 3 merck wheel 96 Feb 11 18:38 applebin_macos-darwin_x86_64-dbg-ST-cfb676c6944e
drwxr-xr-x 4 merck wheel 128 Feb 11 18:38 darwin_arm64-dbg

  • objc_library was compiled into applebin_macos-darwin_x86_64-dbg-ST-cfb676c6944e
  • cc_binary was compiled into darwin_arm64-dbg, they failed to link with each other.

What operating system are you running Bazel on?

Apple M1 (ARM64) MacOS X 12.2.1
bazel version is 6.0.0-pre.20220112.2 (Darwin ARM64 variant bazel-6.0.0-pre.20220112.2-darwin-arm64)

What's the output of bazel info release?

release 6.0.0-pre.20220112.2

Have you found anything relevant by searching the web?

I tried, but I didn't find anything similar.

@oquenchil oquenchil added team-Rules-ObjC Issues for Objective-C maintainers type: bug untriaged labels Feb 14, 2022
keith added a commit to keith/bazel that referenced this issue Feb 14, 2022
Since M1 support was added we started defaulting the CPU for macOS and
iOS builds to the host CPU in the case another CPU wasn't passed. This
change mirrors bazelbuild#13873,
bazelbuild#13440 and
https://github.com/bazelbuild/rules_apple//commit/99e5b631bf060358241a8eaabd285be5c120490f
in the newer starlark transition.

Without this you end up with architecture mismatches for builds. Fixes bazelbuild#14803
@keith
Copy link
Member

keith commented Feb 14, 2022

Thanks for the repro case, fix here! #14816

@brentleyjones
Copy link
Contributor

@bazel-io fork 5.1

@keith
Copy link
Member

keith commented Feb 17, 2022

As a temporary workaround you can probably pass --experimental_builtins_injection_override=-objc_library

brentleyjones pushed a commit to brentleyjones/bazel that referenced this issue Mar 1, 2022
Since M1 support was added we started defaulting the CPU for macOS and
iOS builds to the host CPU in the case another CPU wasn't passed. This
change mirrors bazelbuild#13873, bazelbuild#13440 and https://github.com/bazelbuild/rules_apple//commit/99e5b631bf060358241a8eaabd285be5c120490f
in the newer starlark transition.

Without this you end up with architecture mismatches for builds. Fixes bazelbuild#14803

Closes bazelbuild#14816.

PiperOrigin-RevId: 431641312
(cherry picked from commit 1ec1068)
Wyverald pushed a commit that referenced this issue Mar 2, 2022
Since M1 support was added we started defaulting the CPU for macOS and
iOS builds to the host CPU in the case another CPU wasn't passed. This
change mirrors #13873, #13440 and https://github.com/bazelbuild/rules_apple//commit/99e5b631bf060358241a8eaabd285be5c120490f
in the newer starlark transition.

Without this you end up with architecture mismatches for builds. Fixes #14803

Closes #14816.

PiperOrigin-RevId: 431641312
(cherry picked from commit 1ec1068)

Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
realityforge added a commit to realityforge/Quake-III-Arena that referenced this issue Mar 23, 2022
…led with darwin_x86_64 rather than darwin_arm64

See bazelbuild/bazel#14803 for further details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-ObjC Issues for Objective-C maintainers type: bug untriaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants