bevy icon indicating copy to clipboard operation
bevy copied to clipboard

linking error when used with wry/tao on macOS aarch64

Open TarekAS opened this issue 1 year ago • 6 comments
trafficstars

Bevy version

0.12.1

Relevant system information

Chip: Apple M1 Max OS: macOS Sonoma 14.3 Rustc: 1.75.0 (stable) Xcode 15.2

What you did

Consider the following minimal Rust program:

// main.rs
use bevy::prelude::*;

use tao::event_loop::EventLoop;

fn main() {
    let event_loop: EventLoop<()> = EventLoop::new();
}
// Cargo.toml
[package]
name = "mygame"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { version = "0.12.1", default-features = false, features = [
    "bevy_render",
    "dynamic_linking",
] }
tao = { version = "0.25.0", default-features = false }
wry = { version = "0.36.0" }

Run it on an ARM Mac and it will cause a linking error. I have tried this on 3 separate M1 Macs and it causes the same issue. I updated the OS and Xcode and that didn't solve the problem either.

What went wrong

Project is expected to build with no issue, or an error at the compile level. Instead I get the following linking error:

error: linking with `cc` failed: exit status: 1
  |
  = note: env -u <redacted env print>

= note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lobjc'
          ld: Undefined symbols:
            _RustObjCExceptionTryCatch, referenced from:
                objc_exception::try_no_ret::hb6c5f46d0765cd58 in libtao-b2a7c9fe6e7760b2.rlib[7](tao-b2a7c9fe6e7760b2.tao.44e5656fbb1da1ec-cgu.04.rcgu.o)
                objc_exception::try_no_ret::heb888d6999c3a1ab in libtao-b2a7c9fe6e7760b2.rlib[7](tao-b2a7c9fe6e7760b2.tao.44e5656fbb1da1ec-cgu.04.rcgu.o)
                objc_exception::try_no_ret::h467675c166da1eb2 in libcocoa-bdc083df61ae20c1.rlib[5](cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o)
                objc_exception::try_no_ret::ha07b8ef05ba8efa8 in libcocoa-bdc083df61ae20c1.rlib[5](cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o)
                objc_exception::try_no_ret::hd9a8b230a39d73a6 in libcocoa-bdc083df61ae20c1.rlib[5](cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o)
                objc_exception::try_no_ret::he0d4cb60d8d7f302 in libcocoa-bdc083df61ae20c1.rlib[5](cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o)
                objc_exception::try_no_ret::he239be2eac779649 in libcocoa-bdc083df61ae20c1.rlib[5](cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o)
                ...
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Switching to Mach-O LLVM linker (aka ld64.lld) doesn't help, and returns a similar error:

note: ld64.lld: error: undefined symbol: RustObjCExceptionTryCatch
          >>> referenced by lib.rs:44 (/Users/redacted/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_exception-0.1.2/src/lib.rs:44)
          >>>               /Users/redacted/wrkspc/bevy_sandbox/target/debug/deps/libtao-b2a7c9fe6e7760b2.rlib(tao-b2a7c9fe6e7760b2.tao.44e5656fbb1da1ec-cgu.04.rcgu.o):(symbol objc_exception::try_no_ret::hb6c5f46d0765cd58+0xb8)
          >>> referenced by lib.rs:44 (/Users/redacted/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_exception-0.1.2/src/lib.rs:44)
          >>>               /Users/redacted/wrkspc/bevy_sandbox/target/debug/deps/libtao-b2a7c9fe6e7760b2.rlib(tao-b2a7c9fe6e7760b2.tao.44e5656fbb1da1ec-cgu.04.rcgu.o):(symbol objc_exception::try_no_ret::heb888d6999c3a1ab+0xa4)
          >>> referenced by lib.rs:44 (/Users/redacted/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc_exception-0.1.2/src/lib.rs:44)
          >>>               /Users/redacted/wrkspc/bevy_sandbox/target/debug/deps/libcocoa-bdc083df61ae20c1.rlib(cocoa-bdc083df61ae20c1.cocoa.9d90b2958afad0f3-cgu.2.rcgu.o):(symbol objc_exception::try_no_ret::h467675c166da1eb2+0xb8)
          >>> referenced 17 more times
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

This occurs on both release and debug builds. I tried downgrading wry and tao from their latest versions (0.36 and 0.25 respectively) but still ended up with the same variation of the error

Additional information

I opened a parallel issue in the wry repo (here), as I can't tell which project is actually causing this.

TarekAS avatar Feb 08 '24 07:02 TarekAS

~~I don't think this is wry, because it's not referenced in the error nor imported by the program. I think this is an issue with tao, which raises an exception when linking to MacOS's Cocoa library. objc_exception also appeared a few times, so it may be related to that.~~

I'm going to try testing this locally.

BD103 avatar Feb 08 '24 12:02 BD103

This is an issue with Bevy's dynamic_linking feature. If you turn it off, it will no longer fail to compile. This error requires toa, wry, and bevy to reproduce it. I'm not sure what's going on, but turning off dynamic linking should fix the issue.

BD103 avatar Feb 08 '24 13:02 BD103

Turning off dynamic_linking does indeed make it work, I forgot to mention that in the OP. But would still rather leave it on for development purposes.

Also if bevy_render is removed it works. But enabling anything else that has to do with graphics would make it occur again.

TarekAS avatar Feb 08 '24 18:02 TarekAS

That's very weird. I don't know enough about the libraries (+ Objective C) in question to be able to debug it myself, but let's leave the issue open.

BD103 avatar Feb 09 '24 02:02 BD103