演示地址:https://emscripten-demo.oyzhen.me
要点:
- JS与C++交互的相关细节
- 对emscripten编译生成的js做二次封装以符合JS的使用习惯
- 动态加载wasm模块。
# Get the emsdk repo
git clone https://github.com/juj/emsdk.git
# Enter that directory
cd emsdk
# Fetch the latest version of the emsdk (not needed the first time you clone)
git pull
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file)
./emsdk activate latest
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
# on Windows, run `emsdk` instead of `./emsdk`, and `emsdk_env.bat` instead of `source ./emsdk_env.sh`.
更多细节: 访问emscripten官方文档
npm install
C/C++
需要配置.vscode/c_cpp_properties.json,以便VSCode语法高亮和智能提示
npm run build-wasm
编译后的.wasm文件及其js加载器存放在wasm目录下。
npm run build-asm
npm run build
更多编译细节:访问emscripten官方文档
npm start
然后在浏览器打开链接:http://127.0.0.1:3333,页面加载成功后打开浏览器控制台,尽情玩耍!