首页 > 其他分享 >wasm-pack 基于rust 的 WebAssembly 开发工具

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

时间:2023-10-22 09:44:19浏览次数:44  
标签:WebAssembly github wasm https rust pack

目前基于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

标签:WebAssembly,github,wasm,https,rust,pack
From: https://www.cnblogs.com/rongfengliang/p/17779932.html

相关文章

  • esp32笔记[8]-rust的定时器中断点灯
    摘要使用rust开发esp32c3实现定时器中断点亮led灯.超链接esp32笔记[7]-使用rust+zig开发入门平台信息esp32c3rustMutex锁usecore::cell::RefCell;usecritical_section::Mutex;//no-std库专用的Mutex我们首先注意到的是静态变量BUTTON。我们需要它,因为在中断处理程......
  • Rust,linker but `link.exe` was not found
    themsvctargetsdependonthemsvclinkerbut`link.exe`wasnotfound这是提示未安装vsstudioc++组件,由于vsstudio组件较大,可以选择安装gnu的,具体如下:命令行执行下边指令rustuptoolchaininstallstable-x86_64-pc-windows-gnurustupdefaultstable-x86_64-pc-wind......
  • rust笔记-变量
    rust变量默认是不可变的,需要手动设置可变性。可变的变量给编程提供了灵活性,不可变的变量提供了安全性。而rust中需要根据实际场景来指定的变量类型。变量声明变量声明使用关键字let,语法格式如下:let变量名=值;变量声明后,变量名可以被使用,但是值不能被修改。这种方式申请的......
  • rustdesk 1.2.3-1 尝鲜,有很大提升空间
    产品说的很好。测试了一下电脑从archlinuxcn下的rustdesk1.2.3-1,手机端fdroid下的,版本是1.1.10-1,同一局域网,未自建服务器。电脑端启动后显示账号和一次性密码。手机输入账号密码后连接,手机画面黑屏,过一回依旧黑屏不显示,再一会断联。手机可选显示哪个桌面(一共两)。密码刷新后......
  • Rust: function
    /***file:nested.rs***////公有函数pubfnfunction(){println!("called`my::nested::function()`");}///私有函数#[allow(dead_code)]fnprivate_function(){println!("called`my::nested::private_function()`");}/......
  • 10_rust的结构体struct
    rust的struct定义和实例化struct使用struct关键字,并对整个struct命名。在花括号内,对所有字段(Field)定义名称和类型。创建struct实例:为每个字段指定具体值,无需按声明顺序进行指定。structUser{name:String,id:u64,is_act:bool,}fnmain(){letu1=......
  • python报错解决-ValueError: Trusted host URL must include a host part: '#!
    删掉#后面的字符参考:pipinstall总是报错:ValueError:TrustedhostURLmustincludeahostpart:‘#‘-CSDN博客......
  • Codeforces Round #870 (Div. 2) A. Trust Nobody
    题解#include<cstdio>#include<vector>#include<queue>#include<cstring>#include<algorithm>#include<iostream>#include<stack>#include<bitset>#include<cstdlib>#include<cmath>#include......
  • 从内存使用角度的比较:Go vs Rust
    Go和Rust是最近几年非常火的语言,经常有人问到底该怎么选择,特别是谁更适合搭建网络后台服务,哪一个性能更好,稳定性更高。网络上Go和Rust的比较文章很多,大体上是做一个测试或写几段测试代码,根据运行的时长来比较哪个性能更好,但这种测试可能会陷入误区:1)比来比去,比的是网络IO,因为这种......
  • rust防锁屏
    usersautogui::mouse;usestd::thread::sleep;usestd::time::Duration;fnmain(){lettimeseconds=Duration::from_secs(5);letmutx:u16;lety:u16=1080;letmuti=1;loop{ifi==1{x=300;i......