Skip to content

Instantly share code, notes, and snippets.

@rockwotj
Created December 6, 2015 01:53
Show Gist options
  • Save rockwotj/6eab368cf46870421bfe to your computer and use it in GitHub Desktop.
Save rockwotj/6eab368cf46870421bfe to your computer and use it in GitHub Desktop.
A short ruby script to cross platform a golang project
#! /usr/bin/env ruby
if not ARGV[0] or ARGV[0] == "-h"
puts "Usage: ./go_dist <project>"
exit
end
project_path = ARGV[0]
project = project_path.split('/')[-1]
puts "\e[1mStarting distribution of \e[32m'#{project}'\e[0m"
platforms = {
"darwin" => ["amd64"],
"windows" => ["amd64", "386"],
"linux" => ["amd64", "386", "arm"]
}
platforms.each do |os, array|
exe = project
if os == "windows"
exe += ".exe"
end
array.each do |arch|
output = `env GOOS=#{os} GOARCH=#{arch} go build #{project_path} && echo "success"`
if output.include? 'success'
`mkdir -p $GOPATH/dist/#{project}/#{os}-#{arch}/`
`mv #{exe} $GOPATH/dist/#{project}/#{os}-#{arch}/`
puts "Compiled binary for \e[35m#{os}-#{arch}\e[0m"
else
puts "Build failed for \e[31m#{os}-#{arch}\e[0m"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment