1 ##### Appveyor Rust Install Script #####
2 
3 # https://github.com/starkat99/appveyor-rust
4 
5 # This is the most important part of the Appveyor configuration. This installs the version of Rust
6 # specified by the "channel" and "target" environment variables from the build matrix. By default,
7 # Rust will be installed to C:\Rust for easy usage, but this path can be overridden by setting the
8 # RUST_INSTALL_DIR environment variable. The URL to download rust distributions defaults to
9 # https://static.rust-lang.org/dist/ but can overridden by setting the RUST_DOWNLOAD_URL environment
10 # variable.
11 #
12 # For simple configurations, instead of using the build matrix, you can override the channel and
13 # target environment variables with the --channel and --target script arguments.
14 #
15 # If no channel or target arguments or environment variables are specified, will default to stable
16 # channel and x86_64-pc-windows-msvc target.
17 
18 param([string]$channel=${env:channel}, [string]$target=${env:target})
19 
20 # Initialize our parameters from arguments and environment variables, falling back to defaults
21 if (!$channel) {
22     $channel = "stable"
23 }
24 if (!$target) {
25     $target = "x86_64-pc-windows-msvc"
26 }
27 
28 $downloadUrl = "https://static.rust-lang.org/dist/"
29 if ($env:RUST_DOWNLOAD_URL) {
30     $downloadUrl = $env:RUST_DOWNLOAD_URL
31 }
32 
33 $installDir = "C:\Rust"
34 if ($env:RUST_INSTALL_DIR) {
35     $installUrl = $env:RUST_INSTALL_DIR
36 }
37 
38 if ($channel -eq "stable") {
39     # Download manifest so we can find actual filename of installer to download. Needed for stable.
40     echo "Downloading $channel channel manifest"
41     $manifest = "${env:Temp}\channel-rust-${channel}"
42     Start-FileDownload "${downloadUrl}channel-rust-${channel}" -FileName "$manifest"
43 
44     # Search the manifest lines for the correct filename based on target
45     $match = Get-Content "$manifest" | Select-String -pattern "${target}.exe" -simplematch
46 
47     if (!$match -or !$match.line) {
48         throw "Could not find $target in $channel channel manifest"
49     }
50 
51     $installer = $match.line
52 } else {
53     # Otherwise download the file specified by channel directly.
54     $installer = "rust-${channel}-${target}.exe"
55 }
56 
57 # Download installer
58 echo "Downloading ${downloadUrl}$installer"
59 Start-FileDownload "${downloadUrl}$installer" -FileName "${env:Temp}\$installer"
60 
61 # Execute installer and wait for it to finish
62 echo "Installing $installer to $installDir"
63 &"${env:Temp}\$installer" /VERYSILENT /NORESTART /DIR="$installDir" | Write-Output
64 
65 # Add Rust to the path.
66 $env:Path += ";${installDir}\bin;C:\MinGW\bin"
67 
68 echo "Installation of $channel Rust $target completed"
69 
70 # Test and display installed version information for rustc and cargo
71 rustc -V
72 cargo -V