-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-targets.ps1
109 lines (91 loc) · 3.69 KB
/
install-targets.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function Show-TargetMenu {
Write-Host "`n📦 Targets installation selection" -ForegroundColor Cyan
Write-Host "------------------------"
Write-Host "1. Windows (x86_64-pc-windows-msvc)"
Write-Host "2. Linux (x86_64-unknown-linux-musl)"
Write-Host "3. MacOS (x86_64-apple-darwin)"
Write-Host "4. All targets"
Write-Host "5. Exit"
Write-Host "------------------------"
$choice = Read-Host "Choose an option"
$targets = @()
switch ($choice) {
"1" { $targets = @("x86_64-pc-windows-msvc") }
"2" { $targets = @("x86_64-unknown-linux-musl") }
"3" { $targets = @("x86_64-apple-darwin") }
"4" { $targets = @("x86_64-pc-windows-msvc", "x86_64-unknown-linux-musl", "x86_64-apple-darwin") }
"5" { return $null }
default {
Write-Host "❌ Invalid option" -ForegroundColor Red
return $null
}
}
return $targets
}
function Install-CrossTools {
Write-Host "📥 Installing cross-rs..." -ForegroundColor Yellow
# Installer Docker Desktop si nécessaire
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
Write-Host " Installing Docker Desktop..." -ForegroundColor Yellow
winget install Docker.DockerDesktop
Write-Host "⚠️ Please restart your computer after Docker installation" -ForegroundColor Yellow
return $false
}
# Installer cross
cargo install cross
Write-Host "✅ cross-rs installed successfully" -ForegroundColor Green
return $true
}
function Install-RustTargets {
Write-Host "`n🔧 Rust targets management..." -ForegroundColor Cyan
$targets = Show-TargetMenu
if ($null -eq $targets) {
return $false
}
foreach ($target in $targets) {
$installed = rustup target list | Select-String "^$target" | Select-String "installed"
if (-not $installed) {
Write-Host " 📥 Installing target $target..." -ForegroundColor Yellow
if ($target -eq "x86_64-unknown-linux-musl") {
Install-CrossTools
}
$spinner = @('⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏')
$job = Start-Job -ScriptBlock {
param($target)
rustup target add $target
} -ArgumentList $target
$i = 0
while ($job.State -eq 'Running') {
Write-Host "`r $($spinner[$i % $spinner.Length]) Downloading... " -NoNewline -ForegroundColor Yellow
Start-Sleep -Milliseconds 100
$i++
}
$result = Receive-Job -Job $job
Remove-Job -Job $job
Write-Host "`r " -NoNewline
if ($LASTEXITCODE -eq 0) {
Write-Host " ✅ Target $target installed successfully" -ForegroundColor Green
} else {
Write-Host " ❌ Installation of $target failed" -ForegroundColor Red
Write-Host $result -ForegroundColor Red
return $false
}
} else {
Write-Host " ✅ Target $target already installed" -ForegroundColor Green
}
}
return $true
}
# Main loop
do {
Clear-Host
Write-Host "🎯 Rust Target Installer" -ForegroundColor Magenta
Write-Host "------------------------"
Install-RustTargets
Write-Host "`nPress any key to continue or 'Q' to quit..."
$key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
if ($key.Character -eq 'q' -or $key.Character -eq 'Q') {
Write-Host "`n👋 Goodbye!" -ForegroundColor Cyan
break
}
} while ($true)