Allwinner D1 Rust 测试: web , gpio demo
-
感谢 RVBoards 提供的环境
登录看看基本信息
测试程序路径: /home/rvbtest/liangdi-test
rust 版本
web demo:
web 框架选择了目前 Web Framework Benchmarks rust 排名第一的 ntexuse ntex::web::{self, middleware, App, HttpRequest}; async fn index(req: HttpRequest) -> &'static str { println!("REQ: {:?}", req); "Hello world!\n" } #[ntex::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); web::server(|| { App::new() // enable logger .wrap(middleware::Logger::default()) .service(( web::resource("/index.html").to(|| async { "Hello RVBoards!\n" }), web::resource("/").to(index), )) }) .bind("127.0.0.1:8080")? .run() .await }
运行结果:
curl 访问:
gpio demo:extern crate gpio_cdev; use gpio_cdev::*; fn main() { let chip_iterator = match chips() { Ok(chips) => chips, Err(e) => { println!("Failed to get chip iterator: {:?}", e); return; } }; for chip in chip_iterator { let chip = match chip { Ok(chip) => chip, Err(err) => panic!("Failed to open the chip: {:?}", err) }; println!( "GPIO chip: {}, \"{}\", \"{}\", {} GPIO Lines", chip.path().to_string_lossy(), chip.name(), chip.label(), chip.num_lines() ); for line in chip.lines() { match line.info() { Ok(info) => { let mut flags = vec![]; if info.is_kernel() { flags.push("kernel"); } if info.direction() == LineDirection::Out { flags.push("output"); } if info.is_active_low() { flags.push("active-low"); } if info.is_open_drain() { flags.push("open-drain"); } if info.is_open_source() { flags.push("open-source"); } let usage = if flags.is_empty() { format!("[{}]", flags.join(" ")) } else { "".to_owned() }; println!( "\tline {lineno:>3}: {name} {consumer} {usage}", lineno = info.line().offset(), name = info.name().unwrap_or("unused"), consumer = info.consumer().unwrap_or("unused"), usage = usage, ); } Err(e) => println!("\tError getting line info: {:?}", e), } } println!(); } }
遇到了两个问题:
- 依赖的 nix 包编译错误
gpio-cdev 这个库, 依赖 nix 0.4 , 这个依赖版本, 在我本地 Linux 5.11.12 编译运行没有问题, 在测试环境, 编译有问题, nix github 上面的 supported platforms 中也没提到 rv 的支持, 我手动将 gpio-cdev 的 nix 依赖改为 0.20 后, 正常编译 demo 运行. - 程序运行权限错误
可能的问题: https://github.com/golemparts/rppal/issues/15 , 如果王哥可以试着配置一下权限,可以再运行试试
cd /home/rvbtest/liangdi-test/gpio-demo cargo run
小结:
- rust 对 rv 的支持已经很不错 , web 和 gpio demo 依赖了不少核心的底层库, 目前编译运行也没有遇到大的问题.
- 性能,没有严格的对比,目前这块板子编译 rust 程序有点慢, 编译时 cpu 基本 99%, 内存占用 50% 左右
- 依赖的 nix 包编译错误
-
厉害了
-
收到,感谢测评。rust :)