Documentation

function handle_debug_install () {
    if [ "$DEBUG" == true ]; then
        echo -e "$CYAN• profile = ${YELLOW}dev$RESET"
        CARGO_ARGS="$CARGO_ARGS --debug"
    else
        echo -e "$CYAN• profile = ${GREEN}release$RESET"
    fi
}

function handle_debug_build () {
    if [ "$DEBUG" == true ]; then
        echo -e "$CYAN• profile = ${YELLOW}dev$RESET"
    else
        echo -e "$CYAN• profile = ${GREEN}release$RESET"
        CARGO_ARGS="$CARGO_ARGS --release"
    fi
}

function handle_pgo () {
    if [ "$PGO" == true ]; then
        echo -e "$CYAN• PGO = ${GREEN}true$RESET"
    else
        echo -e "$CYAN• PGO = ${YELLOW}false$RESET"
    fi
}

function handle_fast_compiler () {
    if [ "$FAST_COMPILER" == true ]; then
        if [ "$DEBUG" != true ]; then
            m 'FAST_COMPILER=true requires DEBUG=true' "$RED"
            exit 1
        fi

        if [ "$NIGHTLY" != true ]; then
            m 'FAST_COMPILER=true requires NIGHTLY=true' "$RED"
            exit 1
        fi

        echo -e "$CYAN• compiler = ${RED}cranelift$RESET"
        export RUSTFLAGS="$RUSTFLAGS -Z codegen-backend=cranelift"
    else
        echo -e "$CYAN• compiler = ${GREEN}default$RESET"
    fi
}

function handle_fast_linker () {
    if [ "$FAST_LINKER" == true ]; then
        if command -v wild > /dev/null 2>&1; then
            LINKER=wild
        elif command -v mold > /dev/null 2>&1; then
            LINKER=mold
        fi

        if [ -n "$LINKER" ]; then
            echo -e "$CYAN• linker = ${RED}$LINKER$RESET"
            export RUSTFLAGS="$RUSTFLAGS --codegen linker=clang --codegen link-arg=--ld-path=$LINKER"
        else
            echo -e "$CYAN• linker = ${GREEN}default$RESET"
        fi
    else
        echo -e "$CYAN• linker = ${GREEN}default$RESET"
    fi
}

function handle_nightly () {
    if [ "$NIGHTLY" == true ]; then
        echo -e "$CYAN• channel = ${RED}nightly$RESET"
        CARGO_CHANNEL=+nightly
        export RUSTFLAGS="$RUSTFLAGS -Z threads=8"
    else
        echo -e "$CYAN• channel = ${GREEN}stable$RESET"
    fi
}