emscripten基于llvm的webassembly 编译器
  8KhYbgszLLmZ 2023年11月30日 29 0

emscripten是一个基于llvm的webassembly 编译器

包含的特性

  • 可移植
    支持编译现有的c,c++ 以及其他语言项目,使用lvvm 编译为支持nodejs,浏览器,以及wasm运行时运行的服务
  • 提供apis
    支持将openGL 转换为WebGL,pthreads 转换为web api。。。
  • 快速
    集成了不少工具(llvm,emscripten,binaryen),运行速度接近原生

说明

opencv-wasm 就基于了此工具进行opencv 编译为webassembly
参考构建命令

 


git clone --branch 4.3.0 --depth 1 https://github.com/opencv/opencv.git
 
# Build
(
    cd opencv &&
    git checkout 4.3.0 &&
 
    # Add non async flag before compiling in the python build_js.py script
    docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:sdk-tag-1.39.4-64bit" python ./platforms/js/build_js.py build_wasm --build_wasm --build_test --build_flags "-s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s SINGLE_FILE=0 "
)
 
# Copy compilation result
cp -a ./opencv/build_wasm/ ./build_wasm
 
# Transpile opencv.js files
node opencvJsMod.js
 
# Beautify JS
(
    cd ./build_wasm/bin &&
    npx js-beautify opencv.js -r &&
    npx js-beautify opencv-deno.js -r
)
 
# Copy bins to root
(
    cp ./build_wasm/bin/opencv.wasm ../opencv.wasm &&
    cp ./build_wasm/bin/opencv-bin.js ../opencv-bin.js &&
    cp ./build_wasm/bin/opencv.js ../opencv.js &&
    cp ./build_wasm/bin/opencv-deno.js ../opencv-deno.js &&
    cp -r ./build_wasm/ ../build_wasm_test
)

 

# Build

同时目前官方也提供了支持基于docker 构建的镜像,可以方便wasm 的生成

参考资料

https://github.com/emscripten-core/emscripten
https://github.com/emscripten-core/emsdk
https://emscripten.org/
https://github.com/echamudi/opencv-wasm
https://github.com/WebAssembly/binaryen

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月30日 0

暂无评论

推荐阅读
8KhYbgszLLmZ