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
60 changes: 49 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,64 @@ 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

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

- name: Verify toolchain
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
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'

tools:
runs-on: ubuntu-latest

- name: Setup Rust
uses: ./setup
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Install
run: cargo build
- uses: ./setup
with:
tools: |
cargo-nextest@0.9.140
cargo-llvm-cov@0.8.7
wasm-bindgen-cli@0.2.126

- name: Verify Cargo tools
run: |
cargo nextest --version
cargo llvm-cov --version
wasm-bindgen --version
shell: bash
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, tools, and caching |
23 changes: 20 additions & 3 deletions setup/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# setup-rust
An action to setup a rust compiler and enable caching.
# setup

Configure a Rust toolchain, optional targets and Cargo tools, and caching.

## Usage

```yaml
- name: Setup Rust
uses: actions-ext/rust/setup-rust@c9cdbe5cc8a2485bf2eb22644302559c741ca763
uses: actions-ext/rust/setup@7d919b14e08dc1155a267dffbcc58260bdfdd63b
with:
targets: wasm32-unknown-unknown
tools: |
cargo-nextest@0.9.140
cargo-llvm-cov@0.8.7
```

Cargo tools require `crate@version` entries and are installed with an exact version requirement.

## Inputs

| Name | Default | Description |
| :----------- | :--------------- | :------------------------------------------------------- |
| `toolchain` | `stable` | Rust toolchain to install. |
| `components` | `clippy,rustfmt` | Comma-separated rustup components. |
| `targets` | Empty | Comma-separated Rust targets. |
| `tools` | Empty | Newline-separated Cargo tools in `crate@version` format. |
| `cache_key` | `rust` | Additional Rust cache key. |
75 changes: 44 additions & 31 deletions setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
name: Setup Rust
description: 'Ensure Rust compiler and utilities are available, and setup caching'
description: 'Configure a Rust toolchain, targets, Cargo tools, 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: ''
tools:
description: 'Newline-separated Cargo tools in crate@version format'
default: ''
cache_key:
description: 'Additional Rust cache key'
default: 'rust'

runs:
using: 'composite'
steps:
- name: Set up Rust
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # 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,7 +39,7 @@ runs:
- name: Setup Rust cache
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
key: ${{ runner.os }}-${{ inputs.kind }}
key: ${{ inputs.cache_key }}-${{ inputs.toolchain }}-${{ inputs.targets }}
cache-targets: true
cache-all-crates: true
cache-bin: true
Expand All @@ -39,24 +48,28 @@ runs:
.cargo
.rustup

- run: |
rustup target add aarch64-unknown-linux-gnu
rustup target add x86_64-unknown-linux-gnu
- name: Install Cargo tools
env:
CARGO_TOOLS: ${{ inputs.tools }}
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' }}
run: |
while IFS= read -r specification; do
specification="${specification%$'\r'}"
[ -z "$specification" ] && continue
case "$specification" in
*@*)
crate="${specification%@*}"
version="${specification##*@}"
;;
*)
echo "Cargo tool must use crate@version format: $specification" >&2
exit 1
;;
esac
if [ -z "$crate" ] || [ -z "$version" ]; then
echo "Cargo tool must use crate@version format: $specification" >&2
exit 1
fi
cargo install --locked "$crate" --version "=$version"
done <<< "$CARGO_TOOLS"
if: ${{ inputs.tools != '' }}
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