emscripten基于llvm的webassembly 编译器

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
)

同时目前官方也提供了支持基于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

posted on   荣锋亮  阅读(106)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-10-30 asyncapi event-gateway
2022-10-30 使用haproxy 代理minio
2021-10-30 dremio rbac 功能简单说明一
2021-10-30 dremio 19.0 几个扩展包说明
2021-10-30 dremio 实现类似官方create user sql 处理的思路
2021-10-30 dremio 19.0 创建用户bug说明
2019-10-30 使用viper 进行golang 应用的配置管理

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示