Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Added XGO cross compilation support for Darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
Zillode committed Oct 11, 2016
1 parent 3c0b351 commit 5c9c17a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
41 changes: 41 additions & 0 deletions cross-compile-xgo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env ruby

targets = "darwin/amd64,
dragonfly/amd64,
freebsd/*,
linux/*,
netbsd/*,
openbsd/*,
windows/*"

targets.gsub!(" ","").gsub!("\n","")

version = `git describe --abbrev=0 --tags`.chomp
diff = `git diff`.chomp

#unless diff.empty?
# puts "Forgot to git reset --hard?"
# exit if gets.chomp != "n"
#end

vars = "GO386=387"
ldflags = "-w -X main.Version=#{version}"
build = "#{vars} xgo -v --targets=#{targets} -ldflags '#{ldflags}' ."
puts "Running #{build}"
#`#{build}`

Dir.glob("syncthing-inotify-*").each do |file|
next unless File.file?(file)
next if file.include?(".tar.gz")
name = "syncthing-inotify"
if file.include?("windows")
name = "syncthing-inotify.exe"
end
move = "cp #{file} #{name}"
package = "tar -czf #{file}-#{version}.tar.gz #{name}"
rm = "rm -f syncthing-inotify"
#rm = "rm -f syncthing-inotify #{name}"
puts "Packaging #{file}"
`#{move} && #{package}
& #{rm}`
end
11 changes: 8 additions & 3 deletions cross-compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
diff = `git diff`.chomp

unless diff.empty?
puts "Forgot to git reset --hard?"
puts "Forgot to git reset --hard? (Y/n)"
exit if gets.chomp != "n"
end

Expand All @@ -39,9 +39,14 @@
vars += " GOARM=5"
end
ldflags = "-w -X main.Version=#{version}"
build = "#{vars} go build -ldflags '#{ldflags}'"
if os.include?("darwin")
build = "xgo --targets=darwin/amd64 -ldflags '#{ldflags}' ."
build += " && mv syncthing-inotify-darwin-10.6-amd64 #{name}"
else
build = "#{vars} go build -ldflags '#{ldflags}'"
end
package = "tar -czf syncthing-inotify-#{os}-#{arch}-#{version}.tar.gz #{name}"
remove = "rm #{name}"
remove = "rm -f #{name}"
output = `#{build} 2>&1 && #{package} && #{remove}`
puts output unless output.empty?
if output.include?("must be bootstrapped") || output.include?("no such tool")
Expand Down

0 comments on commit 5c9c17a

Please sign in to comment.