A set of scripts and makefiles to help build go projects
build/scripts/init.shis used to set all required environment variables.build/scripts/build_helper.shhas all build related functions and creates required directories for all builds.build/scripts/build.shdrives the build for the project.build/scripts/install_deps.shhas all external dependencies for the project.
- Change directory to the root of your go project and run:
curl https://raw.githubusercontent.com/farazmd/go-build-helper-scripts/master/install.sh | bash- Uses golangci-lint for linting.
- Add/Update the following in
build/scripts/init.shbased on your project:export APP_NAME=<output-binary-name>.export BINARY=<path/to/main/package>.
- You can add additional external go dependencies like cobra-cli, etc at
build/scripts/install_deps.sh. DEFAULT_PLATFORM_LISTcan be modified to list supported platforms for the project.This can also be overrided usingOVERRIDE_PLATFORM_LISTvariable. All values are space delimited.- Additional global env variables can be in
build/scripts/init.sh. - Additional platform specific env variables can be set using the function
go_set_env_vars_for_platforminbuild/scripts/build_helper.sh.
- The
default.golangci.yamlis just a sample configuration and can be customised based on project needs. - The golangci-lint configuration page has detailed information.
- Make has the following targets:
Usage:
make <target>
Targets:
Help:
help Show this help.
Build:
clean Clear out dist/ directory.
install-deps Install dependencies listed in build/scripts/install_deps.sh
scripts-executable Make all scripts under build/scripts executable
build-all Builds project for all platforms
lint Runs linter- Run
make scripts-executableto have all helper scripts underbuild/scriptsset with executable permissions. make lintruns linter usingbuild/scripts/lint.shscript.make build-allcreates binaries for all platforms underdist/directory.make install-depsis used to install any external dependencies for the project.
-
You can also use the scripts under
build/scripts/if you choose not to useMakefile. -
The
build/scripts/build.shis the main driver for running builds.
build.sh [-h] [ -t <targets> ]
-h Prints this help
-t A target platform or a set of target platforms to build. (Space demilited) Optional
Eg:
build.sh Will build for all platforms listed in DEFAULT_PLATFORM_LIST or OVERRIDE_PLATFORM_LIST
build.sh -t "darwin/arm64 darwin/amd64" Will build only darwin arm64 and amd64 versions- If using the
-toption with multiple platforms, the value has to be within quotes as in the example above.