-
Notifications
You must be signed in to change notification settings - Fork 50
missing bzl_library target for find_cc_toolchain.bzl if .bzl file being documented transitively loads rules_go #300
Description
Problem
If the .bzl file that we're generating documentation for imports rules_cc or anything that imports rules_cc, then stardoc is unable to generate documentation for any of these rules with the error:
ERROR: /Users/abhinav/src/stardoc-repro/BUILD.bazel:11:8: in deps attribute of starlark_doc_extract rule //:my_rule_docs.extract: missing bzl_library targets for Starlark module(s) @@rules_cc+//cc:find_cc_toolchain.bzl. Since this rule was created by the macro 'stardoc', the error might have been caused by the macro implementation
ERROR: /Users/abhinav/src/stardoc-repro/BUILD.bazel:11:8: Analysis of target '//:my_rule_docs.extract' failed
Specifically:
missing bzl_library targets for Starlark module(s) @@rules_cc+//cc:find_cc_toolchain.bzl
Reproduction
-- MODULE.bazel --
bazel_dep(name = "rules_go", version = "0.55.1")
bazel_dep(name = "stardoc", version = "0.8.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
-- BUILD.bazel --
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@stardoc//stardoc:stardoc.bzl", "stardoc")
bzl_library(
name = "my_rule",
srcs = ["my_rule.bzl"],
visibility = ["//visibility:public"],
deps = ["@rules_go//go:def"],
)
stardoc(
name = "my_rule_docs",
out = "my_rule.md",
input = "my_rule.bzl",
deps = [":my_rule"],
)
-- my_rule.bzl --
load("@rules_go//go:def.bzl", "go_test")
def go_helper_test(name, **kwargs):
"""A helper function to create a Go test target with specific attributes."""
go_test(
name = name,
srcs = ["test_helper.go"],
embed = [":helper_lib"],
**kwargs
)
bazel build :my_rule_docs fails with the above setup, but works if we drop the go_test import in my_rule.
Related issue
While this is probably an issue with rules_cc (bazelbuild/rules_cc#279), these targets definitely exist in the latest release: https://github.com/bazelbuild/rules_cc/blob/3dce172deec2a4563c28eae02a8bb18555abafb2/cc/BUILD#L85-L89
However, the above fails even if you add one of the following to the MODULE.bazel.
bazel_dep(name = "rules_cc", version = "0.1.2")
# or
single_version_override(module_name = "rules_cc", version = "0.1.2")
Bazel version
This fails with Bazel 8.3.1.
It works with Bazel 7.6.1, even without the rules_cc upgrade.
Workaround
For the go_test case above, there's currently a workaround:
upgrade rules_cc and explicitly add those bzl targets as dependencies:
deps = [
":my_rule",
+ "@rules_cc//cc:find_cc_toolchain_bzl",
+ "@rules_cc//cc/common",
],