Link C library with Rust project

Author: MarcAntoine-ArnaudCreated Sep 23, 2020Updated Jul 23, 2026
Labelsbug

Describe the Bug

I have a part of the project in C, so I use emscripten to compile it (the complex Makefile is already present, that's why I don't want to use cc). With emscripten I generate a lib.a file.

On a second time I have a Rust project to integrate the process. For that I have defined the C API to call FFI from Rust and in the build.rs I add the link to the lib.a.

Using wasm-pack build everything is builded - not tested yet in web environnement. But in my case I need to target the Web Worker, so I try to compile with wasm-pack build --no-module which provides me that error:

error: cannot import from modules (`env`) with `--no-modules`

Does I missed something ? Is it linked to a configuration on Emscripten side ? Does I need to use Wasm in Wasm ? So generate a first wasm with Emscripten, then include bytes in the Rust code ?

Additional Context

Emscripten is used on Ubuntu (docker), Rust on Mac OSX.

Source: wasm-bindgen/wasm-bindgen