Github actions for Rust

Hi guys , so I have written a cdylib in Rust and i want to cross compile it so i can give the dll file to my windows friend to test it out so i was thinking of using github actions . Is it possible to setup rust.yml file for github repo to it builds the lib for platforms i want and Recive the final compiled files?

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

That sounds life saving man , ill test it out and update you with results

it worked , thanks man

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.