Building Rust for Multiple Platforms Using Github Actions

Rust and Windows

Rust and Linux With musl

  • Compatibility — not all Linux distros has GNU
  • Performance — while this is still arguable about which is faster, musl is definitely more lightweight
  • Static linking — this is probably the most important aspect of producing a fully portable and static Rust binary. Right now you can only do that with musl

Github Actions and musl

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: x86_64-unknown-linux-musl
default: true
Internal error occurred: Failed to find tool. Is `musl-gcc` installed?
Huh?
- name: Rust w/musl
uses: ./.github/actions/rust-musl-builder
env:
BUILD_TARGET: x86_64-unknown-linux-musl
with:
args: ./build-default.sh

Github Actions Matrix Strategy

  • OS: Windows, Linux (GNU), macOS
  • Node: various ABIs (12.x, 13.x, electron) via neon
build_musl:
steps:
.. your musl-specific job ..

build_rest:
strategy:
matrix:
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
.. use the regular Rust Github Action here ..

Keep Your CI Code Cross Platform

  • Composing paths to find and package your binaries
  • Scripts that extract the current version with a regex and a newline-handling regex (hint: it might not match)
  • You’re not in a real shell in Windows. When in doubt be minimal and use either a well behaving (in terms of cross platform) language such as Node.js or Python to do what you’d otherwise do in a shell. Make one of those your main CI driver

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dotan Nahum

Dotan Nahum

2.9K Followers

@jondot | Founder & CEO @ Spectral. Rust + FP + Hacking + Cracking + OSS. Previously CTO @ HiredScore, Como, Conduit.