Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when instantiating WASM files built from C/C++ #45

Open
robertesler opened this issue Dec 24, 2020 · 1 comment
Open

Error when instantiating WASM files built from C/C++ #45

robertesler opened this issue Dec 24, 2020 · 1 comment
Labels
❓ question Further information is requested

Comments

@robertesler
Copy link

robertesler commented Dec 24, 2020

Summary

I've had no luck yet running a test wasmer-java project using .wasm files built from C/C++. The included examples with wasmer-java work fine, but anything that I've built either via emscripten or wasienv throws RuntimeExceptions with missing imports:

Additional details

a C program built using wasienv, the .wasm file runs fine when executed:
wasmer run example.wasm -- DataInput

But when testing in wasmer-java I get this error:
Exception in thread "main" java.lang.RuntimeException: Failed to instantiate the module: 9 link errors: (1 of 9) Import not found, namespace: wasi_unstable, name: fd_prestat_get (2 of 9) Import not found, namespace: wasi_unstable, name: fd_prestat_dir_name (3 of 9) Import not found, namespace: wasi_unstable, name: proc_exit (4 of 9) Import not found, namespace: wasi_unstable, name: fd_fdstat_get (5 of 9) Import not found, namespace: wasi_unstable, name: fd_close (6 of 9) Import not found, namespace: wasi_unstable, name: args_sizes_get (7 of 9) Import not found, namespace: wasi_unstable, name: args_get (8 of 9) Import not found, namespace: wasi_unstable, name: fd_seek (9 of 9) Import not found, namespace: wasi_unstable, name: fd_write at org.wasmer.Instance.nativeInstantiate(Native Method) at org.wasmer.Instance.<init>(Instance.java:45) at Example.main(simple.java:18)
Additionally, a C++ project built using emscripten via JS:
em++ hello.cpp fib.cpp -s STANDALONE_WASM -s ALLOW_MEMORY_GROWTH=0 -s EXPORTED_FUNCTIONS="[_new_fib, _next_val]" -Wl, --no-entry -o hello.js || exit 1

Runs fine in the browser with javascript but when tested in wasmer-java I get this error:
Exception in thread "main" java.lang.RuntimeException: Failed to instantiate the module: link error: Import not found, namespace: wasi_snapshot_preview1, name: proc_exit at org.wasmer.Instance.nativeInstantiate(Native Method) at org.wasmer.Instance.<init>(Instance.java:45) at Example.main(simple.java:18)
Is there an import step I'm missing? Or a build sequence I need to follow? I've based the java code on the examples and it breaks at the instantiation point,:
`Path wasmPath = Paths.get(new Example().getClass().getClassLoader().getResource("hello.wasm").getPath())

// Reads the WebAssembly module as bytes.
byte[] wasmBytes = Files.readAllBytes(wasmPath);

    // Instantiates the WebAssembly module.
    Instance instance = new Instance(wasmBytes);`

The wasmer-jni*.jar is in the classpath. I'm running this on Linux Ubuntu. Both emscripten and wasienv are the most recent versions as of this question's posting.

Thanks for any help, I'd love to use WASM and Java if possible.

@robertesler robertesler added the ❓ question Further information is requested label Dec 24, 2020
@robertesler
Copy link
Author

The more I look into this it appears this may be related to an already open issue: #11
I haven't found a way yet to build .wasm files from C/C++ without an import line so this would be a very nice enhancement. Thanks for the work you all have put in to this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant