Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,42 @@ concurrency:
cancel-in-progress: true

permissions:
checks: write
pull-requests: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
targets: wasm32-unknown-unknown
- os: macos-latest
targets: aarch64-apple-darwin,wasm32-unknown-unknown
- os: windows-latest
targets: wasm32-unknown-unknown

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Prework
run: |
printf '[package]\nname = "rust"\nversion = "0.1.0"\nedition = "2021"\n[dependencies]\n' > Cargo.toml
mkdir -p src
printf 'fn main() {\n println!("Hello, world!");\n}\n' > src/main.rs

- name: Setup Rust
uses: ./setup
- uses: ./setup
with:
targets: ${{ matrix.targets }}

- name: Install
run: cargo build
- name: Verify toolchain
run: |
rustup component list --installed | grep '^clippy-'
rustup component list --installed | grep '^rustfmt-'
rustup target list --installed | grep '^wasm32-unknown-unknown$'
cargo build --manifest-path tests/Cargo.toml
cargo build --manifest-path tests/Cargo.toml --target wasm32-unknown-unknown
shell: bash

- name: Verify macOS target
run: rustup target list --installed | grep '^aarch64-apple-darwin$'
shell: bash
if: runner.os == 'macOS'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
AGENTS.md
ROADMAP.md
/tests/target/
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# node
# rust

Helper actions for Node projects
Helper actions for Rust projects

| Name | Action Reference | Description |
| :--------------- | :----------------------- | :----------------------------------------------------- |
| [setup](./setup) | `actions-ext/rust/setup` | An action to setup a rust compiler and enable caching. |
| Name | Action Reference | Description |
| :--------------- | :----------------------- | :----------------------------------------------- |
| [setup](./setup) | `actions-ext/rust/setup` | Configure a Rust toolchain, targets, and caching |
18 changes: 15 additions & 3 deletions setup/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# setup-rust
An action to setup a rust compiler and enable caching.
# setup

Configure a Rust toolchain, optional targets and components, and caching.

## Usage

```yaml
- name: Setup Rust
uses: actions-ext/rust/setup-rust@c9cdbe5cc8a2485bf2eb22644302559c741ca763
uses: actions-ext/rust/setup@3b918cc2cb4a231ad3752f8cc129da5f07626ce2
with:
targets: wasm32-unknown-unknown
```

Only the host target is installed by default. Use `targets` for additional architectures or WASM. Install Cargo tools in your project's development setup.

## Inputs

| Name | Default | Description |
| :----------- | :--------------- | :--------------------------------- |
| `toolchain` | `stable` | Rust toolchain to install. |
| `components` | `clippy,rustfmt` | Comma-separated rustup components. |
| `targets` | Empty | Comma-separated Rust targets. |
47 changes: 14 additions & 33 deletions setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
name: Setup Rust
description: 'Ensure Rust compiler and utilities are available, and setup caching'
description: 'Configure a Rust toolchain, targets, components, and caching'

inputs:
kind:
type: choice
description: "Whether to install just a default target, or all targets (e.g. for during deployments / wheel building)"
default: "full"
options:
- full
- wasm
toolchain:
description: 'Rust toolchain to install'
default: 'stable'
components:
description: 'Comma-separated rustup components to install'
default: 'clippy,rustfmt'
targets:
description: 'Comma-separated Rust targets to install'
default: ''

runs:
using: 'composite'
steps:
- name: Set up Rust
uses: dtolnay/rust-toolchain@02cb101ec7c40f2c49e1d9714d64511d8e1b74de # latest
with:
toolchain: stable
components: clippy, rustfmt
toolchain: ${{ inputs.toolchain }}
components: ${{ inputs.components }}
targets: ${{ inputs.targets }}

- name: Configure Cargo cache paths
run: |
Expand All @@ -30,33 +33,11 @@ runs:
- name: Setup Rust cache
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
key: ${{ runner.os }}-${{ inputs.kind }}
key: ${{ inputs.toolchain }}-${{ inputs.targets }}
cache-targets: true
cache-all-crates: true
cache-bin: true
cache-on-failure: true
cache-directories: |
.cargo
.rustup

- run: |
rustup target add aarch64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-gnu
shell: bash
if: ${{ inputs.kind == 'full' && runner.os == 'Linux' }}

- run: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
shell: bash
if: ${{ inputs.kind == 'full' && runner.os == 'macOS' }}

- run: |
rustup target add x86_64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
shell: bash
if: ${{ inputs.kind == 'full' && runner.os == 'Windows' }}

- run: rustup target add wasm32-unknown-unknown
shell: bash
if: ${{ inputs.kind == 'wasm' }}
7 changes: 7 additions & 0 deletions tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "rust-action-test"
version = "0.1.0"
edition = "2021"

[lib]
path = "src/lib.rs"
13 changes: 13 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn adds_numbers() {
assert_eq!(add(2, 2), 4);
}
}
Loading