Last active
May 1, 2020 15:08
-
-
Save chertov/c7cfa30073e7fd6ee9c256e10184cc8c to your computer and use it in GitHub Desktop.
Simple rust example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# установить таргет | |
# rustup target add armv5te-unknown-linux-musleabi | |
# brew install llvm | |
export LLVM_CONFIG_PATH=/usr/local/Cellar/llvm/10.0.0_3/bin/llvm-config | |
# собираем проект | |
cargo build --release --target=armv5te-unknown-linux-musleabi | |
# сжимаем если нужно | |
# upx --best ./target/armv5te-unknown-linux-musleabi/release/hello_world | |
# загружаю на камеру в /sdcard | |
scp -oUserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ./target/armv5te-unknown-linux-musleabi/release/hello_world [email protected]:/sdcard | |
# так можно зайти на камеру | |
# ssh -oUserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "hello_world" | |
version = "0.1.0" | |
edition = "2018" | |
[[bin]] | |
name = "hello_world" | |
path = "./main.rs" | |
[dependencies] | |
futures = "0.3" | |
tokio = { version = "0.2.20", features = ["full", "io-driver"] } | |
# оптимизации можно все настроить или убрать | |
[profile.release] | |
lto = true | |
codegen-units=1 | |
opt-level="z" | |
debug = false | |
rpath = false | |
debug-assertions = false | |
panic = 'unwind' | |
incremental = false | |
overflow-checks = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !!!!! положить в .cargo/config | |
[build] | |
target = "armv5te-unknown-linux-musleabi" | |
[target.armv5te-unknown-linux-musleabi] | |
linker = "/usr/local/Cellar/llvm/10.0.0_3/bin/lld" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// совсем простой | |
// fn main() { | |
// println!("Hello, world!"); | |
// } | |
// пример с асинхронным async/await | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
println!("Hello, world!"); | |
// печатаем рагументы командной строки | |
let args: Vec<String> = std::env::args().collect(); | |
println!("{:?}", args); | |
// тикаем в консоль 5 раз | |
let mut k = 0; | |
loop { | |
if k == 5 { break; } | |
println!("tick {}", k); | |
tokio::time::delay_for(std::time::Duration::from_millis(300)).await; | |
k+=1; | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment