Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .cursor/rules/go_module_bazel_migration.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ Root `BUILD.bazel` defines `ALL_BUILD_TAGS`, passed to `gazelle` via `build_tags
- When **`bazel test` / `bazel build` fails** in a way that points to wrong or missing symbols from tag-gated sources — add the needed tags on that package’s `go_test` (and/or `go_library`) so the compiler enables the same constraints.
- When you follow the **`//go:build test`** pattern below (library sources with `test` in the build line) — use `gotags = ["test"] # keep` on the embedding `go_test`.
- For **k8s-style tags** (`kubeapiserver`, `kubelet`, etc.) — add `gotags` **per package** only when that package’s **sources or tests** are actually behind those `//go:build` lines (including tag-gated `*_test.go`). Do not add them speculatively to every test under a tree.
- For **OS-specific test files** (e.g. `poller_darwin_test.go`, `poller_linux_test.go`) that rely on the platform being set as a build tag — use a `select()` to pass the right OS tag at test time:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it, GOOS and GOARCH do it for us on the toolchain level. I ran the tests to confirm that this select is a no-op

@aiuto aiuto Apr 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the weird thing is that I see different behaviors.
Next time I get a pure windows library in a migration PR, I'll reduce it down to that as a demonstration
I'll move to draft for now.


```python
gotags = select({ # keep
"@platforms//os:linux": ["linux"],
"@platforms//os:macos": ["darwin"],
"@platforms//os:windows": ["windows"],
"//conditions:default": [],
}),
```

Reference: `pkg/util/flavor/BUILD.bazel` uses this pattern. Note that `gotags` controls which source files are compiled; it does **not** grant access to host binaries. If a test shells out to a host tool (e.g. `netstat`) that is absent from the Bazel sandbox, the `gotags` fix will not help — that requires a different approach (e.g. backing out the package).

## BUILD.bazel editing rules

Expand Down
Loading