diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1fc73acd..661f8fe5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,6 +59,9 @@ jobs: build-and-test: runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash strategy: matrix: include: @@ -70,15 +73,55 @@ jobs: goos: linux goarch: arm64 artifact_name: tronbyt-server-linux-arm64 - - os: macos-26 + - os: macos-latest goos: darwin goarch: arm64 artifact_name: tronbyt-server-darwin-arm64 + - os: windows-latest + goos: windows + goarch: amd64 + artifact_name: tronbyt-server-windows-amd64.exe steps: - uses: actions/checkout@v6 + # Windows specific setup + # Install GCC and Libwebp + - name: Setup MSYS2 + id: msys2 + if: matrix.goos == 'windows' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + path-type: inherit + update: true + install: >- + mingw-w64-x86_64-gcc + mingw-w64-x86_64-libwebp + mingw-w64-x86_64-pkgconf + + - name: Set CGO Flags (windows) + if: matrix.goos == 'windows' + shell: bash + run: | + # Retrieve the install location from the previous step + MSYS_ROOT="${{ steps.msys2.outputs.msys2-location }}" + + echo "Using MSYS2 at: $MSYS_ROOT" + + # Convert backslashes to forward slashes for GCC compatibility + MSYS_ROOT=$(echo "$MSYS_ROOT" | sed 's/\\/\//g') + + # Write to GITHUB_ENV so following steps (like 'go build') can see them + echo "CGO_CFLAGS=-I${MSYS_ROOT}/mingw64/include" >> "$GITHUB_ENV" + echo "CGO_LDFLAGS=-L${MSYS_ROOT}/mingw64/lib" >> "$GITHUB_ENV" + + # Optional: Add the mingw64 bin folder to PATH so dlls are found during tests + echo "${MSYS_ROOT}/mingw64/bin" >> "$GITHUB_PATH" + + # Linux/Mac specific setup - name: Install system dependencies + if: matrix.goos != 'windows' run: | if [ "$RUNNER_OS" == "Linux" ]; then sudo apt-get update @@ -96,19 +139,29 @@ jobs: run: go mod download - name: Test - # CGO required for pixlet - run: CGO_ENABLED=1 go test -v ./... + env: + CGO_ENABLED: 1 # CGO required for pixlet + run: go test -v ./... - name: Build env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 1 run: | VERSION=${GITHUB_REF_NAME} COMMIT=${GITHUB_SHA} DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + + # Base flags LDFLAGS="-w -s -X 'tronbyt-server/internal/version.Version=${VERSION}' -X 'tronbyt-server/internal/version.Commit=${COMMIT}' -X 'tronbyt-server/internal/version.BuildDate=${DATE}'" - CGO_ENABLED=1 go build -v -ldflags "${LDFLAGS}" -o ${{ matrix.artifact_name }} ./cmd/server + + # Add static flags ONLY for Windows to avoid DLL dependency + if [ "${{ matrix.goos }}" == "windows" ]; then + LDFLAGS="${LDFLAGS} -extldflags '-static'" + fi + + go build -v -ldflags "${LDFLAGS}" -tags gzip_fonts -o ${{ matrix.artifact_name }} ./cmd/server - name: Upload Release Artifacts uses: actions/upload-artifact@v6 diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 00000000..f150a350 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,51 @@ +Write-Host "Checking dependencies..." -ForegroundColor Cyan +if (-not (Get-Command "gcc" -ErrorAction SilentlyContinue)) { + Write-Error "GCC not found. Please ensure MSYS2 MinGW64 bin folder is in your PATH." + exit 1 +} + +# 1. Setup Environment Variables +$env:GOOS = "windows" +$env:GOARCH = "amd64" +$env:CGO_ENABLED = "1" # Required for libwebp and sqlite + +# 2. Get Version Info +$VERSION = "dev" +$COMMIT = "unknown" +$DATE = Get-Date -Format "yyyy-MM-dd" + +if (Test-Path .git) { + if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) { + Write-Error "git not found, but .git directory exists. Cannot determine version information." + exit 1 + } + $COMMIT = git rev-parse --short HEAD + $VERSION = git describe --tags --always --dirty +} + +Write-Host "Building Tronbyt Server ($VERSION)..." -ForegroundColor Green + +# 3. Download Dependencies +go mod download + +# 4. Build 'boot' (Entrypoint wrapper) +# Note: Usually on Windows you don't need this wrapper, but building it just in case. +# Boot is CGO-free (CGO_ENABLED=0), so we toggle it off briefly. +$env:CGO_ENABLED = "0" +go build -ldflags="-w -s" -o boot.exe ./cmd/boot +$env:CGO_ENABLED = "1" + +# 5. Build 'tronbyt-server' +$LDFLAGS = "-w -s -extldflags '-static' -X 'tronbyt-server/internal/version.Version=$VERSION' -X 'tronbyt-server/internal/version.Commit=$COMMIT' -X 'tronbyt-server/internal/version.BuildDate=$DATE'" + +go build -ldflags="$LDFLAGS" -tags gzip_fonts -o tronbyt-server.exe ./cmd/server + +if ($LASTEXITCODE -ne 0) { + Write-Error "Server build failed!" + exit 1 +} + +# 6. Build 'migrate' (Database tool) +go build -ldflags="-w -s" -o migrate.exe ./cmd/migrate + +Write-Host "Build Complete!" -ForegroundColor Green diff --git a/cmd/boot/main.go b/cmd/boot/main.go index 0fd1e441..3d03809d 100644 --- a/cmd/boot/main.go +++ b/cmd/boot/main.go @@ -1,3 +1,5 @@ +//go:build !windows + package main import (