#!/bin/bash # Initialize our own variables: WORKSPACE="" BIN="" SKIP_CHECK_FLAG=false SELECTIVE_BUILD_FLAG=false BIN_BUILD_FLAG=false # A function to display a usage message: usage() { echo "Usage: $0 [-w|--workspace ] [-b|--bin ] [--skip-check]" } # Check if no arguments were passed if [ $# -eq 0 ]; then usage exit 1 fi # Parse the command-line arguments: OPTIONS=$(getopt -o w:b:s --long workspace:,bin:,skip-check -- "$@") if [ $? -ne 0 ]; then # getopt has complained about wrong arguments to stdout usage exit 1 fi eval set -- "$OPTIONS" while true; do case "$1" in -w|--workspace) SELECTIVE_BUILD_FLAG=true WORKSPACE="$2" shift 2 ;; -b|--bin) BIN_BUILD_FLAG=true BIN="$2" shift 2 ;; -s|--skip-check) SKIP_CHECK_FLAG=true shift ;; --) shift break ;; *) echo "Internal error!" exit 1 ;; esac done { if ! $SKIP_CHECK_FLAG ; then cargo clippy --workspace --fix --allow-dirty --allow-staged -- -D clippy::panic -W clippy::all && cargo fmt --all else echo "Skipping check..." fi WORKDIR=$(pwd) if $SELECTIVE_BUILD_FLAG ; then if $BIN_BUILD_FLAG ; then cd $WORKSPACE; cargo build --bin $BIN -r --offline else cargo build -p $WORKSPACE -r --offline fi else cargo build --workspace -r --offline fi cd $WORKDIR if [ $? -eq 0 ]; then echo "Release binaries success! ✅" else echo "Release binaries failed! ❌" exit 1 fi # Define the path to the Cargo.toml file CARGO_TOML_PATH="./Cargo.toml" # Define the release directory where binaries are located RELEASE_DIR="./target/release" # Define the destination directory for the binaries DESTINATION_DIR="./bin" # Remove the destination directory if it exists echo "Removing ${DESTINATION_DIR}..." rm -r ${DESTINATION_DIR} # Create the destination directory if it does not exist mkdir -p $DESTINATION_DIR # Extract the binary names from Cargo.toml # Assume [[bin]] sections contain a 'name = "binary_name"' line # BIN_NAMES=$(grep -A 1 "\[\[bin\]\]" $CARGO_TOML_PATH | grep "name =" | cut -d '"' -f2) # fetch all .exe(s) inside target/release/* only, dont recursively BIN_NAMES=$(find "$RELEASE_DIR" -maxdepth 1 -type f -name '*.exe' -printf '%f\n') # Iterate over the binary names and copy them to the destination directory for BIN_NAME in $BIN_NAMES; do # Construct the copy command COPY_COMMAND="cp ${RELEASE_DIR}/${BIN_NAME} ${DESTINATION_DIR}/${BIN_NAME}" # Execute the copy command echo "Copying ${BIN_NAME}..." $COPY_COMMAND done echo "All binaries have been copied." cp $CARGO_TOML_PATH ${DESTINATION_DIR}/ echo "CARGO_TOML_PATH copied." cp .env ${DESTINATION_DIR}/ echo "ENV copied." cp -R ./storage ${DESTINATION_DIR}/ echo "STORAGE copied." }