simple go tool to cross-compile binaries, hash sums and archives for publishing
This tool doesn't rely anything outside of the standard library, the hashing and compression are handled internally. This keeps the tool nimble and cross platform meaning we don't need to rely on build environments prepopulated with packages (aside from Go itself). You can customize each build with additional flags and CGO_ENABLED environment variable as needed, see the example config below.
go install github.com/dearing/go-cross-compile
Note
if your project is Go 1.24+, you can pin the tool to your module workspace instead of installing it in the host's path
go get -tool github.com/dearing/go-cross-compile@latest
go tool go-cross-compile --version
go tool go-cross-compile --init-config
go tool go-cross-compile
pin => go get -tool github.com/dearing/[email protected]
update => go get -tool github.com/dearing/go-cross-compile@latest
downgrade => go get -tool github.com/dearing/[email protected]
uninstall => go get -tool github.com/dearing/go-cross-compile@none
This project has itself defined as a tool, so as a test drive you can download the project and call the tool to generate a default config and execute without any other preperation.
git clone https://github.com/dearing/go-cross-compile.git
cd go-cross-compile
mkdir build
go tool go-cross-compile --init-config
go tool go-cross-compile --config-file go-cross-compile.json
dir build
Usage: [go tool] go-cross-compile [options]
This tool was inspired from the tedious task of cross compiling go binaries and
hash sums. The md5, sha1, sha256, sha512 and zip options are available for each
artifact of the operation.
- $outDir/$name per artifact member of artifacts defined in the config
- $outDir/$name.$mode.txt for each of md5, sha1, sha256 or sha512 when enabled
- $outDir/$name.zip containing the artifact per build when enabled
Workflow:
1. generate a new config file with 'go-cross-compile --init-config'
2. edit the config file 'go-cross-compile.json' to your liking
3. create the outDir ex: 'mkdir build' (this is a kind of safety check)
4. run 'go-cross-compile --config-file go-cross-compile.json' to have Go build
the artifacts and create the hash sums and zip files
Tips:
- 'go tool dist list' will show the valid GOOS and GOARCH values
- the zip files will contain the artifact at the root of the tree
- the hash sum text files are compatible with the gnu core text utilities
- the argument --version will emit debug metadata of the tool itself
- the tool will exit with a non-zero status on error
Options:
-config-file string
config file to use (default "go-cross-compile.json")
-init-config
initialize a new config file and exit
-version
emit version and build info and exit
{
"outDir": "build",
"srcDir": ".",
"md5": false,
"sha1": true,
"sha256": false,
"sha512": false,
"zipFile": true,
"artifacts": [
{
"name": "go-cross-compile-darwin-amd64",
"os": "darwin",
"arch": "amd64"
},
{
"name": "go-cross-compile-darwin-arm64",
"os": "darwin",
"arch": "arm64"
},
{
"name": "go-cross-compile-linux-arm64",
"os": "linux",
"arch": "arm64"
},
{
"name": "go-cross-compile-linux-amd64",
"os": "linux",
"arch": "amd64"
},
{
"name": "go-cross-compile-linux-amd64-stripped",
"os": "linux",
"arch": "amd64",
"flags": [
"-ldflags=-s -w"
]
},
{
"name": "go-cross-compile-windows-amd64.exe",
"os": "windows",
"arch": "amd64"
},
{
"name": "go-cross-compile-windows-amd64-stripped.exe",
"os": "windows",
"arch": "amd64",
"flags": [
"-ldflags=-s -w"
]
},
{
"name": "go-cross-compile-windows-arm64.exe",
"os": "windows",
"arch": "arm64"
}
]
}