2025-02-06 14:30:38 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Installs the default toolchains and components for different platforms.
|
|
|
|
# To use this script rustup must be installed first.
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
cd "$SCRIPT_DIR/.."
|
|
|
|
|
|
|
|
source scripts/utils/log
|
|
|
|
|
|
|
|
ANDROID_TARGETS="x86_64-linux-android i686-linux-android aarch64-linux-android armv7-linux-androideabi"
|
|
|
|
ANDROID_COMPONENTS="rust-analyzer"
|
|
|
|
|
|
|
|
IOS_TARGETS="aarch64-apple-ios-sim aarch64-apple-ios x86_64-apple-ios"
|
|
|
|
IOS_COMPONENTS="rust-analyzer"
|
|
|
|
|
2025-04-29 10:56:54 +02:00
|
|
|
WINDOWS_TARGETS="x86_64-pc-windows-msvc x86_64-pc-windows-gnu i686-pc-windows-msvc"
|
|
|
|
WINDOWS_COMPONENTS="rust-analyzer"
|
|
|
|
|
|
|
|
LINUX_TARGETS="aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu"
|
|
|
|
LINUX_COMPONENTS="rust-analyzer"
|
|
|
|
|
|
|
|
MACOS_TARGETS="aarch64-apple-darwin x86_64-apple-darwin"
|
|
|
|
MACOS_COMPONENTS="rust-analyzer"
|
|
|
|
|
2025-02-06 14:30:38 +01:00
|
|
|
function main {
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
2025-04-29 10:56:54 +02:00
|
|
|
# A previous version of this script didn't have individual options for the desktop platforms but
|
|
|
|
# had only a single `desktop` option which we keep here for backwards compatibility.
|
|
|
|
# Should be removed at a later point.
|
|
|
|
"windows" | "desktop")
|
|
|
|
setup "Windows" "$WINDOWS_TARGETS" "$WINDOWS_COMPONENTS"
|
|
|
|
;;
|
|
|
|
"linux")
|
|
|
|
setup "Linux" "$LINUX_TARGETS" "$LINUX_COMPONENTS"
|
|
|
|
;;
|
|
|
|
"macos")
|
|
|
|
setup "macOS" "$MACOS_TARGETS" "$MACOS_COMPONENTS"
|
|
|
|
;;
|
2025-02-06 14:30:38 +01:00
|
|
|
"android")
|
|
|
|
setup "Android" "$ANDROID_TARGETS" "$ANDROID_COMPONENTS"
|
|
|
|
;;
|
|
|
|
"ios")
|
2025-04-29 10:56:54 +02:00
|
|
|
setup "iOS" "$IOS_TARGETS" "$IOS_COMPONENTS"
|
2025-02-06 14:30:38 +01:00
|
|
|
;;
|
|
|
|
"install-hook")
|
|
|
|
install_hook
|
|
|
|
;;
|
|
|
|
"--help")
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
log_error "Invalid argument: \`$1\`"
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_usage {
|
|
|
|
log "Setup default Rust targets and components for different platforms"
|
|
|
|
log ""
|
2025-04-29 10:56:54 +02:00
|
|
|
log "Usage: setup-rust android|ios|windows|linux|macos|install-hook"
|
2025-02-06 14:30:38 +01:00
|
|
|
log " android Run Android-specific setup"
|
|
|
|
log " ios Run iOS-specific setup"
|
2025-04-29 10:56:54 +02:00
|
|
|
log " windows Run Windows-specific setup"
|
|
|
|
log " linux Run Linux-specific setup"
|
|
|
|
log " macos Run macOS-specific setup"
|
2025-02-06 14:30:38 +01:00
|
|
|
log " install-hook Copies the setup-rust-post-checkout file to .git/hooks/post-checkout"
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup {
|
|
|
|
local platform=$1
|
|
|
|
local targets=$2
|
|
|
|
local components=$3
|
|
|
|
|
|
|
|
log "Installing default Rust targets/components"
|
|
|
|
log "platform: $platform"
|
|
|
|
log "targets: $targets"
|
|
|
|
log "components: $components"
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
rustup target add $targets
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
rustup component add $components
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_hook {
|
|
|
|
local hook=$SCRIPT_DIR/../.git/hooks/post-checkout
|
|
|
|
if [[ -f "$hook" ]]; then
|
|
|
|
log_error "$(realpath "$hook") file already exists - will not overwrite"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
cp "$SCRIPT_DIR/setup-rust-post-checkout" "$hook"
|
|
|
|
chmod +x "$hook"
|
2025-04-29 10:56:54 +02:00
|
|
|
log "Hook installed. You must now set the environment variable MULLVAD_SETUP_PLATFORM to one of the following:"
|
|
|
|
log "\`android\`, \`ios\`, \`windows\`, \`linux\`, \`macos\`"
|
2025-02-06 14:30:38 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run script
|
|
|
|
main "$@"
|