Skip to content

Commit

Permalink
Fix Windows builds and test they compile
Browse files Browse the repository at this point in the history
They are still not officially supported but this ensures we don't
break the build accidentally.

Caches are enabled by default in actions/setup-go@v4 so no need to
manually cache.
  • Loading branch information
hifi committed Dec 15, 2023
1 parent 6824eb6 commit f79935a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- run: |
go install golang.org/x/tools/cmd/goimports@latest
Expand All @@ -29,21 +28,36 @@ jobs:
- uses: pre-commit/[email protected]

build:
name: Build & Unit Test
build-windows:
name: Build Windows
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y mingw-w64

- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/cache@v2
- run: |
go build ./cmd/litestream/
file ./litestream.exe
env:
CGO_ENABLED: "1"
GOOS: windows
GOARCH: amd64
CC: x86_64-w64-mingw32-gcc
build:
name: Build & Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
path: ~/go/pkg/mod
key: ${{ inputs.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ inputs.os }}-go-
go-version: ${{ env.GO_VERSION }}

- run: go env

Expand Down
11 changes: 5 additions & 6 deletions cmd/litestream/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
import (
"context"
"io"
"log"
"log/slog"
"os"
"os/signal"
Expand Down Expand Up @@ -37,16 +36,16 @@ func runWindowsService(ctx context.Context) error {
defer elog.Close()

// Set eventlog as log writer while running.
log.SetOutput((*eventlogWriter)(elog))
defer log.SetOutput(os.Stderr)
slog.SetDefault(slog.New(slog.NewTextHandler((*eventlogWriter)(elog), nil)))
defer slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))

log.Print("Litestream service starting")
slog.Info("Litestream service starting")

if err := svc.Run(serviceName, &windowsService{ctx: ctx}); err != nil {
return errStop
}

log.Print("Litestream service stopped")
slog.Info("Litestream service stopped")
return nil
}

Expand All @@ -69,7 +68,7 @@ func (s *windowsService) Execute(args []string, r <-chan svc.ChangeRequest, stat
}

// Execute replication command.
if err := c.Run(s.ctx); err != nil {
if err := c.Run(); err != nil {
slog.Error("cannot replicate", "error", err)
statusCh <- svc.Status{State: svc.StopPending}
return true, 2
Expand Down

0 comments on commit f79935a

Please sign in to comment.