Skip to content

feat: support building modctl for Windows - #705

Open
NopeCharon wants to merge 1 commit into
modelpack:mainfrom
NopeCharon:feat/windows-build-support
Open

NopeCharon wants to merge 1 commit into
modelpack:mainfrom
NopeCharon:feat/windows-build-support

Conversation

@NopeCharon

Copy link
Copy Markdown

Problem

GOOS=windows GOARCH=amd64 go build ./... fails on main:

pkg/version/version.go:22:15: undefined: platform
pkg/xattr/xattr.go:39:18: undefined: unix.Getxattr
pkg/backend/build/builder.go:420:38: undefined: syscall.Stat_t
cmd/login.go:87:42: cannot use syscall.Stdin (variable of uintptr type syscall.Handle) as int value in argument to terminal.ReadPassword

Also, the disk space pre-check added in #471 is only a no-op stub on Windows.

Fixes #520

Changes

  • pkg/diskspace: move the statfs query out of Check into availableSpace. It uses unix.Statfs on Linux/macOS (same logic as before, overflow cap included) and windows.GetDiskFreeSpaceEx on Windows, which honors per-user quotas. The pre-check now runs natively on Windows. The no-op stub stays for other platforms.
  • pkg/xattr: move Get/Set to xattr_unix.go (linux || darwin). On other platforms both return an error wrapping errors.ErrUnsupported. Callers in pkg/codec already treat xattr errors as a cache miss and as a best-effort failure. On Windows, extraction still works but skips the xattr metadata cache, so files are always rewritten. NTFS alternate data streams could be a follow-up if needed.
  • pkg/version: Platform now uses runtime.GOOS instead of per-OS platform constants. It prints the same values on Linux and macOS.
  • pkg/backend/build: move the UID/GID lookup into fileOwner (unix vs. !unix). Platforms without numeric owners return zero IDs. The test helper that derives the expected owner is split the same way, so the test package also compiles on Windows.
  • cmd/login: terminal.ReadPassword(int(os.Stdin.Fd())) works on both Unix and Windows.
  • CI: new Cross Compile (windows/amd64) job in ci.yml that runs go build ./... and go vet ./... (test files included) with GOOS=windows CGO_ENABLED=0, to prevent regressions.

Tests

  • go test -tags static,system_libgit2 ./... passes on linux/arm64. pkg/diskspace, pkg/xattr, pkg/backend/build and cmd tests also pass on darwin/arm64.
  • GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build ./... && go vet ./... passes. GOOS=freebsd vet passes too.
  • golangci-lint run (v2.4) reports 0 issues.
  • I couldn't run the binary on a real Windows host, so the Windows-specific code paths are only compile-checked.

`GOOS=windows GOARCH=amd64 go build ./...` failed because several
packages relied on Unix-only APIs or on platform constants that were
only defined for Linux and macOS:

- pkg/version: `platform` was only declared in platform_linux.go and
  platform_darwin.go. Use runtime.GOOS instead, which reports the same
  values on Linux and macOS and works on every other platform.
- pkg/xattr: Get/Set call unix.Getxattr/unix.Setxattr. Move them to
  xattr_unix.go (linux || darwin) and add a stub for other platforms
  that returns an error wrapping errors.ErrUnsupported. Callers in
  pkg/codec already treat xattr errors as a cache miss and as a
  best-effort failure, so extraction keeps working without the
  metadata cache.
- pkg/diskspace: split the statfs query out of Check into
  availableSpace, implemented with unix.Statfs on Linux/macOS and with
  windows.GetDiskFreeSpaceEx on Windows (honoring per-user quotas), so
  the build/pull disk space pre-check now runs natively on Windows
  instead of being skipped. The no-op stub remains for other
  platforms.
- pkg/backend/build: getFileMetadata asserted *syscall.Stat_t, which
  does not exist on Windows. Move the UID/GID lookup into fileOwner,
  implemented for unix and returning zero IDs elsewhere. The test now
  derives the expected owner per platform as well.
- cmd/login: terminal.ReadPassword(syscall.Stdin) does not compile on
  Windows, where syscall.Stdin is a Handle. Use int(os.Stdin.Fd()).

Add a CI job that cross-compiles and vets the module (including tests)
for windows/amd64 to prevent regressions.

Fixes modelpack#520

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Windows support for disk-space pre-check and other Unix-only packages

1 participant