交叉编译

主要是懒...

background

日常环境:

  neofetch
                    'c.          zoomq@ZQ160626rMBP
                 ,xNMM.          ------------------
               .OMMMMo           OS: macOS Big Sur 10.16 22D68 arm64
               OMMM0,            Host: MacBookPro18,4
     .;loddo:' loolloddol;.      Kernel: 22.3.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 5 days, 5 hours, 39 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 330 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: bash 5.1.16
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 2048x1280, 3200x1800
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Spectacle
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    Terminal: iTerm2
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal Font: FiraCode-Regular 18 (normal) / SarasaMonoSCNerd-regular 18 (non-ascii)
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   CPU: Apple M1 Max
    kMMMMMMMMMMMMMMMMMMMMMMd     GPU: Apple M1 Max
     ;KMMMMMMMWXXWMMMMMMMk.      Memory: 11065MiB / 65536MiB
       .cooc,.    .,coo:.

虽然有 linux 的 home server, 不过, 一个小工具,能在本地编译出来发布二进制执行文件多好?

goal

从本地同时可以 cargo build 出来两个主要场景的成品:

  • macOS arm64
  • Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-175-generic x86_64) 类似 LTS 目标环境

trace

没办法简单的成功, 还是用真机或是对应专用编译 Docker 来完成吧...

abrew

arm 版本 brew

$ abrew install FiloSottile/musl-cross/musl-cross

引发一系列手工安装:

  • abrew install --build-from-source gnu-sed
  • abrew install --build-from-source lzip
  • abrew install --build-from-source make
  • ...

...
==> /opt/homebrew/opt/make/bin/gmake install TARGET=x86_64-linux-musl
🍺  /opt/homebrew/Cellar/musl-cross/0.9.9_1: 1,851 files, 215.8MB, built in 5 minutes 35 seconds
==> Running `brew cleanup musl-cross`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

对应 Cargo.toml 中追加:

...
[target.x86_64-unknown-linux-musl]
linker = "/opt/homebrew/Cellar/musl-cross/0.9.9_1/bin/x86_64-linux-musl-gcc"

尝试编译:

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

然后:

...
Some errors have detailed explanations: E0405, E0408, E0412, E0416, E0425, E0433, E0463, E0531.
error: could not compile `regex-syntax` due to 990 previous errors

折腾出 900+ 错误...败退...

GitHub-action

能免费用起来的, 先用起来...

..TBD

refer.

关键参考

Cross-compilation in Rust

logging

版本记要

  • ..
  • 230226 ZQ init.
          _~∽|-~_
      \) /  ◷ O  \ \/
        '_   ⎕   _'
        \ '--.--' <

...act by ferris-actor v0.2.4 (built on 23.0303.201916)

知识共享许可协议 本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可;-)