Last active
February 7, 2017 03:52
-
-
Save martinlindhe/93d245ec5240432c3f67e4230bec44c0 to your computer and use it in GitHub Desktop.
cross-compile golang on Windows host
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
$hostOS = Invoke-Expression "go env GOOS" | |
$hostARCH = Invoke-Expression "go env GOARCH" | |
$buildInfoDate = (Get-Date).ToString("yyyy-MM-dd_hh:mm") | |
# NOTE: don't use "arm64", since raspbian is 32-bit only, feb-2017 | |
$env:GOOS = "linux" | |
$env:GOARCH = "arm" | |
$env:GOARM = "7" | |
Invoke-Expression "go build -v -ldflags '-X main.BuildInfoDate=$buildInfoDate' cmd/ex1/ex1.go" | |
if ($LastExitCode -ne 0) { | |
Return | |
} | |
Remove-Item Env:\GOOS | |
Remove-Item Env:\GOARCH | |
Remove-Item Env:\GOARM | |
Write-Host "Uploading binary ..." | |
$uploadTime = Measure-Command { | |
Invoke-Expression "scp ex1 breakout1:." | |
} | |
Write-Host "Upload took" $uploadTime.TotalSeconds "sec" | |
Invoke-Expression "ssh breakout1 chmod +x ./ex1" | |
# Invoke-Expression "ssh breakout1 ./ex1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment