briantkelley / apple-rs

Idiomatic Rust bindings for iOS and macOS system libraries and frameworks.
Apache License 2.0
7 stars 0 forks source link

selector! Symbols Not Found with Parallel Compilation #1

Closed briantkelley closed 1 year ago

briantkelley commented 1 year ago

When multiple codegen-units are enabled, the linker can't find symbols generated via the selector! macro, even if the symbols are .globl. The crate should support parallel compilation and not rely on generating a single object file.

Example Output:

  "_SELECTOR_HASH", referenced from:
      objc4::objc::NSObjectProtocol::hash::h91eca09c69015546 in objc4-c139172f333a53e3.3pu9jnhuvgbntkkt.rcgu.o
  "_SELECTOR_IS_EQUAL_", referenced from:
      objc4::objc::NSObjectProtocol::is_equal::he789608616ce574a in objc4-c139172f333a53e3.3pu9jnhuvgbntkkt.rcgu.o
  "_SELECTOR_IS_PROXY", referenced from:
      objc4::objc::NSObjectProtocol::is_proxy::h6e8723108dba80f9 in objc4-c139172f333a53e3.3pu9jnhuvgbntkkt.rcgu.o
  "_SELECTOR_SUPERCLASS", referenced from:
      objc4::objc::NSObjectProtocol::superclass::hbe7c358e1df689cb in objc4-c139172f333a53e3.3pu9jnhuvgbntkkt.rcgu.o
ld: symbol(s) not found for architecture arm64
briantkelley commented 1 year ago

I don't think this is generally solvable in Rust (see attempts and commit messages in fb05e276682ee78a882c619895bb3388843062fc and 06b9ca90808e805ef27b46b433af2a428312a7e5).

The selector symbol must be emitted into each object file in which it's used and cannot be exported. But Rust defines the symbol once and assumes it's visible to the other translation units.

briantkelley commented 1 year ago

I think the only way the downstream linking problem can be fixed is to derive trait implementations for each object type. A general purpose derive procedural macro would likely leverage some bindgen support (#4). Although I suspect this won't fix the parallel compilation problem.

briantkelley commented 1 year ago

Topic posted on the Rust Users forum: Per Object File Symbols (Objective-C FFI).