ikhvorost / ReactBridge

Swift Macros for React Native
MIT License
38 stars 4 forks source link

Xcode 16b1 • Undefined symbols #9

Closed Brett-Best closed 4 months ago

Brett-Best commented 5 months ago

Using Xcode 16b1 we are currently unable to compile because of:

Undefined symbols for architecture arm64:
  "methodInfo.unsafeMutableAddressor : Reproducer.RCTMethodInfo in Static #1 in static Reproducer.CalendarModule.__rct_export__createEvent() -> Swift.UnsafePointer<Reproducer.RCTMethodInfo>?", referenced from:
      static Reproducer.CalendarModule.__rct_export__createEvent() -> Swift.UnsafePointer<Reproducer.RCTMethodInfo>? in noop-file.o
ld: symbol(s) not found for architecture arm64

Reproducer:

@ReactModule(jsName: "Calendar")
class CalendarModule: NSObject, RCTBridgeModule {

  @ReactMethod
  @objc func createEvent(title: String, location: String) {
    print("Create event '\(title)' at '\(location)'")
  }
}

Workaround, inline the macro source:

@ReactModule(jsName: "Calendar")
class CalendarModule: NSObject, RCTBridgeModule {
  @objc func createEvent(title: String, location: String) {
    print("Create event '\(title)' at '\(location)'")
  }

  @objc static func __rct_export__createEvent() -> UnsafePointer<RCTMethodInfo>? {
    struct Static {
      static let jsName = strdup("createEvent")
      static let objcName = strdup("createEventWithTitle:(NSString * _Nonnull)title location:(NSString * _Nonnull)location")
      nonisolated (unsafe) static var methodInfo = RCTMethodInfo(jsName: jsName, objcName: objcName, isSync: false)
    }
    return withUnsafePointer(to: &Static.methodInfo) {
      $0
    }
  }

Feels like an Xcode and/or Swift bug at this point given the inlined source works fine.

ikhvorost commented 5 months ago

Hi! I'm able to reproduce the same on Xcode 16 beta and it looks like a Xcode's issue with macros because it throws the error for Swift 5. Lets wait next beta to test.

Brett-Best commented 5 months ago

Yeah agreed, I'll get a feedback raised and TSI with Apple and post any updates I receive 🙂

ikhvorost commented 4 months ago

The issue is fixed on Xcode 16 beta in 1.2.0. Thanks.