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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy