Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kubos_cargo.zsh
get_cpu_count() {
python -c 'import multiprocessing as mp; print(mp.cpu_count())'
}
CPU_COUNT=$(get_cpu_count)
kubos_cargo() {
# NOTE: this assumes we're building something that's a subdir of $HOME/Code
typeset -a o_target
o_projects=(--project "$PWD")
zparseopts -D -K -- p+:=o_projects -project+:=o_projects -target:=o_target
typeset -a o_env
if [[ "$o_target[2]" != "" ]]; then
# strip the leading '='
target=${o_target[2]#=}
CC=$(docker run --rm -it kubos/kubos-linux-dev cat /root/.cargo/config | \
remarshal -if toml -of json | jq ".target[\"$target\"].linker" -r)
o_env=(-e CC=$CC -e PKG_CONFIG_ALLOW_CROSS=1)
fi
projects=("${(@)o_projects:#-p}")
projects=("${(@)projects:#--project}")
for project in "$projects[@]"; do
echo -n "[$fg[white]in $reset_color$fg_bold[green]$project$reset_color$reset_color]: "
echo "cargo $@ ${(@)o_target}"
echo docker run --cpus $CPU_COUNT --rm -it -v "$HOME/Code:$HOME/Code" \
-v "$HOME/.cargo/registry:/root/.cargo/registry" \
-w "$project" ${(@)o_env} kubos/kubos-linux-dev cargo $@ ${(@)o_target}
docker run --cpus $CPU_COUNT --rm -it -v "$HOME/Code:$HOME/Code" \
-v "$HOME/.cargo/registry:/root/.cargo/registry" \
-w "$project" ${(@)o_env} kubos/kubos-linux-dev cargo $@ ${(@)o_target}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment