C/C++ が含まれる Rust プロジェクトを WebAssembly にビルドする
WIP
前提
C/C++ が含まれる Rust プロジェクトでは cc クレートを使って cargo build の際に clang へのオプションを指定することが出来る。また Rust から C/C++ のコードを呼ぶために FFI を用意する必要があり、bindgen クレートを使ってヘッダーファイルから自動生成することが出来る。 clang で WebAssembly をビルドする場合は v8 以降の clang を用意する必要がある。Homebrew を使う場合は単に brew install llvm でパスを通せば clang-8 を使うことが出来る。 sysroot の問題
WebAssembly はサンドボックスで実行されることが望まれるため、C の標準ライブラリをダイナミックリンクすることが出来ない。
一方でブラウザでの実行を想定している場合は sysroot が存在しない。もしかしたら Emscripten が改造している musl を使うことでなんとかコンパイル出来るかもしれない(要調査)。 ただしヘッダというかライブラリが無い。Emscriptenのを使うか、WASI SDKのようなプロジェクトが成熟するのを待った方が良いだろう。 cc でも特にブラウザ用の WebAssembly の sysroot を用意していない。
Ideally we would support this! The target, however, doesn't really have a C compiler because there's no real standard "sysroot" (currently) to actually compile C code against. The recently released clang 8.0 compiler though is the only one we'd also be compatible with on wasm32-unknown-unknown, so we could at least add that and rely on users to set the right CFLAGS to compile with the right headers/sysroot/etc