Skip to content

Cleanup path-mapping enablement#4441

Merged
fmeum merged 1 commit into
bazel-contrib:masterfrom
dzbarsky:zbarsky/context2
Sep 4, 2025
Merged

Cleanup path-mapping enablement#4441
fmeum merged 1 commit into
bazel-contrib:masterfrom
dzbarsky:zbarsky/context2

Conversation

@dzbarsky

@dzbarsky dzbarsky commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

What type of PR is this?
code cleanup

What does this PR do? Why is it needed?
This enables path-mapping for the GoInfo action and simplifies the builder_args. As a side effect, we now set the -goroot flag for link actions but they do not yet opt into path mapping (and I don't think they will work yet, since they use .path on the archives)

Which issues(s) does this PR fix?

Fixes #

Other notes for review

@fmeum fmeum enabled auto-merge (squash) September 4, 2025 20:16
@fmeum fmeum merged commit 2d297e9 into bazel-contrib:master Sep 4, 2025
1 check passed
fmeum pushed a commit that referenced this pull request Apr 7, 2026
Since #4441, the
`GoStdlibList` action uses `SUPPORTS_PATH_MAPPING_REQUIREMENT` and
passes the cache directory via `add_all` (which enables path mapping).
This causes the stdlib builder to write path-mapped directory names
(e.g. `bazel-out/cfg/`) into `stdlib.pkg.json`. The gopackagesdriver
then reads these paths at runtime to open source files, but the mapped
directory doesn't exist on disk — the actual files are under the real
config directory (e.g. `bazel-out/k8-fastbuild/`).

This breaks the gopackagesdriver for any Go target:

```
error: unable to resolve imports: open .../bazel-out/cfg/bin/external/io_bazel_rules_go/stdlib_/gocache/...: no such file or directory
```

Affected stdlib packages are those with CGO-compiled files (`net`,
`os/user`, `internal/runtime/cgobench`, etc.) whose `CompiledGoFiles`
reference gocache entries under the mapped path.

**Fix:** Unlike the stdlib build action (`_build_stdlib`), the
`GoStdlibList` action produces `stdlib.pkg.json` which is consumed at
runtime by the gopackagesdriver — not by Bazel. Path mapping is not
appropriate here because the mapped paths are never resolved back to
real paths before being read. Revert to using `cache_dir.path` (real
filesystem path) and remove `SUPPORTS_PATH_MAPPING_REQUIREMENT` from
this action only.

This PR is an alternative to
#4584 which tried to
resolve this at the gopackagesdriver but that solution was deemed
brittle.
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.

2 participants