Skip to content

Unable to run wasm module built from Rust with C++ dependency. Error: Can't resolve 'env' #741

@JanKaul

Description

@JanKaul

🐛 Bug description

npm run start fails when running a wasm module that was built from Rust with C++ dependency using wasm-pack. Inspecting the generated wasm module shows that it tries to import (import "env" "double_it" (func $double_it (type $t5))) from a module "env" that it doesn't know ("double_it" is the function in the C++ dependency). The C++ dependency is actually a C file which has been renamed to have a ".cpp" ending. npm run start works with the ".c" file. So maybe the ".cpp" ending triggers different compilation flags that yield the different result. Since both C and C++ compile to wasm I thought there should be no difference in the usage.

A same problem has been initially encountered also for the ".c" file in the comment: #621 (comment). The problem was potentially resolved with a newer clang or Rust update.

Project available here: https://github.com/JanKaul/simple-wasm

🤔 Expected Behavior

npm run start should succeed.

👟 Steps to reproduce

  1. C++ dependency build with cc crate, which determines compiler automatically (I guess clang)
  2. wasm-pack build succeeds
  3. npm install succeeds
  4. npm run strart fails with following error:
ERROR in ../pkg/simple_wasm_bg.wasm
Module not found: Error: Can't resolve 'env' in '/home/user/workspace/rust/simple-wasm/pkg'
 @ ../pkg/simple_wasm_bg.wasm
 @ ../pkg/simple_wasm.js
 @ ./index.js
 @ ./bootstrap.js
ℹ 「wdm」: Failed to compile.

🌍 Your environment

wasm-pack 0.8.1
rustc 1.39.0 (4560ea788 2019-11-04)

clang version 9.0.0-2 (tags/RELEASE_900/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions