Github actions for Rust

Yes, and you don't need any third-party actions either. GitHub Actions runners already have rustup installed, so you can ensure you have an up-to-date Rust just with that. actions/upload-artifact lets you make the file downloadable.

name: Build

permissions: {}

on:
  pull_request:
  push:
    branches:
      - main

env:
  # Disable incremental compilation for faster from-scratch builds
  CARGO_INCREMENTAL: 0

jobs:
  build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v4
    - run: rustup update
    - run: cargo build --release
    - uses: actions/upload-artifact@v4
      with:
        path: target/release/mylibrary.dll

My favorite additional action to use is GitHub - Swatinem/rust-cache: A GitHub Action that implements smart caching for rust/cargo projects for caching dependencies so builds can be faster, but you probably don't need that unless you have a lot of dependencies.

7 Likes