)]}'
{
  "commit": "dfabfe9ab146aef567cb37284817de571a78e6ff",
  "tree": "bc2d2ee2d92257efabfbef612b7e992128df084c",
  "parents": [
    "fcc41bbe67d83d3cd388890ff7c872832944347c"
  ],
  "author": {
    "name": "Teo Koon Peng",
    "email": "teokoonpeng@gmail.com",
    "time": "Sat Apr 18 15:04:50 2026 +0800"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Sat Apr 18 07:04:50 2026 +0000"
  },
  "message": "gopackagesdriver: fix missing cgo files when RBE is used (#4589)\n\nBug fix #4588\n\nWe notice in our codebase that gopls fails to index some files. The\ngopackagesdriver logs show this error:\n\n```\nerror: unable to load JSON files: unable to resolve imports: open \u003comitted\u003e/_cgo_gotypes.go: no such file or directory\n```\n\nI feed the error to gemini and it proposed this:\n\n\u003cdetails\u003e\n\n\u003csummary\u003eGemini report\u003c/summary\u003e\n\n## Root Cause\n\nThe root cause lies within the `rules_go` Bazel ruleset, specifically in\nthe `go_pkg_info_aspect` aspect located at\n`go/tools/gopackagesdriver/aspect.bzl`.\n\nTo understand the issue, it is helpful to understand a few key concepts\nin this workflow:\n* **`pkg.json`**: A metadata file generated by the `go_pkg_info_aspect`\naspect for each Go target. It contains structured information (like\ndependencies, source files, and import paths) that `gopackagesdriver`\nuses to inform `gopls` about how the package is constructed.\n* **`compiled_go_files`**: A list within the aspect\u0027s provider that\ntracks all the Go source files destined for compilation. In Bazel,\nexposing these files in an output group (like `go_pkg_driver_srcs`)\ntells the build system that it must actually execute the actions to\ngenerate these files before the build command finishes.\n* **`cgo_out_dir`**: The output directory containing intermediate Go\nfiles generated by the `cgo` tool (such as `_cgo_gotypes.go` and\n`_cgo_export.go`). These files are generated from C/C++ sources or Go\nfiles containing `import \"C\"`.\n\nWhen the aspect processes a `go_test` target, it traverses the\ndependencies to find the archive containing the test sources. While it\ncorrectly generates the `pkg.json` metadata file pointing to the\ngenerated `cgo` output files within the `cgo_out_dir`, it forgot to add\nthe `cgo_out_dir` to the list of `compiled_go_files`.\n\nBecause `cgo_out_dir` was omitted from `compiled_go_files` (which maps\nto the `go_pkg_driver_srcs` output group), Bazel did not guarantee that\nthe `cgo` outputs were actually built and present on disk before\ncompleting the aspect execution. When `gopls` then parsed the `pkg.json`\nand attempted to read the generated source files, they were missing,\nresulting in the error.\n\n## Resolution\n\nThe issue was resolved by patching `rules_go` to ensure that\n`cgo_out_dir` is correctly added to `compiled_go_files` when processing\n`go_test` dependencies.\n\n```diff\ndiff --git a/go/tools/gopackagesdriver/aspect.bzl b/go/tools/gopackagesdriver/aspect.bzl\nindex dbe5663..8dc7d3e 100644\n--- a/go/tools/gopackagesdriver/aspect.bzl\n+++ b/go/tools/gopackagesdriver/aspect.bzl\n@@ -108,6 +108,8 @@ def _go_pkg_info_aspect_impl(target, ctx):\n                 if archive.data.label \u003d\u003d dep_archive.data.label:\n                     pkg_json_files.append(make_pkg_json_with_archive(ctx, dep_archive.data.name, dep_archive))\n                     compiled_go_files.extend(dep_archive.source.srcs)\n+                    if dep_archive.data.cgo_out_dir:\n+                        compiled_go_files.append(dep_archive.data.cgo_out_dir)\n                     export_files.append(dep_archive.data.export_file)\n                     break\n \n```\n\n\u003c/details\u003e\n\nI don\u0027t fully understand the root cause but the proposed fix is working\nfor us. Does the fix make sense?\n\nSigned-off-by: Teo Koon Peng \u003ckoonpeng@google.com\u003e\nCo-authored-by: Fabian Meumertzheim \u003cfabian@meumertzhe.im\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "dbe56633c658a6bc5467ec26c4e3360303e13c74",
      "old_mode": 33188,
      "old_path": "go/tools/gopackagesdriver/aspect.bzl",
      "new_id": "8dc7d3e243665f860db008ba8d5a60152e7d590a",
      "new_mode": 33188,
      "new_path": "go/tools/gopackagesdriver/aspect.bzl"
    }
  ]
}
