Skip to content

Instantly share code, notes, and snippets.

@0b10011
Created November 22, 2019 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0b10011/137a167bdb8ada1ecfdcd8b6aecf0e6d to your computer and use it in GitHub Desktop.
Save 0b10011/137a167bdb8ada1ecfdcd8b6aecf0e6d to your computer and use it in GitHub Desktop.
A dockerized drop-in replacement for `cargo` that supports caching.
#!/bin/bash
# This is a drop-in replacement for `cargo`
# that runs in a Docker container as the current user
# on the latest Rust image
# and saves all generated files to `./cargo/` and `./target/`.
#
# Be sure to make this file executable: `chmod +x ./cargo`
#
# # Examples
#
# - Running app: `./cargo run`
# - Building app: `./cargo build`
# - Building release: `./cargo build --release`
#
# # Installing globally
#
# To run `cargo` from anywhere,
# save this file to `/usr/local/bin`.
# You'll then be able to use `cargo`
# as if you had installed Rust globally.
sudo docker run \
--rm \
--user "$(id -u)":"$(id -g)" \
--mount type=bind,src="$PWD",dst=/usr/src/app \
--workdir /usr/src/app \
--env CARGO_HOME=/usr/src/app/.cargo \
rust:latest \
cargo "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment