-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrust.sh
More file actions
executable file
·114 lines (94 loc) · 3.08 KB
/
rust.sh
File metadata and controls
executable file
·114 lines (94 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -euo pipefail
install_cargo_crate() {
NAME="$1"
BIN="${2:-$NAME}"
if ! type "$BIN" >/dev/null 2>&1; then
if [ ! -f ~/.cargo/bin/"$BIN" ]; then
echo "Installing cargo crate: $NAME"
cargo install "$NAME"
fi
fi
}
provision_setup_rust() {
cat >>~/.shell_aliases <<"EOF"
RustBuildProvisionPackages() {
mkdir -p ~/.local/bin
while IFS= read -r -d '' FILE_PATH; do
FILE_NAME=$(basename "$FILE_PATH")
if [ ! -f "$FILE_PATH"/Cargo.toml ]; then
continue
fi
if [ ! -f "$HOME/.local/bin/$FILE_NAME" ] || [ "$1" = "-f" ]; then
(cd "$FILE_PATH" &&
echo "" &&
echo "Building: $FILE_NAME" &&
cargo build --release --jobs 1 &&
echo "Copying $FILE_NAME" &&
cp target/release/"$FILE_NAME" "$HOME/.local/bin/" &&
chmod +x "$HOME/.local/bin/$FILE_NAME" &&
rm -rf target)
fi
done < <(find ~/development/environment/src/scripts/misc -maxdepth 1 -mindepth 1 -type d -print0)
}
_RustUpdateProvisionPackages() {
rm -rf ~/.rustup
rustup toolchain install stable
while IFS= read -r -d '' FILE_PATH; do
FILE_NAME=$(basename "$FILE_PATH")
if [ ! -f "$FILE_PATH"/Cargo.toml ]; then
continue
fi
(cd "$FILE_PATH" && \
cargo update && \
cargo build --release)
printf "Updated: $FILE_NAME\n\n"
done < <(find ~/development/environment/src/scripts/misc -maxdepth 1 -mindepth 1 -type d -print0)
echo "Rebuilding all packages..."
RustBuildProvisionPackages -f
echo "Updated all packages, you should commit the changes"
}
EOF
add_vscode_extension "rust-lang.rust-analyzer"
install_nvim_package cespare/vim-toml
install_nvim_package rust-lang/rust.vim
cat >>~/.vimrc <<"EOF"
let g:rustfmt_autosave = 1
let RustPrintMapping="vnoremap <leader>kk yOprintln!(\"a {:?}\", a);<C-c>11hvpgvyf\"lllvp"
autocmd filetype rust :exe RustPrintMapping
EOF
if [ "$IS_NIXOS" != "1" ]; then
cat >>~/.shellrc <<"EOF"
if [ -d "$HOME"/.cargo/env ]; then
. "$HOME/.cargo/env"
fi
export PASTEL_COLOR_MODE=24bit
EOF
fi
if [ -f "$PROVISION_CONFIG"/rust-cross-compile ]; then
if [ ! -f ~/.check-files/rust-cross-compile ] && type "apt-get" >/dev/null 2>&1; then
# TODO: generalize installation for arch linux
sudo apt-get install -y gcc-x86-64-linux-gnu
rustup target add x86_64-unknown-linux-musl
# export CC_x86_64_unknown_linux_musl=x86_64-linux-gnu-gcc
# export RUSTFLAGS='-C linker=x86_64-linux-gnu-gcc'
touch ~/.check-files/rust-cross-compile
fi
fi
if [ -f "$PROVISION_CONFIG"/extra-crates ]; then
install_system_package perf
# https://github.com/flamegraph-rs/flamegraph
install_cargo_crate flamegraph
# https://github.com/RazrFalcon/cargo-bloat
install_cargo_crate cargo-bloat
# https://github.com/TimonPost/cargo-unused-features
install_cargo_crate cargo-unused-features unused-features
# https://github.com/sharkdp/pastel
install_cargo_crate pastel
fi
cat >>~/.shellrc <<"EOF"
if type rustup >/dev/null 2>&1; then
rustup default 2>&1 >/dev/null || rustup default stable
fi
EOF
}