-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgobuildall.ps1
83 lines (68 loc) · 1.73 KB
/
gobuildall.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
#!/usr/bin/pwsh
New-Item -ItemType Directory -Force -Path @(
"build/windows_x64",
"build/windows_x86",
"build/linux_x64",
"build/linux_x86",
"build/linux_arm64",
"build/darwin_x64",
"build/darwin_x86",
"build/darwin_arm64"
) | Out-Null
$rootDir = Get-Location
Write-Host "rootDir: $rootDir"
if ($IsWindows) {
$script:GoExe = "go.exe"
} else {
$script:GoExe = "go"
}
class BuildTarget {
[String]$OS
[String]$Arch
[String]$BuildDir
BuildTarget(
[String]$OS,
[String]$Arch,
[String]$BuildDir
) {
$this.OS = $OS
$this.Arch = $Arch
$this.BuildDir = $BuildDir
}
}
$targets = @(
[BuildTarget]::new("linux", "amd64", "linux_x64"),
[BuildTarget]::new("linux", "386", "linux_x86"),
[BuildTarget]::new("linux", "arm64", "linux_arm64"),
[BuildTarget]::new("windows", "amd64", "windows_x64"),
[BuildTarget]::new("windows", "386", "windows_x86"),
[BuildTarget]::new("darwin", "amd64", "darwin_x64"),
[BuildTarget]::new("darwin", "amd64", "darwin_x86"),
[BuildTarget]::new("darwin", "arm64", "darwin_arm64")
)
$jobs = @()
$targets | ForEach-Object {
$jobs += Start-ThreadJob `
-Name $_.BuildDir `
-StreamingHost $Host `
-ScriptBlock {
$item = $using:_
$OS = $item.OS
$Arch = $item.Arch
$BuildDir = $item.BuildDir
$rootDir = $using:rootdir
$GoExe = $using:GoExe
Write-Host "Building for $OS $ARCH"
Set-Location $rootDir\build\$BuildDir
New-Item -Path Env:\GOOS -Value $OS -Force | Out-Null
New-Item -Path Env:\GOARCH -Value $ARCH -Force | Out-Null
& $GoExe build ../..
Write-Host "Compressing $BuildDir"
Set-Location $rootDir\build
Compress-Archive `
-Path (Get-ChildItem .\$BuildDir\*) `
-DestinationPath "${BuildDir}.zip" `
-CompressionLevel Optimal
}
}
Wait-Job -Job $jobs