#!/usr/bin/env sh
#
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# curl https://sh.rustup.rs -sSf | sh
# curl -sSLf "https://static.rust-lang.org/rust-key.gpg.ascii" -o rust-key.gpg.ascii
# gpg --import /tmp/rust-key.gpg.ascii
# 108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE

# get the dir of the current script
sdir=$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd) && cd "${sdir}" || return 1

mkdir -p ~/.local/share/cargo
# ln -snf "$sdir/config.toml"  ~/.cargo/config.toml
# ln -snf "$sdir/rustfmt.toml" ~/.rustfmt.toml

# has_program() {
#   command -v ${1:?Need program name} >/dev/null 2>&1
# }

# if ! has_program rustup; then
#   curl https://sh.rustup.rs -sSf | sh /dev/stdin -y
#   # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y
# fi

if command -v rustup >/dev/null 2>&1; then
  rustup update
else
  # curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
  # curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
      # --profile default -c \
      # clippy \
      # rust-src \
      # rust-std \
      # rustfmt \
      # --default-toolchain nightly || exit 1
fi
# components = ["rustfmt", "rust-src", "clippy"]

mkdir -p ~/.config/zsh/.zfunc
rustup completions zsh       > ~/.config/zsh/.zfunc/_rustup
rustup completions zsh cargo > ~/.config/zsh/.zfunc/_cargo

# cargo install --locked cargo-update # for checking/applying updates to installed executables
# cargo install --locked cargo-expand
# cargo install --locked cargo-udeps
# cargo install --locked watchexec-cli

cargo install cargo-update
cargo install cargo-cache
cargo install cargo-binstall

# cargo install --locked cargo-edit
# cargo install --locked cargo-play
# cargo install --locked cargo-expand
# cargo install --locked cargo-udeps
# cargo install --locked cargo-make
# cargo install --locked cargo-nextest

# perf binary size
# cargo install --locked cargo-bloat
# cargo install --locked cargo-unused-features

# cargo install --locked flamegraph
# command -v perf >/dev/null 2>&1 || {
#   echo "You may need to install the following dependencies on arch:"
#   echo "linux-tools-meta"
# }
