Skip to content

Instantly share code, notes, and snippets.

@SCP002
Last active September 24, 2026 04:18
Show Gist options
  • Select an option

  • Save SCP002/a24afa9f8aa6902c4ecadf3ac6ca117f to your computer and use it in GitHub Desktop.

Select an option

Save SCP002/a24afa9f8aa6902c4ecadf3ac6ca117f to your computer and use it in GitHub Desktop.
Golang: Shell script to build your project to each OS / Architecture available.
#!/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