Skip to content

rustc does not invoke ld with appropriate -target for linking a mac catalyst binary #80202

Closed
@visigoth

Description

@visigoth

I am trying to build a Mac Catalyst binary with rust. The compiler supports the x86_64-apple-ios-macabi target, but rustc does not invoke ld correctly. Note that I am building with xargo because I need to cross-compile core and std for the target triple myself (as Mac Catalyst is tier 3 iirc).

I have the simplest possible project hosted here: https://github.com/visigoth/catalystsample

When running xargo build --target x86_64-apple-ios-macabi, rustc eventually invokes cc like this to link the binary. Note that the invocation of rustc has -target x86_64-apple-ios-macabi in it, while cc is invoked with -arch x86_64:

     Running `rustc --crate-name catalystsample --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C metadata=720d334a6f1e8087 --out-dir /Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/deps --target x86_64-apple-ios-macabi -C incremental=/Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/incremental -L dependency=/Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/deps -L dependency=/Users/shaheen/code/catalystsample/target/debug/deps --sysroot /Users/shaheen/.xargo`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-arch" "x86_64" "-isysroot" "/Applications/Xcode_12.2.0_beta_4_fb.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk" "-Wl,-syslibroot" "/Applications/Xcode_12.2.0_beta_4_fb.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk" "-L" "/Users/shaheen/.xargo/lib/rustlib/x86_64-apple-ios-macabi/lib" ...

The important part is how cc is invoked: cc -arch x86_64. This fails with ld: building for macOS, but linking in object file built for Mac Catalyst, file ....

If I simply change cc -arch x86_64 to cc -target x86_64-apple-ios-macabi and run the command manually, the binary links and runs successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-iosOperating system: iOSO-macosOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions