Skip to content

Conversation

knqyf263
Copy link

@knqyf263 knqyf263 commented Oct 7, 2025

Summary

  • Move build tags to the beginning of files, before copyright headers
  • Add new //go:build syntax alongside legacy // +build syntax for compatibility

Problem

Build tags were placed after copyright headers, causing them to be ignored by the Go compiler. This resulted in Windows cross-compilation errors where both os_posix.go and os_windows.go were compiled together, leading to duplicate declarations:

GOOS=windows go build .
# github.com/joelanford/go-apidiff/pkg/diff/internal/osfs
pkg/diff/internal/osfs/os_windows.go:50:16: method file.Lock already declared at pkg/diff/internal/osfs/os_posix.go:29:16
pkg/diff/internal/osfs/os_windows.go:65:16: method file.Unlock already declared at pkg/diff/internal/osfs/os_posix.go:36:16
pkg/diff/internal/osfs/os_windows.go:77:6: rename redeclared in this block

Solution

According to Go's build tag specification, build constraints must be placed at the beginning of the file before any other comments. This fix moves the build tags to the proper location.

Build tags must be placed at the beginning of the file, before any
other comments including copyright headers. This fixes Windows cross-
compilation errors where both os_posix.go and os_windows.go were being
compiled together, causing duplicate declarations.
@knqyf263 knqyf263 marked this pull request as ready for review October 7, 2025 05:54
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.

1 participant