File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,16 +23,43 @@ cargo run
2323cargo build --release
2424```
2525
26- ### 或者使用musl静态编译
26+ ### musl 静态编译
2727
28- > 需要在 Linux 环境或 Docker 中进行,macOS 不支持。
28+ 生成的二进制文件不依赖 glibc,可在任何 x86_64 Linux 上运行。
29+
30+ #### Linux 环境
31+
32+ ``` bash
33+ rustup target add x86_64-unknown-linux-musl
34+ cargo build --target x86_64-unknown-linux-musl --release
35+ ```
36+
37+ #### macOS 交叉编译
38+
39+ macOS 需要安装 musl-cross 工具链:
2940
3041``` bash
42+ # 1. 安装 musl-cross
43+ brew install FiloSottile/musl-cross/musl-cross
44+
45+ # 2. 添加 Rust target
3146rustup target add x86_64-unknown-linux-musl
47+
48+ # 3. 配置链接器(项目已包含 .cargo/config.toml)
49+ # 如果没有,创建 .cargo/config.toml 内容如下:
50+ # [target.x86_64-unknown-linux-musl]
51+ # linker = "x86_64-linux-musl-gcc"
52+
53+ # 4. 编译
3254cargo build --target x86_64-unknown-linux-musl --release
3355```
3456
35- ### musl静态编译后的二进制文件
57+ > 注意:确保使用 rustup 安装的 Rust,而非 Homebrew 的 Rust。
58+ > 当前Homebrew 的 Rust 不支持交叉编译 target。
59+ > 如有冲突,临时用 rustup 的 cargo ~ /.cargo/bin/cargo build --release --target x86_64-unknown-linux-musl
60+ > 或者卸载Homebrew 的 Rust ` brew uninstall rust ` 后使用 rustup 版本。
61+
62+ ### musl 静态编译后的二进制文件
3663
3764``` bash
3865target/x86_64-unknown-linux-musl/release/reader-rust
You can’t perform that action at this time.
0 commit comments