Skip to content

bazel: migrate external mdbook plugins to Bazel#3202

Merged
mgeisler merged 1 commit into
mainfrom
bazel-all-mdbook-plugins
Jun 16, 2026
Merged

bazel: migrate external mdbook plugins to Bazel#3202
mgeisler merged 1 commit into
mainfrom
bazel-all-mdbook-plugins

Conversation

@mgeisler

Copy link
Copy Markdown
Collaborator

Configure mdbook-i18n-helpers, mdbook-linkcheck2, mdbook-pandoc, and mdbook-svgbob as Bazel external plugins using rules_rust.

Update xtask/src/main.rs to build all preprocessor tools via Bazel, programmatically resolve their paths, copy them to ~/.cargo/bin.

This is a drop-in replacement for the old Cargo based approach. It will go away as we move the mdbook build call itself to Bazel, but it's useful in its own since it establishes that we can build the mdbook plugins with Bazel.

@mgeisler mgeisler requested a review from gribozavr June 10, 2026 10:13
@mgeisler mgeisler changed the title bazel: migrate external mdbook plugins to Bazel bazel: Migrate external mdbook plugins to Bazel Jun 10, 2026
@mgeisler mgeisler force-pushed the bazel-all-mdbook-plugins branch 3 times, most recently from 9b22ef6 to 7247cc3 Compare June 10, 2026 16:04
@mgeisler mgeisler requested a review from qwandor June 10, 2026 16:04
@mgeisler mgeisler force-pushed the bazel-all-mdbook-plugins branch from 7247cc3 to 03b642a Compare June 14, 2026 10:16
@mgeisler mgeisler changed the title bazel: Migrate external mdbook plugins to Bazel bazel: migrate external mdbook plugins to Bazel Jun 14, 2026
@mgeisler

Copy link
Copy Markdown
Collaborator Author

Blocked on #3212.

Configure mdbook-i18n-helpers, mdbook-linkcheck2, mdbook-pandoc, and
mdbook-svgbob as Bazel external plugins using `rules_rust`.

Update `xtask/src/main.rs` to build all preprocessor tools via Bazel,
programmatically resolve their paths, copy them to `~/.cargo/bin`.

This is a drop-in replacement for the old Cargo based approach. It
will go away as we move the `mdbook build` call itself to Bazel, but
it's useful in its own since it establishes that we can build the
`mdbook` plugins with Bazel.
@mgeisler mgeisler force-pushed the bazel-all-mdbook-plugins branch from 03b642a to 207db0d Compare June 14, 2026 15:40
@mgeisler mgeisler requested a review from djmitche June 14, 2026 15:40
Comment thread MODULE.bazel
"2025-09-01/rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz": "b3c2d890d9405285e015ab4ceb78087e3ec55c64b0b3030d79102dfe5e622e09",
"2025-09-01/rustc-nightly-x86_64-unknown-linux-gnu.tar.xz": "7f5486ae6ece8a734149e5fce6dc8f1bcdcb36b5c5cb53a819569109b445c700",
},
version = "nightly/2025-09-01",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That was a few nights ago...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I know 😄 It's what we have hard-coded in main.rs. We should of course update it once in a while.

Comment thread MODULE.bazel
crate.from_specs(
name = "mdbook_plugins",
generate_binaries = True,
host_tools = "@rust_host_tools_nightly",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need to build these with the nightly toolchain? (Assuming that that is what this is saying.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I was asking myself (and Gemini) the same thing! What is happening here is that we want Bazel to run the equivalen to of cargo install.

It turns out that this isn't exposed in a stable way: there is a -Z bindeps flag (reference), but this requires a nightly compiler.

This is what rules_rust uses internally when we specify that we want the binary artifacts.

Comment thread MODULE.bazel
artifact = "bin",
package = "mdbook-pandoc",
repositories = ["mdbook_plugins"],
version = "0.11.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we configure Dependabot to update these dependencies too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually... I don't think it is supported. There is Dependabot support for Bazel modules, but the version number here is from crates.io and Bazel doesn't really know anything about it.

So I think we're in the same boat as before where this was hard-coded in main.rs.

Comment thread MODULE.bazel
use_repo(crate, "mdbook_plugins")

# mdbook-svgbob depends transitively on sauron-core, which has a
# "=0.3.30" dependency on futures. This conflicts with other plugins.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does Bazel not allow multiple versions of a library crate in the tree? That seems like a big difference from cargo that could relate in other issues in future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it is different. I've been playing with this for a few weeks now and what I've learnt is that

  • We had the same problem with cargo install, we just didn't know. When you cargo install foo, a small workspace is created on the fly and foo is compiled in that. Our different cargo install calls created different workspaces and could thus depend on whatever incompatible crate versions they like.

  • With the declarations here, we create a bigger workspace called mdbook_plugins and compile most mdbook plugins in this workspace. We thus save a little time since transitive dependencies are only compiled once.

  • We are creating multiple Bazel "repositories" with rules_rust: here mdbook_plugins and svgbob_plugin. We also have a repository called crates which is populated with the dependencies from our actual Cargo workspace via

    crate.from_cargo(
        name = "crates",
        cargo_lockfile = "//:Cargo.lock",
        manifests = ["//:Cargo.toml"],
    )
    use_repo(crate, "crates")

    This uses our Cargo.lock file and I believe this means that the same crate can be available in multiple different versions. I'm not 100% sure, though.

I hope this helps clarify things a little?

Comment thread xtask/src/main.rs
("mdbook-linkcheck2", "0.12.0"),
];
// Tools not yet migrated to be installed with Bazel.
let tools = [("mdbook", "0.5.3"), ("i18n-report", "0.2.0")];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why can't these be moved to Bazel at the same time?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, they could... I was just starting with the mdbook plugins to round off that part of the build.

I'll migrate everything eventually — and remove cargo xtask install-tools since everything will be installed/compiled on the fly with Bazel.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Being moved in #3215!

@mgeisler mgeisler merged commit 60de209 into main Jun 16, 2026
46 checks passed
@mgeisler mgeisler deleted the bazel-all-mdbook-plugins branch June 16, 2026 12:42
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.

3 participants