Emscripten
LLVMを使ったC/C++をJS/WebAssemblyに変換するtoolchain
-sでemccにcompile optionを渡す
一覧はsrc/settings.jsから見れる
https://emscripten.org/docs/api_reference/advanced-apis.html#settings-js
https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
https://emsettings.surma.technology/
htmlで見れるようにしたもの
typescript
--emit-tsdd.tsを出力できる https://emscripten.org/docs/tools_reference/emcc.html#emcc-emit-tsd
要tsc
もう少し詳しい型定義もある
https://www.npmjs.com/package/@types/emscripten
--pre-jsで提供するJSで使えるobjectsの型定義
Moduleで使用するpropsはINCOMING_MODULE_JS_APIで指定できる
https://emscripten.org/docs/api_reference/module.html#id2
その他、globalで使えるものはsrc/preamble.jsで設定される
https://emscripten.org/docs/api_reference/preamble.js.html
_malloc,_freeは以前はdefaultで含めていたが、今はEXPORTED_FUNCTIONSに含めないと削られてしまう
code reading
src/*.m?jsがglue code生成時に挿入される
#IFDEFなどのC preprocessorが直打ちされており、compile optionによって生成されるコードが変わる
https://github.com/emscripten-core/emscripten/blob/main/src/compiler.mjs でJS glue codeを生成している?
clang+wasm-ldでstandalone wasmを作る
https://dev.classmethod.jp/articles/wasi-sdk-wasm-browser/
wasi
WebAssembly Standalone
wasm-ldの概説
https://lld.llvm.org/WebAssembly.html
https://depth-first.com/articles/2019/10/16/compiling-c-to-webassembly-and-running-it-without-emscripten/
libclang_rt.builtins-wasm32.aが見つからないエラーの話がある
https://dassur.ma/things/c-to-webassembly/
llvmの中間言語を介す
かなり原理的な話が解説されている
https://00f.net/2019/04/07/compiling-to-webassembly-with-llvm-and-clang/
libclang_rt.builtins-wasm32.aが見つからないエラーの話がある
https://danielmangum.com/posts/wasm-wasi-clang-17/
clang 17正式にsupport
wasm-ldを使わなくてもwasmを作れるようになった?
JavaScript Promise Integration APIを使う
https://emscripten.org/docs/porting/asyncify.html
-sJSPI=1で有効化
-sJSPI_EXPORTSで非同期化するwasmの函数を指定
-sJSPI_IMPORTSでwasmにわたすJSの非同期函数を指定
CMakeとEmscriptenでbuildする
#2024-08-17 10:42:35
#2024-08-16 21:23:23
#2024-08-09 08:37:54