go-build-bash icon indicating copy to clipboard operation
go-build-bash copied to clipboard

"go build" implementation by bash script

go-build-bash

A bash script that emulates go build.

The goal of this project is to help Go users understand what to do to build a package.

Some advantages of go-build-bash over the official go build include:

It can build large modules like kubectl , uber-go/zap, spf13/cobra, golang/protobuf etc.

Prerequisite

Host machine

  • Bash 5.1 or later
  • go version 1.20
  • OS:MacOS or Linux
  • (On MacOS) brew install bash findutils gnu-sed coreutils
  • CPU:x86-64

Cross compilation supported

4 combinations of cross OS compilation are supported:

  • darwin => darwin
  • darwin => linux
  • linux => darwin
  • linux => linux

Usage

Build a "hello world" program:

$ cd examples/hello
$ GOOS=linux GOARCH=amd64 ../../go-build.sh
$ docker run --rm -v `pwd`:/mnt/ -w /mnt busybox ./hello

hello world

Build kubectl:

$ cd examples/kubectl
$ GOOS=linux GOARCH=amd64 ../../go-build.sh
$ docker run --rm -v `pwd`:/mnt/ -w /mnt busybox ./kubectl version

TODO

  • [ ] Support Apple silicon
  • [ ] Debug features

License

MIT

Author

@DQNEO