Home

Awesome

goxc build status

NOTE: goxc has long been in maintenance mode. Ever since Go1.5 supported simple cross-compilation, this tool lost much of its value. There are still many aspects of goxc which I'm very proud of, and some packaging features in particular, which are still useful. I'm very much a go user, but I myself haven't had any need for goxc for a long while.

If you see something you'd like to add to goxc, please go ahead, fork and PR. Good PRs will earn you commit access to the repo. Thanks for everyone's help over the years.

goxc is a build tool for Go, with a focus on cross-compiling and packaging.

By default, goxc [g]zips (& .debs for Linux) the programs, and generates a 'downloads page' in markdown (with a Jekyll header).

goxc is written in Go but uses os.exec to call 'go build' with the appropriate flags & env variables for each supported platform.

goxc was inspired by Dave Cheney's Bash script golang-crosscompile.

Notable Features

Installation

goxc requires the go source and the go toolchain.

  1. Install go from source. (Requires gcc (or MinGW) and 'hg')

    • OSX Users Note: If you are using XCode 5 (OSX 10.9), it is best to go straight to Go 1.2rc5 (or greater). This is necessary because Apple have replaced the standard gcc with llvm-gcc, and Go 1.1 compilation tools depend on the usual gcc.

      • There is another workaround incase Go 1.2rc5 is not an option:

          brew tap homebrew/versions
          brew install apple-gcc42
          go get github.com/laher/goxc
          CC=`brew list apple-gcc42 | grep bin/gcc-4.2` goxc -t
        
  2. Install goxc:

    go get github.com/laher/goxc
    	
    
  3. a. (just once per Go version): to pre-build the toolchains for all platforms:

    goxc -t
    
    • Note that rebuilding the toolchain is only required for Go up until v1.4. This step will become unnecessary in Go 1.5.
    • Note that, until goxc v0.16.0, rebuilding the toolchain was triggered automatically. This has now been switched off (by default). Automatic rebuilding was causing a number of subtle bugs for different users, and has been switched off since v0.16.0.
    • Also note that building the toolchain takes a while. Cross-compilation itself is quite fast.

Basic Usage

cd path/to/app/dir
goxc

More options

Use goxc -h to list all options.

"Tasks"

goxc performs a number of operations, defined as 'tasks'. You can specify tasks as commandline arguments

Outcome

By default, artifacts are generated and then immediately archived into (outputdir).

Examples:

The version number is specified with -pv=0.1.1 .

By default, the output directory is ($GOBIN)/(appname)-xc, and the version is 'unknown', but you can specify these.

e.g.

  goxc -pv=0.1.1 -d=/home/me/myuser-github-pages/myapp/downloads/

NOTE: it's bad idea to use project-level github-pages - your repo will become huge. User-level gh-pages are an option, but it's better to use the 'bintray' tasks.:

If non-archived, artifacts generated into a directory structure as follows:

(outputdir)/(version)/(OS)_(ARCH)/(appname)(.exe?)

Be careful if you want to build a project with multiple executables. You need to add {{.ExeName}} to your OutPath-setting in your '.goxc.json'. So it may look like the following code snippet.

"OutPath": "{{.Dest}}{{.PS}}{{.AppName}}{{.PS}}{{.Version}}{{.PS}}{{.ExeName}}_{{.Version}}_{{.Os}}_{{.Arch}}{{.Ext}}"

Configuration file

For repeatable builds (and some extra options), it is recomended to use goxc with one or more configuration file(s) to save and re-run compilations.

To create a config file (.goxc.json), just use the -wc (write config) option.

goxc -wc -d=../site/downloads -bc="linux windows" xc -GOARM=7

You can also use multiple config files to support different paremeters for each platform.

The following would add a 'local' config file, .goxc.local.json. This file's contents will override .goxc.json. The idea of the .local.json files is to git-ignore them - for any local parameters which you only want on this particular computer, but not for other users or even for yourself on other computers/OS's.

goxc -wlc -d=../site/downloads

The configuration file(s) feature is documented in much more detail in the wiki

Github Releases

This is the good stuff, so let’s go from the top.

	goxc -t
	goxc -wc default publish-github -owner=<username> 
	goxc -wc default publish-github -repository=<reponame>
	cat .goxc.json
	goxc bump

https://github.com/settings/tokens

	goxc -wlc default publish-github -apikey=123456789012
	echo ".goxc.local.json" >> .gitignore

Note that you can put a dummy key into the commandline and edit the file later with the real key.

	goxc

There’s heaps of ways to reconfigure each task to get the outcome you really want, but this produces some pretty sensible defaults. Have fun.

Limitations

License

Copyright 2013 Am Laher

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See also