diff --git a/apps/chanora_flutter/ios/Runner/SileroCoreMLBridge.swift b/apps/chanora_flutter/ios/Runner/SileroCoreMLBridge.swift index 3e2823c..692c302 100644 --- a/apps/chanora_flutter/ios/Runner/SileroCoreMLBridge.swift +++ b/apps/chanora_flutter/ios/Runner/SileroCoreMLBridge.swift @@ -106,6 +106,45 @@ public func chanoraSileroVadFreeString(_ string: UnsafeMutablePointer?) { @objc public static func run() { let started = DispatchTime.now() + // Static linker references: keep the Swift compiler / linker from + // dead-stripping the @_cdecl symbols under Whole-Module-Optimization + // + LTO in Archive builds. dlsym(RTLD_DEFAULT) below does NOT count + // as a static reference for the dead-stripper — these `_ = ` lines + // do. Without them, TestFlight builds shipped without the symbols + // even though Debug builds (no LTO) worked. + // + // The `withoutActuallyEscaping` dance prevents the optimizer from + // proving the references are unused: assigning the function value + // to a `@convention(c)` typealias forces address-taken semantics. + _ = unsafeBitCast( + chanoraSileroVadCreate as @convention(c) () -> UnsafeMutableRawPointer?, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadDestroy as @convention(c) (UnsafeMutableRawPointer?) -> Void, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadReset as @convention(c) (UnsafeMutableRawPointer?) -> Int32, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadProcess + as @convention(c) ( + UnsafeMutableRawPointer?, UnsafePointer?, Int, + UnsafeMutablePointer? + ) -> Int32, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadLastError as @convention(c) () -> UnsafeMutablePointer?, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadFreeString as @convention(c) (UnsafeMutablePointer?) -> Void, + to: UnsafeRawPointer.self, + ) + typealias CreateFn = @convention(c) () -> UnsafeMutableRawPointer? typealias DestroyFn = @convention(c) (UnsafeMutableRawPointer?) -> Void typealias ResetFn = @convention(c) (UnsafeMutableRawPointer?) -> Int32 diff --git a/apps/chanora_flutter/macos/Runner/SileroCoreMLBridge.swift b/apps/chanora_flutter/macos/Runner/SileroCoreMLBridge.swift index 3e2823c..692c302 100644 --- a/apps/chanora_flutter/macos/Runner/SileroCoreMLBridge.swift +++ b/apps/chanora_flutter/macos/Runner/SileroCoreMLBridge.swift @@ -106,6 +106,45 @@ public func chanoraSileroVadFreeString(_ string: UnsafeMutablePointer?) { @objc public static func run() { let started = DispatchTime.now() + // Static linker references: keep the Swift compiler / linker from + // dead-stripping the @_cdecl symbols under Whole-Module-Optimization + // + LTO in Archive builds. dlsym(RTLD_DEFAULT) below does NOT count + // as a static reference for the dead-stripper — these `_ = ` lines + // do. Without them, TestFlight builds shipped without the symbols + // even though Debug builds (no LTO) worked. + // + // The `withoutActuallyEscaping` dance prevents the optimizer from + // proving the references are unused: assigning the function value + // to a `@convention(c)` typealias forces address-taken semantics. + _ = unsafeBitCast( + chanoraSileroVadCreate as @convention(c) () -> UnsafeMutableRawPointer?, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadDestroy as @convention(c) (UnsafeMutableRawPointer?) -> Void, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadReset as @convention(c) (UnsafeMutableRawPointer?) -> Int32, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadProcess + as @convention(c) ( + UnsafeMutableRawPointer?, UnsafePointer?, Int, + UnsafeMutablePointer? + ) -> Int32, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadLastError as @convention(c) () -> UnsafeMutablePointer?, + to: UnsafeRawPointer.self, + ) + _ = unsafeBitCast( + chanoraSileroVadFreeString as @convention(c) (UnsafeMutablePointer?) -> Void, + to: UnsafeRawPointer.self, + ) + typealias CreateFn = @convention(c) () -> UnsafeMutableRawPointer? typealias DestroyFn = @convention(c) (UnsafeMutableRawPointer?) -> Void typealias ResetFn = @convention(c) (UnsafeMutableRawPointer?) -> Int32