Skip to content

Instantly share code, notes, and snippets.

@lmammino
Last active May 7, 2019 16:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmammino/8077e68d2be0a4cc06827a16015b92c5 to your computer and use it in GitHub Desktop.
Save lmammino/8077e68d2be0a4cc06827a16015b92c5 to your computer and use it in GitHub Desktop.
Compile and run rust programs

Allows to compile and run a Rust program under unix systems:

./rrun <rust_file_name> <runtime_arguments>

For instance:

./rrun args 1 2 3 4 5

(the .rs extension is optional)

#!/usr/bin/env bash
mkdir -p "/tmp/rrun"
FILENAME=$1
if [[ "$FILENAME" == *.rs ]]
then
SOURCE="${FILENAME}"
else
SOURCE="${FILENAME}.rs"
fi
HASH=$(md5 -q $SOURCE)
DEST="/tmp/rrun/${FILENAME}_${HASH}"
shift
rustc "${SOURCE}" -o "${DEST}" && ${DEST} $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment