Skip to content

Commit 8a2e13b

Browse files
committed
Auto merge of #220 - gdoenlen:master, r=fmoko
Add windows install script Adds a powershell install script for windows users that are at least running powershell 5. It is almost a direct port of install.sh. This would be used to automatically download the script much like curl | bash, but with: `Invoke-WebRequest https://urltoscript.com | Select-Object -ExpandProperty Content | Out-File $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1`
2 parents e6161a6 + ee311b8 commit 8a2e13b

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

install.ps1

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env pwsh
2+
3+
#Requires -Version 5
4+
param($path = "$pwd/rustlings")
5+
6+
Write-Host "Let's get you set up with Rustlings!"
7+
8+
Write-Host "Checking requirements..."
9+
if (Get-Command git -ErrorAction SilentlyContinue) {
10+
Write-Host "SUCCESS: Git is installed"
11+
} else {
12+
Write-Host "WARNING: Git does not seem to be installed."
13+
Write-Host "Please download Git using your package manager or over https://git-scm.com/!"
14+
exit 1
15+
}
16+
17+
if (Get-Command rustc -ErrorAction SilentlyContinue) {
18+
Write-Host "SUCCESS: Rust is installed"
19+
} else {
20+
Write-Host "WARNING: Rust does not seem to be installed."
21+
Write-Host "Please download Rust using https://rustup.rs!"
22+
exit 1
23+
}
24+
25+
if (Get-Command cargo -ErrorAction SilentlyContinue) {
26+
Write-Host "SUCCESS: Cargo is installed"
27+
} else {
28+
Write-Host "WARNING: Cargo does not seem to be installed."
29+
Write-Host "Please download Rust and Cargo using https://rustup.rs!"
30+
exit 1
31+
}
32+
33+
# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0).
34+
# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2.
35+
function vercomp($v1, $v2) {
36+
if ($v1 -eq $v2) {
37+
return 0
38+
}
39+
40+
$v1 = $v1.Replace(".", "0")
41+
$v2 = $v2.Replace(".", "0")
42+
if ($v1.Length -gt $v2.Length) {
43+
$v2 = $v2.PadRight($v1.Length, "0")
44+
} else {
45+
$v1 = $v1.PadRight($v2.Length, "0")
46+
}
47+
48+
if ($v1 -gt $v2) {
49+
return 1
50+
} else {
51+
return 2
52+
}
53+
}
54+
55+
$rustVersion = $(rustc --version).Split(" ")[1]
56+
$minRustVersion = "1.31"
57+
if ((vercomp $rustVersion $minRustVersion) -eq 2) {
58+
Write-Host "WARNING: Rust version is too old: $rustVersion - needs at least $minRustVersion"
59+
Write-Host "Please update Rust with 'rustup update'"
60+
exit 1
61+
} else {
62+
Write-Host "SUCCESS: Rust is up to date"
63+
}
64+
65+
Write-Host "Cloning Rustlings at $path"
66+
git clone -q https://github.com/rust-lang/rustlings $path
67+
if (!($LASTEXITCODE -eq 0)) {
68+
exit 1
69+
}
70+
71+
# UseBasicParsing is deprecated, pwsh 6 or above will automatically use it,
72+
# but anyone running pwsh 5 will have to pass the argument.
73+
$version = Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/rust-lang/rustlings/releases/latest `
74+
| ConvertFrom-Json | Select-Object -ExpandProperty tag_name
75+
Write-Host "Checking out version $version..."
76+
Set-Location $path
77+
git checkout -q tags/$version
78+
79+
Write-Host "Installing the 'rustlings' executable..."
80+
cargo install --force --path .
81+
if (!(Get-Command rustlings -ErrorAction SilentlyContinue)) {
82+
Write-Host "WARNING: Please check that you have '~/.cargo/bin' in your PATH environment variable!"
83+
}
84+
85+
Write-Host "All done! Run 'rustlings' to get started."

0 commit comments

Comments
 (0)