Skip to content

Instantly share code, notes, and snippets.

@fungos
Last active June 15, 2018 13:43
Show Gist options
  • Save fungos/5c94a2b7ed4a5b7ea4572e54c0c96a34 to your computer and use it in GitHub Desktop.
Save fungos/5c94a2b7ed4a5b7ea4572e54c0c96a34 to your computer and use it in GitHub Desktop.
A quickly hacked together Power Shell script to install and setup a complete Rust Development Environment.
function Download-Redirect-As
{
$uri = $args[0]
$target = $args[1]
Write-Host "Downloading $target..."
$request = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Ignore
if ($request.StatusCode -ge 300 -and $request.StatusCode -lt 400)
{
$uri = $request.Headers.Location
}
Invoke-WebRequest -Uri $uri -OutFile $target
}
Write-Host "Checking for VSCode..."
# Install VSCode if not installed already
$vscode_path = "C:\Program Files\Microsoft VS Code\"
$code_bin = "$($vscode_path)bin\code"
if ((Get-Command $code_bin -ErrorAction SilentlyContinue) -eq $null)
{
$vscode_path = "C:\Program Files (x86)\Microsoft VS Code\"
$code_bin = "$($vscode_path)bin\code"
if ((Get-Command $code_bin -ErrorAction SilentlyContinue) -eq $null)
{
Download-Redirect-As 'https://vscode-update.azurewebsites.net/latest/win32-x64/stable' 'vscode.exe'
Write-Host "Installing VSCode... please wait, this can take a while."
./vscode.exe /VERYSILENT /SILENT | Out-Null
Remove-Item -Path "vscode.exe"
}
}
if ((Get-Command $code_bin -ErrorAction SilentlyContinue) -eq $null)
{
$vscode_path = "C:\Program Files\Microsoft VS Code\"
$code_bin = "$($vscode_path)bin\code"
if ((Get-Command $code_bin -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "Error: could't validate if installation worked, aborting."
exit
}
}
Write-Host VSCode found in: $code_bin
# Install Required VSCode Extensions
Write-Host "Installing required VSCode extensions..."
Start-Process -FilePath $code_bin -ArgumentList "--install-extension rust-lang.rust" -Wait
Start-Process -FilePath $code_bin -ArgumentList "--install-extension ms-vscode.cpptools" -Wait
Start-Process -FilePath $code_bin -ArgumentList "--install-extension webfreak.debug" -Wait
# Install Rustup if not installed already
Write-Host "Checking for Rustup..."
if ((Get-Command "rustup" -ErrorAction SilentlyContinue) -eq $null)
{
Download-Redirect-As 'https://win.rustup.rs/' 'rustup-init.exe'
./rustup-init.exe -y | Out-Null
Remove-Item -Path "rustup-init.exe"
}
# Update Rust
Write-Host "Adding Rust compiler and components..."
& rustup install nightly
& rustup component add rust-src
& rustup component add rust-docs
& rustup component add rust-analysis
& rustup component add rls-preview
& rustup component add rustfmt-preview
& rustup update
Write-Host "Compiling Clippy, this can take some time..."
& rustup run nightly cargo install clippy
& rustup default stable
Write-Host "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment