fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.12k stars 283 forks source link

[Bug] Flutter macos build crashed on M2 Mac #815

Closed kingfisherphuoc closed 1 year ago

kingfisherphuoc commented 1 year ago

Describe the bug

I built a MacOS app by using Flutter (flutter build macos command). It's working well on my M1 Macbook. However, when I tested on my friend's M2 Mac, it crashed. Does anyone have a clue how to fix it? Here's the log:

Version:               1.0.0 (1)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2022-11-02 15:44:34.0519 +0700
OS Version:            macOS 12.6 (21G115)
Report Version:        12
Anonymous UUID:        610CC70D-80DB-362E-6168-CB7FFD990E40

Sleep/Wake UUID:       686BA11E-F563-4C8F-AA19-C4937F9181DC

Time Awake Since Boot: 9500 seconds
Time Since Wake:       5014 seconds

System Integrity Protection: enabled

Crashed Thread:        0

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: '/Users/*/Library/Developer/Xcode/DerivedData/Runner-eixmpjopssepzedozqbaoavjkhar/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/native.build/cargo_target/aarch64-apple-darwin/release/deps/libnative.dylib'
Referenced from: '/private/var/folders/*/Proxy App.app/Contents/MacOS/Proxy App'
Reason: tried: '/Users/*/Library/Developer/Xcode/DerivedData/Runner-eixmpjopssepzedozqbaoavjkhar/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/native.build/cargo_target/aarch64-apple-darwin/release/deps/libnative.dylib' (no such file), '' (no such file), '' (no such file)
(terminated at launch; ignore backtrace)
Thread 0 Crashed:
0   dyld                                   0x105103e98 __abort_with_payload + 8
1   dyld                                   0x10510b024 abort_with_payload_wrapper_internal + 104
2   dyld                                   0x10510b058 abort_with_payload + 16
3   dyld                                   0x1050c2a28 dyld4::halt(char const*) + 580
4   dyld                                   0x1050bdfb8 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3644
5   dyld                                   0x1050bd06c start + 488

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000006   x1: 0x0000000000000001   x2: 0x000000016b11e928   x3: 0x00000000000001ab
    x4: 0x000000016b11e528   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000000000020   x9: 0x0000000000000009  x10: 0x000000016b11e6fc  x11: 0x00000000000002d2
   x12: 0x0000000000000000  x13: 0x0000000000000036  x14: 0x00000002703cf8db  x15: 0x0000000000000000
   x16: 0x0000000000000209  x17: 0x00000001050bb14c  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x000000016b11e528  x21: 0x00000000000001ab  x22: 0x000000016b11e928  x23: 0x0000000000000001
   x24: 0x0000000000000006  x25: 0x000000016b11e528  x26: 0x0000000000000400  x27: 0x00000000000003ca
   x28: 0x0000000000000316   fp: 0x000000016b11e4f0   lr: 0x000000010510b024
    sp: 0x000000016b11e4b0   pc: 0x0000000105103e98 cpsr: 0x00001000
   far: 0x0000000104df8000  esr: 0x56000080  Address size fault

Binary Images:
       0x1050b8000 -        0x105117fff dyld (*) <38ee9fe9-b66d-3066-8c5c-6ddf0d6944c6> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=976K resident=0K(0%) swapped_out_or_unallocated=976K(100%)
Writable regions: Total=9216K written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=9216K(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
VM_ALLOCATE                         16K        1 
__DATA                              96K        6 
__DATA_CONST                       176K        6 
__LINKEDIT                         480K        6 
__TEXT                             496K        6 
dyld private memory               1024K        1 
===========                     =======  ======= 
TOTAL                             66.2M       28 

Codegen logs with RUST_LOG=debug environment variable

There's no problem with the `flutter_rust_bridge_codegen` command.

To Reproduce

No response

Expected behavior

No response

Generated binding code

No response

OS

MacOs

Version of flutter_rust_bridge_codegen

1.45.0

Flutter info

No response

Version of clang++

No response

Version of ffigen

No response

Additional context

No response

welcome[bot] commented 1 year ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 1 year ago

Library not loaded: '/Users/*/Library/Developer/Xcode/DerivedData/Runner-eixmpjopssepzedozqbaoavjkhar/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/native.build/cargo_target/aarch64-apple-darwin/release/deps/libnative.dylib'

fzyzcjy commented 1 year ago

/cc @Roms1383 IIRC you faced some similar issues when lib cannot be loaded in mac silicon - is this the same?

Roms1383 commented 1 year ago

could be indeed @fzyzcjy, but @kingfisherphuoc you already tried the fix like in this comment I guess ?

kingfisherphuoc commented 1 year ago

@Roms1383 yes, I did try the fix. Previously, I cannot run the project on M1 mac, but after the fix I can run it normally:

// This file initializes the dynamic library and connects it with the stub
// generated by flutter_rust_bridge_codegen.
import 'dart:ffi';
import 'dart:io' as io;
import 'bridge_generated.dart';
// Re-export the bridge so it is only necessary to import this file.
export 'bridge_generated.dart';
const _base = 'native';
// On MacOS, the dynamic library is not bundled with the binary,
// but rather directly **linked** against the binary.
final _dylib = io.Platform.isWindows ? '$_base.dll' : 'lib$_base.so';

final Native api = NativeImpl(((io.Platform.isIOS || io.Platform.isMacOS) && !const bool.fromEnvironment('SILICON', defaultValue: false))
        ? DynamicLibrary.executable() : DynamicLibrary.open(_dylib));

The problem is when I tried to build flutter build macos, the generated built (*.app) run well on my Mac. However, when I sent it to others Macs (both M1 or M2), it did not run at all and I got the crash above.

Roms1383 commented 1 year ago

@kingfisherphuoc well, I must admit I have no clue and I cannot reproduce it since I have a single machine (M1 from last year). Is it blocking for you or acceptable to build it on the target platform each time ? Do you think it'd bring some concern later down the pipeline when it comes to e.g. release your final version ? @fzyzcjy probably knows more than I do on this topic, sorry but this is typically an area where my knowledge falls short (which is also part of the reason I came to contribute to FRB in the first place).

fzyzcjy commented 1 year ago

I also do not have a M2 indeed (mine is Intel CPU). That looks like general flutter and/or rust setup problem though, so maybe people in general flutter/rust know a bit more.

kingfisherphuoc commented 1 year ago

I have another intel Mac (2013). I will try to create another version from it. (it's working well on other targets: IOS, Android, Windows).

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.