1. circleci/rust@1.6.2

circleci/rust@1.6.2

Certified
Sections
Easily test, build, run and validate your Rust applications on CircleCI!
Created: January 13, 2021Version Published: December 30, 2024Releases: 10
Org Usage:
69

Orb Quick Start Guide

Use CircleCI version 2.1 at the top of your .circleci/config.yml file.

1 version: 2.1

Add the orbs stanza below your version, invoking the orb:

1 2 orbs: rust: circleci/rust@1.6.2

Use rust elements in your existing workflows and jobs.

Usage Examples

lint_test_build_for_release

Check linting with Clippy, run any present tests then build the crate.

1 2 3 4 5 6 7 8 version: '2.1' orbs: rust: circleci/rust@x.y.z workflows: production: jobs: - rust/lint-test-build: release: true

Jobs

lint-test-build

Check linting with Clippy, run any present tests then build the crate.

Show job Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
clippy_arguments
Arguments to pass to cargo run clippy.
No
''
string
release
Whether to build the binary for release or debug.
No
false
boolean
version
Version of Rust executor to utilize.
No
1.49.0
string
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

Commands

build

Build a Rust crate.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
crate
Directory of the create to build.
No
''
string
release
Whether to build the binary for release or debug.
No
false
boolean
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

cargo-run

Run a cargo package.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
package
Package to run.
No
''
string
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

clippy

Run Clippy against your codebase. Learn more: https://github.com/rust-lang/rust-clippy.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
flags
Additional flags to pass along to Clippy.
No
'--all --all-targets'
string
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

format

Validate formatting of Rust project.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
nightly-toolchain
Whether or not to use the nightly toolchain version.
No
false
boolean
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

install

Install Rustup, Cargo and Rust. Note: it is best practice to leverage a Docker image with Rust preinstalled for reproducibility and speed.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
version
Version of Rust to install and default to.
No
stable
string

test

Test a cargo crate or package.

Show command Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
cache_version
Cache version to use - increment this to build a fresh cache.
No
v1
string
package
Package to test.
No
''
string
with_cache
Whether to restore and save the cache or not - set to no if running multiple commands in one job.
No
true
boolean
working_directory
Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root.
No
~/project
string

Executors

default

Default Rust executor.

Show executor Source
PARAMETER
DESCRIPTION
REQUIRED
DEFAULT
TYPE
tag
Tag of the Rust image to use.
No
1.49.0
string

Orb Source

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 # This code is licensed from CircleCI to the user under the MIT license. # See here for details: https://circleci.com/developer/orbs/licensing version: 2.1 description: | Easily test, build, run and validate your Rust applications on CircleCI! display: home_url: https://www.rust-lang.org source_url: https://github.com/CircleCI-Public/rust-orb commands: build: description: | Build a Rust crate. parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string crate: default: "" description: Directory of the create to build. type: string release: default: false description: Whether to build the binary for release or debug. type: boolean with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} - run: command: | #!/usr/bin/env bash if [ "$ORB_VAL_RELEASE" = 1 ]; then set -- "$@" --release fi cargo build "$@" environment: ORB_VAL_CRATE_DIR: <<parameters.crate>> ORB_VAL_RELEASE: <<parameters.release>> name: Cargo Build <<parameters.crate>> working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} paths: - ~/.cargo cargo-run: description: | Run a cargo package. parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string package: default: "" description: Package to run. type: string with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} - run: command: cargo run <<parameters.package>> name: Cargo Run <<parameters.package>> working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} paths: - ~/.cargo clippy: description: | Run Clippy against your codebase. Learn more: https://github.com/rust-lang/rust-clippy. parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string flags: default: --all --all-targets description: Additional flags to pass along to Clippy. type: string with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} - run: command: rustup component add clippy name: Install Clippy - run: command: cargo clippy <<parameters.flags>> name: Run Clippy working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} paths: - ~/.cargo format: description: | Validate formatting of Rust project. parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string nightly-toolchain: default: false description: Whether or not to use the nightly toolchain version. type: boolean with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} - run: command: | #!/usr/bin/env bash rustup_args=() cargo_args=() if [ "$ORB_VAL_NIGHTLY_TOOLCHAIN" = "true" ]; then rustup_args+=(--toolchain nightly) cargo_args+=(+nightly) fi rustup component add rustfmt "${rustup_args[@]}" cargo "${cargo_args[@]}" fmt -- --check environment: ORB_VAL_NIGHTLY_TOOLCHAIN: <<parameters.nightly-toolchain>> name: Install and Run fmt working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} paths: - ~/.cargo install: description: | Install Rustup, Cargo and Rust. Note: it is best practice to leverage a Docker image with Rust preinstalled for reproducibility and speed. parameters: version: default: stable description: Version of Rust to install and default to. type: string steps: - run: command: | #!/usr/bin/env bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ -y --default-toolchain "$RUST_VERSION" # shellcheck source=/dev/null source "$HOME"/.cargo/env environment: RUST_VERSION: <<parameters.version>> name: Install Rustup - run: command: echo 'source $HOME/.cargo/env' >> $BASH_ENV name: Setting up Cargo environment in $BASH_ENV test: description: | Test a cargo crate or package. parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string package: default: "" description: Package to test. type: string with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} - run: command: cargo test <<parameters.package>> name: Cargo Test <<parameters.package>> working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "<<parameters.working_directory>>/Cargo.lock" }} paths: - ~/.cargo executors: default: description: | Default Rust executor. docker: - image: cimg/rust:<<parameters.tag>> parameters: tag: default: 1.49.0 description: Tag of the Rust image to use. type: string jobs: lint-test-build: description: | Check linting with Clippy, run any present tests then build the crate. executor: name: default tag: << parameters.version >> parameters: cache_version: default: v1 description: Cache version to use - increment this to build a fresh cache. type: string clippy_arguments: default: "" description: Arguments to pass to cargo run clippy. type: string release: default: false description: Whether to build the binary for release or debug. type: boolean version: default: 1.49.0 description: Version of Rust executor to utilize. type: string with_cache: default: true description: Whether to restore and save the cache or not - set to no if running multiple commands in one job. type: boolean working_directory: default: ~/project description: Path to the directory containing your Cargo.lock file. Not needed if Cargo.lock lives in the root. type: string steps: - checkout: path: /home/circleci/project - when: condition: <<parameters.with_cache>> steps: - restore_cache: keys: - cargo-<<parameters.cache_version>>-{{ checksum "Cargo.lock" }} - clippy: flags: <<parameters.clippy_arguments>> with_cache: false working_directory: <<parameters.working_directory>> - test: with_cache: false working_directory: <<parameters.working_directory>> - build: release: <<parameters.release>> with_cache: false working_directory: <<parameters.working_directory>> - when: condition: <<parameters.with_cache>> steps: - save_cache: key: cargo-<<parameters.cache_version>>-{{ checksum "Cargo.lock" }} paths: - ~/.cargo working_directory: <<parameters.working_directory>> examples: lint_test_build_for_release: description: Check linting with Clippy, run any present tests then build the crate. usage: version: "2.1" orbs: rust: circleci/rust@x.y.z workflows: production: jobs: - rust/lint-test-build: release: true
Developer Updates
Get tips to optimize your builds
Or join our research panel and give feedback
By submitting this form, you are agreeing to ourTerms of UseandPrivacy Policy.