macOS 上の Rust で Docker を使わずに Linux バイナリをクロスビルド
Docker を使えばできるのは自明なので、使わない方向だとどうなるのか気になった
rustup しただけだと使えない
$ rustup target add x86_64-unknown-linux-musl
システムデフォルトの ld ではなくリンカを入れる必要がある
musl-cross を使う
$ brew install filosottile/musl-cross/musl-cross
これで x86_64-linux-musl-gcc というリンカが入る
.cargo/config にリンカの設定を追記する
code:config
linker = "x86_64-linux-musl-gcc"
ビルドできて楽しい 🦀
参考にしました
Note that rustup target add only installs the Rust standard library for a given target. There are typically other tools necessary to cross-compile, particularly a linker.
リンカは絶対自分で準備しないといけないらしいです
設定の書き方はここを見るのが安心
英語が読めていると思っていても読めていないものなので、母国語だと安心できる