Cargo 静态编译

git clone --recursive https://github.com/kornelski/pngquant.git

vi ~/.cargo/config.toml


[http]
debug = true
proxy = "127.0.0.1:1080"

1.apt 更新

2.apt install cargo

3.修改源码的Cargo.toml

[source.crates-io]
#registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

apt install musl-tools

apt-get install musl-dev

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static

 export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

wget https://cdn.jsdelivr.net/gh/rust-lang-nursery/rustup.rs/rustup-init.sh

sh rustup-init.sh

export PATH="$HOME/.cargo/bin:$PATH"

rustup target add x86_64-unknown-linux-musl

静态编译设置  源码目录/.cargo/config

[target.'cfg(target_os = "linux")']
rustflags = ["-C", "target-feature=+crt-static"]

[target.'cfg(target_os = "windows")']
rustflags = ["-C", "target-feature=+crt-static"]

gcc编译

cargo build --release --target x86_64-unknown-linux-gnu

独立编译

cargo build --release --target x86_64-unknown-linux-musl

你可能感兴趣的:(linux,运维,服务器)