dart-archive/wasm

Failed to load dynamic library

mit-mit opened this issue · 3 comments

Repro steps:

  1. Clone this repo, and run dart run wasm:setup to complete setup
  2. Create a new Dart app: cd ~/tmp; dart create wasmtest
  3. Add wasm to the pubspec (as a git dep)
  4. Add a small wasm app (like square.cc from readme) and compile to Wasm
  5. Replace bin/wasmtest.dart with:
import 'dart:io';
import 'package:wasm/wasm.dart';

void main() {
  final data = File('square.wasm').readAsBytesSync();
  final mod = WasmModule(data);
  print(mod.describe());
  final inst = mod.builder().build();
  final square = inst.lookupFunction('square');
  print(square(12));
}
  1. Try to run: dart run

=>

mit-macbookpro4:wasmtest mit$ dart run
Unhandled exception:
Invalid argument(s): Failed to load dynamic library '/Users/mit/tmp/wasmtest/.dart_tool/wasm/libwasmer.dylib': dlopen(/Users/mit/tmp/wasmtest/.dart_tool/wasm/libwasmer.dylib, 1): image not found
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
#2      new WasmRuntime._init (package:wasm/src/runtime.g.dart:118:47)
#3      runtime (package:wasm/src/runtime.dart:20:29)
#4      runtime (package:wasm/src/runtime.dart)
#5      new WasmModule (package:wasm/src/module.dart:21:14)
#6      main (file:///Users/mit/tmp/wasmtest/bin/wasmtest.dart:6:15)
#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Oh, I see the issue. You need to run dart run wasm:setup from inside the wasmtest directory. Users will have to do this whenever they add wasm as a dep to a new project.

Specifically, in the readme steps, just after the user runs dart pub get, they'll need to run dart run wasm:setup.

You also don't have to clone this repo locally if you're just trying to use it. The git dep is sufficient.

Also, when I was running through the readme steps on my windows machine, I had to put quotes around the linker flags:
clang --target=wasm32 -nostdlib "-Wl,--export-all" "-Wl,--no-entry" -o square.wasm square.cc

Got it. I updated https://github.com/dart-lang/wasm/pull/31/files. Please review.

Instead of complaining image not found, Dart could provide the suggestion "Did you forget to call dart run wasm:setup?" That way, it would help people.