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