124 lines
3.1 KiB
Bash
124 lines
3.1 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
echo "Initializing development environment..."
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Rust directories
|
|
# -----------------------------------------------------------------------------
|
|
|
|
mkdir -p /opt/rustup /opt/cargo
|
|
chown "$(id -u):$(id -g)" /opt/rustup /opt/cargo
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Fish configuration
|
|
# -----------------------------------------------------------------------------
|
|
|
|
mkdir -p /etc/fish/conf.d
|
|
mkdir -p /etc/fish/completions
|
|
|
|
tee /etc/fish/conf.d/rust.fish >/dev/null <<'EOF'
|
|
set -gx RUSTUP_HOME /opt/rustup
|
|
set -gx CARGO_HOME /opt/cargo
|
|
fish_add_path $CARGO_HOME/bin
|
|
EOF
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Rustup
|
|
# -----------------------------------------------------------------------------
|
|
|
|
export RUSTUP_HOME=/opt/rustup
|
|
export CARGO_HOME=/opt/cargo
|
|
|
|
echo "Installing rustup..."
|
|
|
|
curl \
|
|
--proto '=https' \
|
|
--tlsv1.2 \
|
|
-sSf \
|
|
https://sh.rustup.rs \
|
|
| sh -s -- -y --no-modify-path
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Rust toolchain
|
|
# -----------------------------------------------------------------------------
|
|
|
|
echo "Installing stable Rust toolchain..."
|
|
|
|
/opt/cargo/bin/rustup default stable
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Fish completions
|
|
# -----------------------------------------------------------------------------
|
|
|
|
echo "Installing rustup Fish completion..."
|
|
|
|
/opt/cargo/bin/rustup completions fish \
|
|
| tee /etc/fish/completions/rustup.fish >/dev/null
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Export Rust development tools to the host
|
|
# -----------------------------------------------------------------------------
|
|
export PATH="/opt/cargo/bin:$PATH"
|
|
echo "Exporting development tools..."
|
|
|
|
DEV_HOME="$HOME"
|
|
DEV_USER="$(basename "$DEV_HOME")"
|
|
|
|
export_bin() {
|
|
local binary="$1"
|
|
|
|
if command -v "$binary" >/dev/null 2>&1; then
|
|
echo " exporting $binary"
|
|
sudo -u "$DEV_USER" \
|
|
env HOME="$DEV_HOME" \
|
|
distrobox-export \
|
|
--bin "$(command -v "$binary")" \
|
|
--export-path "$DEV_HOME/.local/bin"
|
|
else
|
|
echo " warning: $binary not found"
|
|
fi
|
|
}
|
|
|
|
# Rust
|
|
for binary in \
|
|
cargo \
|
|
cargo-clippy \
|
|
cargo-fmt \
|
|
cargo-miri \
|
|
clippy-driver \
|
|
rls \
|
|
rust-analyzer \
|
|
rustc \
|
|
rustdoc \
|
|
rustfmt \
|
|
rust-gdb \
|
|
rust-gdbgui \
|
|
rust-lldb \
|
|
rustup
|
|
do
|
|
export_bin "$binary"
|
|
done
|
|
|
|
# Native toolchain
|
|
export_bin clang
|
|
export_bin clang++
|
|
export_bin cmake
|
|
export_bin lld
|
|
export_bin ld.lld
|
|
export_bin gdb
|
|
export_bin strace
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Done
|
|
# -----------------------------------------------------------------------------
|
|
|
|
echo
|
|
echo "Development environment initialized successfully."
|
|
echo
|
|
echo "Rust:"
|
|
/opt/cargo/bin/rustc --version
|
|
/opt/cargo/bin/cargo --version
|
|
/opt/cargo/bin/rustup --version
|