环境搭建
- git clone https://github.com/emscripten-core/emsdk.git
- git pull
- ./emsdk install latest
- ./emsdk activate latest
- source ./emsdk_env.sh
- ./emcc -v && ./emcc c11__Thread_local.c -s WASM_WORKERS --threadprofiler --memoryprofiler -v -o test.html && node a.out.js
- emrun --no_browser --port 8087 .
- emrun FILENAME.html
- docker run --rm -v $(pwd):/src -u ( i d − u ) : (id -u): (id−u):(id -g)
emscripten/emsdk emcc helloworld.cpp -o helloworld.js
emcmake
- call emsdk_env.bat
- ::TIMEOUT /T 0.5
- cmd /c buildApp.bat
- ::TIMEOUT /T 3
- cd -wasm
- mkdir wasm
- cd wasm
- cmd /c emcmake cmake -DWASM=ON -DPRODUCTMODE=OFF -DSRC_MAP_DEBUG_MODE=%1 -DDEBUG_SRC_SITE=%2 …
- ::TIMEOUT /T 3
- ::emmake make clean
- ::for /l %%a in (1,1,4) do ( emmake make -j32)
- emmake make -j32
- pause
- cmd /c call build_wasm.bat 0 “http://localhost:999/”
- http-server ./wasm -p 999 --cors
- emake报错时需将mingw32-make改成make
面向WebAssembly编程笔记
创建虚拟文件系统,实现fopen打开本地文
预加载本地文件
./emcc test/hello_world_file.cpp -o hello.html –preload-file test/hello_world_file.txt
Emscripten Test Suite
def test_cmake_px_icu(self):os.mkdir('build')self.run_process([EMCMAKE, 'cmake', test_file('cmake/px_icu')], cwd='build')self.run_process(['cmake', '--build', 'build'])self.assertContained('OK', self.run_js('build/test_prog.js'))
Emscripten 多线程
- 多线程 -s WASM_WORKERS
- 单线程 -s SINGLE_FILE
- lock-free atomic原子不断轮询设置操作,不可中断(其它线程不会读到操作一半的值),解决死锁
- 示例目录:upstream\emscripten\tests\wasm_worker
NetWork
- emscripten_async_wget
- -lwebsocket.js -s WEBSOCKET_URL
- 捕获异常:-fexceptions -fwasm-exceptions
- 定时器:emcc -O3 example.cpp -sASYNCIFY
- 异常位置打印:-fsanitize=undefined ,-fsanitize-minimal-runtime,-fsanitize=address
优化
- emcc -sENVIRONMENT=web,只生成web代码,不生成nodejs代码,减少大小
- toolchain profiler:set EMPROFILE=1,emcc test.c -o test.html,emprofile --graph
https://www.cnblogs.com/chenchao521/articles/15493198.html
编译qt源码
进入源码目录,命令行输入,
./configure.bat -no-warnings-are-errors -xplatform wasm-emscripten -platform win32-g++ -nomake examples -prefix %CD%\qtbase
大概10分钟就可以编译完毕
构建需要的模块
E:/Qt/Qt5.10.1/Tools/mingw530_32/bin/make.exe module-qtbase module-qtdeclarative
如果不需要裁剪,可以直接 E:/Qt/Qt5.10.1/Tools/mingw530_32/bin/make.exe
引用
- 1
- mozilla
- cntofu
源码调试
DWARF
wamr
vs