Created
September 24, 2015 17:40
-
-
Save angelsl/3b8addb951d458ff271d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[String]$Edition = "msvc", | |
[String]$Destination = "C:\Tools\RustNMSVC", | |
[String[]]$Components = @("rustc", "cargo"), | |
[String]$7z = "C:\Program Files\7-Zip\7z.exe", | |
[String]$DownloadUrl = "https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-{0}.tar.gz" | |
) | |
function DownloadFile ($url) { | |
$temp = Temp | |
(New-Object System.Net.WebClient).DownloadFile($url, $temp) | |
return $temp | |
} | |
function Combine { | |
return [System.IO.Path]::Combine([String[]]$args) | |
} | |
function FullPath($path1) { | |
return [System.IO.Path]::GetFullPath($path1) | |
} | |
function Temp() { | |
return FullPath (Combine ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())) | |
} | |
$start = Get-Location | |
$dest = FullPath $Destination | |
# Download the file | |
$file = DownloadFile ($DownloadUrl -f $Edition) | |
$dir = Temp | |
$inclFlag = [String]::Join(' ', (([String[]]$Components) | ForEach-Object { '-i!"{0}"' -f (Combine ("rust-nightly-x86_64-pc-windows-{0}" -f $Edition) $_ ) })) | |
# Extract the file | |
& "cmd" "/c" ('"{0}" x -so "{1}" | "{0}" -si x -o"{2}" {3} -ttar' -f $7z, $file, $dir, $inclFlag) | |
$ext = Combine $dir ("rust-nightly-x86_64-pc-windows-{0}" -f $Edition) | |
Remove-Item -Recurse $Destination | |
New-Item -ItemType Directory $Destination | |
Set-Location | |
foreach($component in $Components) { | |
$path = Combine $ext $component | |
Remove-Item -ErrorAction Continue (Combine $path "manifest.in") | |
& "robocopy" $path $Destination "/MOVE" "/E" | |
} | |
Remove-Item -Recurse -ErrorAction Continue $dir | |
Remove-Item $file | |
Write-Output ("Rust installed at {0}" -f $Destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment