Skip to content

Commit

Permalink
Add rust config
Browse files Browse the repository at this point in the history
  • Loading branch information
e-nomem committed May 18, 2021
1 parent 69dc0bc commit dd7da57
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
4 changes: 3 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ bin_exists() {
. "$source_dir/setup_scripts/setup_gnupg.sh"
. "$source_dir/setup_scripts/setup_ssh.sh"
. "$source_dir/setup_scripts/setup_fish.sh"
. "$source_dir/setup_scripts/setup_rust.sh"

phony stow_all stow_stow stow_gnupg stow_ssh stow_git stow_homebrew stow_fish
phony all stow_all rust_all

## ----- Task Definitions End Here ----- ##

# Go do the things
run_task stow_all
run_task all
56 changes: 56 additions & 0 deletions setup_scripts/setup_rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
# This script has been executed instead of sourced
echo "Please source this file!" >&2
exit 1
fi

install_rustup() {
if ! bin_exists brew; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y < /dev/null
fi
}
task install_rustup

update_rustup() {
rustup self update
}
task update_rustup install_rustup

# This function generates the task to install specific crates
generate_crate_install() {
local channel crate tasks taskName safe_channel
channel="$1"
safe_channel="${channel//[-.]/_}"
shift

tasks=()
for crate in "$@"; do
taskName="crate_${safe_channel}_${crate//-/_}"
tlib_generate_task "$taskName" "update_rust_$safe_channel" <<FUNC
cargo +$channel install $crate
FUNC
tasks+=("$taskName")
done
phony "update_crates_$safe_channel" "${tasks[@]}"
}

# install_rust is a function that actually generates a set of tasks
# to set up a default profile for all the rust channels we want
genrate_install_rust() {
local channel tasks safe_channel
tasks=()
for channel in "$@"; do
safe_channel="${channel//[-.]/_}"
tlib_generate_task "update_rust_$safe_channel" update_rustup <<FUNC
rustup update $channel --no-self-update
FUNC
generate_crate_install "$channel" cargo-audit cargo-edit
phony "rust_$safe_channel" "update_rust_$safe_channel" "update_crates_$safe_channel"
tasks+=("rust_$safe_channel")
done
phony rust_all "${tasks[@]}"
}

genrate_install_rust stable
14 changes: 8 additions & 6 deletions tasklib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ tlib_get_dependency_array_name() {
}

tlib_register_dependency() {
local taskName arrayname array
local taskName arrayname tmp array
taskName="$1"
shift
tlib_assert_task_is_defined "$taskName"

arrayname="$(tlib_get_dependency_array_name "$taskName")[@]"
array=( "${!arrayname}" )
arrayname="$(tlib_get_dependency_array_name "$taskName")"
tmp="$arrayname[@]"
array=( "${!tmp}" )

while [[ "$#" -gt 0 ]]; do
tlib_debug "registering depdency $taskName -> $1"
Expand All @@ -219,11 +220,12 @@ tlib_register_dependency() {
}

tlib_get_dependencies_recursive() {
local taskName task_list arrayname array subtask list dep
local taskName task_list arrayname tmp array subtask list dep
taskName="$1"
task_list=()
arrayname="$(tlib_get_dependency_array_name "$taskName")[@]"
array=( "${!arrayname}" )
arrayname="$(tlib_get_dependency_array_name "$taskName")"
tmp="$arrayname[@]"
array=( "${!tmp}" )

tlib_debug "getting dependencies for task $taskName"

Expand Down

0 comments on commit dd7da57

Please sign in to comment.