Reputation: 4565
I use
import "github.com/dontpanic92/wxGo/wx"
in a program that can run with or without a GUI.
i.e. you might run it like:
./program --gui true
or
./program --gui false
When running on Linux with GUI false I'd like to avoid having to compile all of wxGo/wx
.
How can I check in the same code to git so that it will compile on Mac or Linux just fine.
i.e. right now when I compile on Linux I have to comment out any reference to wxGo/wx
Upvotes: 1
Views: 1359
Reputation: 5582
If you want to exclude specific Go files from building on certain operating systems, architectures, Go versions or if certain tags are specified during compilation, these are your options:
If you want a file to only build on Linux, append _linux
to the file name, e.g. gui_linux.go
. It is also possible to specify an architecture, or both, e.g. gui_windows_amd64.go
.
Add a //+build ...
comment at the top of your Go file, e.g. // +build linux,386
.
See https://golang.org/pkg/go/build/#hdr-Build_Constraints for details.
Upvotes: 4