Building Multiple Go Package Binaries Simultaneously
The question revolves around building multiple package binaries simultaneously, as the default advice of using a top-level cmd folder doesn't seem to work. The provided code example shows a particular folder structure that enables building specific binaries correctly.
To build all binaries in one step using the go build command, a variation of the following is recommended:
cd $GOPATH/someProject for CMD in `ls src/cmd`; do go build ./src/cmd/"$CMD" done
This command iterates through the packages in the src/cmd directory and builds each package individually. The resulting binaries will be stored in their respective package directories.
Alternatively, if you don't wish to install the binaries into $GOPATH/bin, a script can be employed. This is a common practice in open source projects, where build scripts handle multiple binary production.
The following example script can be used:
cd $GOPATH/someProject for CMD in `ls cmd`; do go build ./cmd/$CMD done
This script iterates through the packages in the cmd directory and runs go build on each. The result is a set of binaries stored in their respective cmd package directories.
For further reference, the following popular projects provide examples of build scripts:
The above is the detailed content of How to Build Multiple Go Package Binaries Simultaneously Without a Top-Level `cmd` Folder?. For more information, please follow other related articles on the PHP Chinese website!