Поддержка MUSL для полностью статических c двоичных файлов :
По умолчанию Rust статически связывает весь код Rust. Однако, если вы используете стандартную библиотеку, она будет динамически связываться с системной реализацией lib c.
Если вы хотите получить бинарный файл 100% stati c, MUSL lib c может быть используется в Linux:
rustup target add x86_64-unknown-linux-musl
RUSTFLAGS='-C link-arg=-s' cargo build --release --target x86_64-unknown-linux-musl
main.rs
файл:
use actix_web::{web, App, HttpServer, Responder};
async fn index(info: web::Path<(String, u32)>) -> impl Responder {
format!("Hello {}! id:{}", info.0, info.1)
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(web::resource("/{name}/{id}/index.html").to(index)))
.bind("127.0.0.1:8080")?
.run()
.await
}
Cargo.toml
файл:
[profile.release]
opt-level = 's' # Optimize for size.
lto = true # Link Time Optimization (LTO)
# codegen-units = 1 # Set this to 1 to allow for maximum size reduction optimizations:
# panic = 'abort' # removes the need for this extra unwinding code.
[dependencies]
actix-web = "2.0.0" # Actix web is a simple, pragmatic and extremely fast web framework for Rust.
actix-rt = "1.0.0" # Actix runtime
Rust Поддержка платформы