Skip to content

Fix Stardoc in repos which use rules_go with Bazel 8+#4446

Merged
fmeum merged 4 commits intobazel-contrib:masterfrom
tetromino:stardoc
Sep 11, 2025
Merged

Fix Stardoc in repos which use rules_go with Bazel 8+#4446
fmeum merged 4 commits intobazel-contrib:masterfrom
tetromino:stardoc

Conversation

@tetromino
Copy link
Copy Markdown
Contributor

Fixes #4394

Requires bumping rules_cc dep (and making it a dep for legacy WORKSPACE users).

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

Fixes Stardoc API doc generation when using Bazel 8 for .bzl files in repos which transitively depend upon rules_go

Which issues(s) does this PR fix?

Fixes #4394 and bazelbuild/stardoc#300

Other notes for review

You can test the code via

cd ..
mkdir test
cd test
cat >MODULE.bazel <<EOF
bazel_dep(name = "rules_go", version = "0.57.0")
local_path_override(module_name = "rules_go", path = "../rules_go")
bazel_dep(name = "stardoc", version = "0.8.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
EOF

cat >BUILD <<EOF
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"],
)
EOF

cat >my_rule.bzl <<EOF
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
    )
EOF

bazelisk build my_rule_docs

Do you want an integration test in rules_go which does this? I didn't add one because I didn't want to introduce a new dependency on Stardoc or mess with existing .bazelversion files.

Fixes bazel-contrib#4394

Requires bumping rules_cc dep (and making it a dep for legacy WORKSPACE users).
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @tetromino, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical compatibility issue where Stardoc failed to generate API documentation for rules_go projects when using Bazel 8+. The fix involves updating the rules_cc dependency and ensuring its proper declaration across both MODULE.bazel and WORKSPACE environments, thereby providing the necessary build toolchain information for Stardoc to function correctly.

Highlights

  • Stardoc Compatibility Fix: Resolves an issue preventing Stardoc API documentation generation in repositories that use rules_go with Bazel 8+.
  • Dependency Update: The rules_cc dependency has been updated to version 0.2.5 to ensure compatibility and provide necessary toolchain information.
  • Legacy WORKSPACE Support: Explicitly adds rules_cc as a dependency for projects still using the legacy WORKSPACE file, ensuring consistent behavior across Bazel versions.
  • Build Rule Dependencies: A direct dependency on @rules_cc//cc:find_cc_toolchain_bzl was added to go/private/BUILD.bazel to resolve transitive dependency issues related to toolchain discovery.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the Stardoc generation issue with Bazel 8+ by explicitly adding rules_cc as a dependency. The changes are consistently applied for both bzlmod and legacy WORKSPACE users. My feedback focuses on improving maintainability by adding comments to explain the new dependencies.

Avoids the rules_cc compatibility_proxy_repo mess (which makes WORKSPACE use
difficult - will solve it when we need it) but is sufficiently new for
Stardoc to still work.
@fmeum fmeum enabled auto-merge (squash) September 11, 2025 19:07
@fmeum fmeum merged commit 0683029 into bazel-contrib:master Sep 11, 2025
1 check 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/private:context bzl_library is missing transitive dep on @rules_cc//cc:find_cc_toolchain.bzl - breaks Stardoc users

2 participants