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] pure_dart example fails to lookup symbol #772

Closed jwinarske closed 1 year ago

jwinarske commented 1 year ago

Describe the bug

Attempting to run pure_dart example on M1 Mac results in:

% ./main.exe ../../../target/debug//libflutter_rust_bridge_example.dylib
flutter_rust_bridge example program start (dylibPath=../../../target/debug//libflutter_rust_bridge_example.dylib)
construct api
Unhandled exception:
Invalid argument(s): Failed to lookup symbol 'store_dart_post_cobject': dlsym(RTLD_DEFAULT, store_dart_post_cobject): symbol not found
#0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:34)
#1      FlutterRustBridgeExampleSingleBlockTestWire._store_dart_post_cobjectPtr (package:flutter_rust_bridge_example/bridge_generated.io.dart:945)
#2      FlutterRustBridgeExampleSingleBlockTestWire._store_dart_post_cobject (package:flutter_rust_bridge_example/bridge_generated.io.dart)
#3      FlutterRustBridgeExampleSingleBlockTestWire.store_dart_post_cobject (package:flutter_rust_bridge_example/bridge_generated.io.dart)
#4      StoreDartPostCObjectExt.storeDartPostCObject (package:flutter_rust_bridge/src/ffi/io.dart:16)
#5      FlutterRustBridgeBase._setUpRustToDartComm (package:flutter_rust_bridge/src/basic.dart:39)
#6      new FlutterRustBridgeBase (package:flutter_rust_bridge/src/basic.dart:22)
#7      new FlutterRustBridgeExampleSingleBlockTestPlatform (package:flutter_rust_bridge_example/bridge_generated.io.dart:18)
#8      new FlutterRustBridgeExampleSingleBlockTestImpl (package:flutter_rust_bridge_example/bridge_generated.dart:16)
#9      initializeExternalLibrary (package:flutter_rust_bridge_example/ffi.io.dart:8)
#10     main (package:flutter_rust_bridge_example/main.dart:22)
#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295)
#12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192)

The symbol is there, it's just prefixed with _:

% nm -gU ../../../target/debug//libflutter_rust_bridge_example.dylib |grep store_dart_post_cobject
000000000013f1bc T _store_dart_post_cobject

Codegen logs with RUST_LOG=debug environment variable

NA

To Reproduce

No response

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Version of ffigen

No response

Additional context

No response

fzyzcjy commented 1 year ago

Is it the same problem as https://github.com/fzyzcjy/flutter_rust_bridge/issues/754?

jwinarske commented 1 year ago

different

jwinarske commented 1 year ago

I'm not trying to run codegen here. Just using as-is.

fzyzcjy commented 1 year ago

All right. Could you please try the debug suggestions there?

Btw, cc @Roms1383 - here is another case of M1 mac + store_dart_post_cobject error

jwinarske commented 1 year ago

My bad. It is a duplicate of #754, so closing.

This does address the problem:

If I replace :

DynamicLibrary.executable() with DynamicLibrary.open(path) (like in non-IOS/MacOS) in frb_example/pure_dart/dart/lib/ffi.io.dart it works.

So it looks like that version of ffigen is not detecting the platform correctly. Perhaps a roll of ffigen will address it.

buf1024 commented 1 year ago

change file ffi.io.dart to should be solved problem:

return FlutterRustBridgeExampleSingleBlockTestImpl(
    !(Platform.isMacOS || Platform.isIOS) ? DynamicLibrary.executable() : DynamicLibrary.open(path),
  );

it seems the origin logic is incorrect.

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.