Skip to content

bzlmod: allow non-default go.work file names#2303

Merged
jayconrod merged 1 commit intobazel-contrib:masterfrom
findleyr:allow-custom-go-work-name
Mar 12, 2026
Merged

bzlmod: allow non-default go.work file names#2303
jayconrod merged 1 commit intobazel-contrib:masterfrom
findleyr:allow-custom-go-work-name

Conversation

@findleyr
Copy link
Copy Markdown
Contributor

The go command accepts any file as a workspace file via the GOWORK environment variable, and writes checksums to a sibling file with a .sum suffix (e.g. GOWORK=go.bazel.work produces go.bazel.work.sum).

go_deps.from_file(go_work = ...) currently rejects any name other than go.work, and hardcodes go.work.sum as the sum file name. This is stricter than the go command itself. Notably, go_work_from_label already accepts any name; only the sum-file path checks.

Remove the name check and derive the sum file name from the work file name.

A non-default name is useful when a repository wants a Bazel-only workspace that the go toolchain won't auto-discover (the toolchain walks up directories looking specifically for go.work), so native go builds remain unaffected by the Bazel workspace configuration.

What type of PR is this?

Bug fix

What package or component does this PR mostly affect?

go_repository

What does this PR do? Why is it needed?

Which issues(s) does this PR fix?

Fixes #2302

Other notes for review

The go command accepts any file as a workspace file via the GOWORK
environment variable, and writes checksums to a sibling file with
a .sum suffix (e.g. GOWORK=go.bazel.work produces go.bazel.work.sum).

go_deps.from_file(go_work = ...) currently rejects any name other
than go.work, and hardcodes go.work.sum as the sum file name. This
is stricter than the go command itself. Notably, go_work_from_label
already accepts any name; only the sum-file path checks.

Remove the name check and derive the sum file name from the work
file name.

A non-default name is useful when a repository wants a Bazel-only
workspace that the go toolchain won't auto-discover (the toolchain
walks up directories looking specifically for go.work), so native
go builds remain unaffected by the Bazel workspace configuration.
@findleyr
Copy link
Copy Markdown
Contributor Author

CC @jayconrod @achew22

Copy link
Copy Markdown
Contributor

@jayconrod jayconrod left a comment

Choose a reason for hiding this comment

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

Thanks for fixing! I'd completely forgotten that GOWORK could be used to set the work file name.

@jayconrod jayconrod merged commit 40c2c73 into bazel-contrib:master Mar 12, 2026
15 checks passed
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.

go_deps.from_file(go_work=...) rejects non-default go.work file names

2 participants