woshidama323 / LearnRust

2 stars 0 forks source link

LearnRust #4

Open woshidama323 opened 2 years ago

woshidama323 commented 2 years ago

rust笔记

### 1. 能否toml中依赖private repo
https://medium.com/@c_ameron/rust-how-to-build-a-docker-image-with-private-cargo-dependencies-ab91c25c4301
woshidama323 commented 2 years ago

cargo run [options] [-- args] Run a binary or example of the local package.

All the arguments following the two dashes (--) are passed to the binary to run. If you're passing arguments to both Cargo and the binary, the ones after -- go to the binary, the ones before go to Cargo. --bin name Run the specified binary.

--example name Run the specified example.

来源: https://doc.rust-lang.org/cargo/commands/cargo-run.html

rust-gdb --args target/debug/benchy merkleproofs --size 2

对应cargo的运行方法 https://github.com/filecoin-project/rust-fil-proofs

cargo run --release --bin benchy -- merkleproofs --size 2

1. 命令行

https://docs.rs/clap/latest/clap/

vec

You can explicitly create a Vec with Vec::new:

let v: Vec = Vec::new(); Run …or by using the vec! macro:

https_proxy=192.168.20.9:1089 cargo deps -d 4 | dot -Tpng > graph.png 绘制调用关系

woshidama323 commented 2 years ago

Neptune is a Rust implementation of the Poseidon hash function tuned for Filecoin.

https://www.poseidon-hash.info/

Poseidon: ZK-friendly Hashing https://eprint.iacr.org/2019/458.pdf Yoshiki

https://crates.io/crates/bellperson/0.18.2

bellperson是 bellman的fork版本 在此基础上增加了gpu等并行计算优化

arity 是树的自由度

woshidama323 commented 2 years ago

迁移一个repo 到一个新的地方

git clone --bare {repo}
cd {project}.git
git push --mirror {new-repo}

## 样例
https_proxy=192.168.20.9:1089 git clone --bare https://github.com/jeek2018/rust-fil-proofs.git

[参考资料] https://gist.github.com/niksumeiko/8972566

woshidama323 commented 2 years ago
admindeMac-mini:filecoin-ffi admin$ cat  rust/.cargo/config
[net]
git-fetch-with-cli = true
woshidama323 commented 2 years ago

### 如果从remote端git 下来依赖包,那么cargo 中不会自动追踪 最新的commit的信息 主要原因是cargo.lock 中已经锁定了主要的依赖版本,需要update 一下才能更新
https_proxy=192.168.20.9:1089 cargo update

[参考资料] https://github.com/rust-lang/cargo/issues/8555

woshidama323 commented 2 years ago

rust 从git repo中获取到的代码放在这里

$HOME/.cargo/git/checkouts

场景,本地测试,开发过程中临时修改代码

https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html

不想push到repo中 可以这么干

[package]
name = "my-library"
version = "0.1.0"

[dependencies]
uuid = "1.0"

[patch.crates-io]
uuid = { path = "../path/to/uuid" }

但是需要注意上面的这个只是针对 需要替换的package 是从crate.io来的时候,可以这样用


 [patch."https://github.com/woshidama323/bellperson"]
bellperson = { version = "0.18.0",path = "/home/fsw/.cargo/git/checkouts/rust-gpu-tools-0b366f849ae22563/ec52b6b/" }

### 如果是从github等其他来源的话,需要这样

注意: patch目前不支持 workspace 成员中的Cargo.toml 替换,需要放在根的位置

woshidama323 commented 2 years ago

cargo test

## 为能够用gdb的方法调试rust 需要找到unittest 对应的可执行程序

target/debug/dep/crate_name_....

## 有时候只想编译test 但是不运行,有时候运行时间比较长
cargo test --no-run
woshidama323 commented 2 years ago

rust 关于静态编译的问题

遇到一个问题就是,cargo.toml文件中依赖的包 如果是git的方式应用的,比如rust-fil-proofs 中引用的hwloc 就是这个场景,

直接从crates.io 下来的包要本地必须安装hwloc 但是git下来的确不要

目前能够确定的是与git 有直接关系 只是rust 层是如何编译处理的,这个问题需要做个小实验来验证
woshidama323 commented 2 years ago

cargo build from git

export CARGO_NET_GIT_FETCH_WITH_CLI=true

woshidama323 commented 2 years ago

rust wasm 没有找到工具链的解决方法


rustup default stable
rustup update
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

来源

woshidama323 commented 1 year ago

rust 对于嵌入式系统的支持

https://docs.rust-embedded.org/book/

woshidama323 commented 1 year ago

solc 转化成rust 代码用于合约调用 https://github.com/gakonst/ethers-rs

https://crates.io/crates/ethers-solc

rust 相关eth应用

flashbot 中间件 https://github.com/onbjerg/ethers-flashbots flashbot文档 https://docs.flashbots.net/flashbots-auction/overview