-
Notifications
You must be signed in to change notification settings - Fork 40
feat: windows build #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: windows build #697
Changes from all commits
055a02a
bbfc68a
e914cec
d6dda76
e4d1a2f
dca6f41
d2b19ac
c8b827a
c494ccb
612faa0
4cfe5c1
360bd48
6e89fde
de15398
e9c290b
d671c65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could remove the |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| Write-Host "Checking dependencies..." -ForegroundColor Cyan | ||
noahpodgurski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the |
||
| # 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| //go:build !windows | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this change. |
||
|
|
||
| package main | ||
|
|
||
| import ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured if we're doing windows-latest, might as well update mac, I can remove if you'd like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's better to be explicit with version numbers so that the runners don't change unexpectedly.