-
-
Notifications
You must be signed in to change notification settings - Fork 97
Open
Labels
type: feature requestNew feature or requestNew feature or request
Description
VS Code Bazel extension does not respect root toolchains / .bazelrc in multi-module bzlmod monorepos
Problem description
When using Bazel with bzlmod in a monorepo, each app or library is its own Bazel module (apps/appX/MODULE.bazel, modules/shared/MODULE.bazel, etc.).
The monorepo root also has a MODULE.bazel where all toolchains and the main .bazelrc are centralized.
Expected behavior
- The VS Code Bazel extension should treat the monorepo root as the single Bazel workspace root.
- All build/test/run actions (CodeLens, Test UI, right-click commands) should run Bazel from the repo root, so that:
- the root
.bazelrcis applied, - toolchains registered in the root
MODULE.bazelare available, - cross-module deps work (e.g.
@other_module//path:target), - labels are consistent (
//modules/transport/...:foo) rather than relative to a leaf folder.
- the root
Actual behavior
- The extension currently picks the nearest
MODULE.bazelor WORKSPACE file to the open file and treats that as the workspace root. - If I open
apps/app-go/src/main.goand run “Bazel: Build Target”, the extension runs Bazel inapps/app-go/.- Labels resolve relative to that folder (e.g.
//proto/...instead of//modules/transport/proto/...). - Toolchains defined in the root
MODULE.bazelare not registered. - The root
.bazelrcis ignored.
- Labels resolve relative to that folder (e.g.
- This makes cross-module builds/tests fail when triggered from VS Code, even though they succeed when run manually from the monorepo root.
Why this matters
- With bzlmod, the recommended monorepo structure is multiple modules with a root module that wires toolchains and overrides.
- IDE users (VS Code) expect Bazel commands to “just work” without having to
cdinto the root manually. - As of today, developers must either:
- open only the repo root in VS Code (which breaks per-app workspace setups), or
- duplicate toolchain registration and
.bazelrcin every leaf module (which defeats the purpose of centralization).
Steps to reproduce
- Create a monorepo with:
MODULE.bazel # root, toolchains + local_path_override
apps/app-go/MODULE.bazel # leaf module - Open
apps/app-go/in VS Code. - Run “Bazel: Build Target” on a file.
- Observe: Bazel runs from
apps/app-go/instead of the monorepo root, toolchains are missing, and labels resolve incorrectly.
Desired solution
- Provide a VS Code setting to force Bazel commands to run from the top-level workspace root (not the nearest).
- Example:
"bazel.workspaceRootMode": "repo-root-only". - Or auto-detect the “primary” root (the one containing
.git/andMODULE.bazel) instead of treating every nested module as independent. - At minimum, document that opening a leaf module as the VS Code workspace will break root toolchains/config.
Environment
- Bazel: 8.x with bzlmod enabled
- VS Code: latest
- Extension: vscode-bazel latest
- OS: Any
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: feature requestNew feature or requestNew feature or request