Last active
September 24, 2026 04:18
-
-
Save SCP002/a24afa9f8aa6902c4ecadf3ac6ca117f to your computer and use it in GitHub Desktop.
Golang: Shell script to build your project to each OS / Architecture available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| project_name="my-project" | |
| build_path="build" | |
| cgo_enabled=0 | |
| command -v go > /dev/null || { echo "go not found in PATH" >&2; exit 1; } | |
| mkdir -p "$build_path" | |
| for target in $(go tool dist list); do | |
| os=${target%/*} | |
| arch=${target#*/} | |
| ext="" | |
| [[ $os == "windows" ]] && ext=".exe" | |
| [[ $arch == "wasm" ]] && ext=".wasm" | |
| echo "Building for $os / $arch" | |
| CGO_ENABLED=$cgo_enabled GOOS=$os GOARCH=$arch go build -trimpath -o "${build_path}/${project_name}-${os}-${arch}${ext}" . | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment