wasm-pack 基于rust 的 WebAssembly 开发工具

目前基于WebAssembly的应用是越来越多了,同时周边工具以及生成也越来越强大了,wasm-pack 是rust
周边一个很强大的工具,以下是一个简单的试用

参考使用

  • 安装
 
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
  • 创建简单项目
wasm-pack new hello-wasm
  • 代码结构

lib.rs 中包含了基于c 以及原生rust 的方法
一些调整
lib.rs

 
mod utils;
 
use wasm_bindgen::prelude::*;
 
#[wasm_bindgen]
pub fn greet()->String {
    return "dalongdemo".to_string();
}
  • 构建
    会自动下载依赖,会有点慢,会生成一个npm 包
 
wasm-pack build -t nodejs

本地安装npm 包

cd pkg && yarn link
  • 项目集成使用
yarn init -y
yarn link hello-wasm

代码使用

const  {greet}  = require("hello-wasm")
 
let result = greet()
 
console.log(result)
  • 效果

 

参考资料

https://github.com/rustwasm/wasm-pack
https://github.com/appcypher/awesome-wasm-langs
https://github.com/AssemblyScript/assemblyscript

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

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-10-22 dremio 23 版本的试用简单说明
2022-10-22 dremio 21 版本之后反射No File System scheme matches 问题解决
2022-10-22 dremio 23 s3 插件默认ssl 配置问题
2022-10-22 dremio 23 版本docker 镜像jdk 说明
2022-10-22 dremio 23 社区版发布提供了
2022-10-22 dremio 官方 dbt 扩展
2022-10-22 minio gateway nas 参考配置

导航

< 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
点击右上角即可分享
微信分享提示