Release multi-target Rust applications with GitLab CI

Mike Ensor
8 min readFeb 5, 2022

TL;DR

  • Add host targets using rustup target add x86_64-pc-windows-gnu (any Rust Tier 1) to build multiple OS platform binaries. Cargo CLI flags to specify target in cargo <cmd> --target <host-platform> commands.
  • GitLab CI —Create a custom Rust build image to reduce build times and ensure consistency between builds.
  • Use a dedicated stage “release-build” that builds --release host target binaries and pushes them to the Gitlab Project Registry.
  • Use GitLab’s registry.gitlab.com/gitlab-org/release-cli:latestdocker build image to create a Release. Utilize variables as expansion can be tricky. Use a git tag to indicate a full release build
  • Working example project: https://gitlab.com/mike-ensor/gitlab-downloader

Brief Background

I recently decided to dive deep on Rust. Previous attempts have been very superficial, building a few Advent of Code problems, but not really diving into the details and completely avoiding the “rusty” way to build. This led me to build something more substantial and on a few other side projects, I’ve developed a minor gripe about cloning GitLab repos contained within a group. Without any scripting, a new developer needs to clone each repo independently. I figured this…

--

--