0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wasm32-unknown-emscriptenとbindgenでつまづいた

Posted at

C/C++ライブラリをRustプロジェクトでビルド&bindgenしつつwasm32-unknown-emscripten targetでビルドする際につまづいたのでメモ。

C/C++ライブラリは*-sys crateとして分離、build.rsでC/C++をビルドしつつbindgenも動かす構成。
C/C++のビルドはccを使いライブラリのMakefileなどを参考にファイルとオプションを設定すればよい。

macOSビルドや、Windowsビルドは手元で成功し、LinuxビルドもCI上で成功している状態からスタート。

つまづき1

bindgenが memory.h を見つけられないという。 memory.h 以外の可能性もある。

fatal error: 'memory.h' file not found

emscriptenでは独自のヘッダーを持っているのでそれをインクルードさせる必要がある。build.rs内でbindgenの .clang_arg("-I/emscripten/.../include") などを利用してもいいが、これをやると他targetのビルドがやりづらくなる。
ここでの正解は BINDGEN_EXTRA_CLANG_ARGS=--sysroot=/emscripten/.../sysroot など sysroot をemscriptenのものにすること。

つまづき2

emscriptenのbindgenが関数を出力しないことがあった。これは可視性の設定が影響している。
こちらは、他targetのビルドに影響しないためbuild.rsのbindgenに .clang_arg("-fvisibility=default") することで解決した。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?