Is it possible to compile WASM from Rust using C libraries?


#1

I’m attempting to build WASM file from my Rust code which using C library(in particular, a library is sqlite3).

$ cargo build --target wasm32-unknown-emscripten

However, I received an error message from emcc like WARNING:root:emcc: cannot find library "sqlite3"

When I attempt to build code to binary by $ cargo build, rustc can compile it ordinary.
My code looks like below.

// src/main.rs
extern "C" {
    pub fn sqlite3_libversion_number() -> ::std::os::raw::c_int;
}

fn main() {
    println!("Hello with SQLite version {}", unsafe {
        sqlite3_libversion_number()
    });
}

// build.rs
pub fn main() {
  println!("cargo:rustc-link-lib={}", "sqlite3");
  println!(
    "cargo:rustc-link-search={}",
    "/path/to/directory/includes/sqlite3.h"
  );
}

So, my question is, In the first place, is it possible to compile WASM from Rust code which using C libraries?
Moreover if possible, what are things I’m misunderstanding?