@echo off setlocal cd /d "%~dp0" where go >nul 2>nul if errorlevel 1 ( echo [error] Go toolchain not found in PATH. exit /b 1 ) where upx >nul 2>nul if errorlevel 1 ( echo [error] UPX not found in PATH; the build convention requires compression. exit /b 1 ) if not exist "bin" mkdir "bin" echo [1/2] Building bin\myfile.exe ... go build -trimpath -ldflags "-s -w" -o "bin\myfile.exe" . if errorlevel 1 ( echo [error] go build failed. exit /b 1 ) echo [2/2] Compressing with UPX ... upx -9 "bin\myfile.exe" if errorlevel 1 ( echo [error] UPX compression failed. exit /b 1 ) echo Build complete: %~dp0bin\myfile.exe exit /b 0