Last active
September 21, 2021 20:37
-
-
Save melardev/0ed5a1ec74b0b4e78e90c28d77de6f77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $false)][switch]$Linux = $False, | |
[switch]$Move = $false, | |
[switch]$Arm = $false, | |
[switch]$Alpine = $false | |
) | |
# Do not forget to replace "app" by the project name | |
# Example usage: | |
# - Build for current OS and architecture and move to $GOPATH/bin | |
# pwsh build.ps1 -Linux -Move | |
# - Build for Arm and Alpine | |
# pwsh build.ps1 -Linux -Alpine -Arm | |
if ([bool]$Linux) | |
{ | |
Write-Host "Compiling for Linux" | |
$Env:GOOS = "linux"; | |
if ([bool]$Arm) | |
{ | |
$Env:GOARCH = "arm64"; | |
} | |
else | |
{ | |
$Env:GOARCH = "amd64"; | |
} | |
if ([bool]$Alpine) | |
{ | |
$Env:CGO_ENABLED = 0 | |
} | |
go build -ldflags="-s -w" | |
if ($Move) | |
{ | |
Write-Host "Moving app to $env:GOPATH/bin" | |
Move-Item -Force app $env:GOPATH/bin | |
} | |
} | |
else | |
{ | |
Write-host "Compiling for Windows" | |
$Env:GOOS = "windows"; $Env:GOARCH = "amd64"; go build -ldflags="-s -w" | |
if ($Move) | |
{ | |
Write-Host "Moving app.exe to $env:GOPATH/bin" | |
Move-Item -Force "app.exe" $env:GOPATH/bin | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment