Skip to content

Instantly share code, notes, and snippets.

@dmgolembiowski
Last active December 5, 2024 17:32
Show Gist options
  • Save dmgolembiowski/f9d907898a2c5c2161df3bd1be5f7cbd to your computer and use it in GitHub Desktop.
Save dmgolembiowski/f9d907898a2c5c2161df3bd1be5f7cbd to your computer and use it in GitHub Desktop.
For first-time cargo release builds that one prefers to have symlinked rather than copied
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# SYMLINK_DIR=
if [ "$( env | grep -Ec "^SYMLINK_DIR=" )" -ne 1 ]; then
echo "SYMLINK_DIR is not set"
echo "Defaulting to $SCRIPT_DIR"
SYMLINK_DIR=$SCRIPT_DIR
else
SYMLINK_DIR=$( env | grep -E "^SYMLINK_DIR=" | cut -d "=" -f 2 )
fi
$SCRIPT_DIR/cargo build --workspace --release
CARGO_EXIT_CODE=$?
if [ $CARGO_EXIT_CODE -ne 0 ]; then
exit $CARGO_EXIT_CODE
fi
for file in target/release/*; do
if [[ -x "$file" && ! -d "$file" ]]; then
echo "ln -s $PWD/$file $SYMLINK_DIR/$(basename $file)"
fi
done
@dmgolembiowski
Copy link
Author

To use, copy this script to your cargo bin directory and ensure it is executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment