我想用自定义版本的musl构建静态Rust可执行文件。作为第一步,我正熟悉Rust的构建系统。
我采用了稍微过时的docker-rust-musl
GitHub项目和更新过时的网址。一切似乎都适用于构建,但是当我想用x86_64-unknown-linux-musl
进行编译时,编译器找不到musl std
crate:
root@beb234fba4af:/build# cat example.rs
fn main() { println!("hi!"); panic!("failed"); }
root@beb234fba4af:/build# rustc --target=x86_64-unknown-linux-musl example.rs
error[E0463]: can't find crate for `std`
|
= note: the `x86_64-unknown-linux-musl` target may not be installed
error: aborting due to previous error
实际上,/usr/local/lib/rustlib/
只包含x86_64-unknown-linux-gnu
目录,即使构建期间的输出表明构建了x86_64-unknown-linux-musl
:
[...]
Building stage2 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-musl)
[...]
但是,在安装步骤中x86_64-unknown-linux-gnu
无处可见:
[...]
Install std stage2 (x86_64-unknown-linux-gnu)
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rust-std-x86_64-unknown-linux-gnu'
std is standing at the ready.
Install rustc stage2 (x86_64-unknown-linux-gnu)
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rustc'
Rust is ready to roll.
Build completed in 0:31:07
安装x86_64-unknown-linux-musl
Rust标准库需要做些什么?
进度:
挖掘构建环境显示make all
使用std
构建Rust musl
库,但后续的make install
步骤不会安装它。
我们在前面提到的docker镜像的build.sh
脚本中有一个temporary fix。
目前还不清楚这是构建环境还是其使用的问题。
Rust开发人员的问题是known。但是,没有修复。