Skip to content

Bazel backdating#3223

Draft
mgeisler wants to merge 3 commits into
mainfrom
bazel-backdating
Draft

Bazel backdating#3223
mgeisler wants to merge 3 commits into
mainfrom
bazel-backdating

Conversation

@mgeisler

Copy link
Copy Markdown
Collaborator

Hey @qwandor and @djmitche, this is a WIP of where I'm taking the project. On this branch,

% bazel build :da
# ...
Target //:da up-to-date:
  bazel-bin/da_html
  bazel-bin/da_pandoc

produces a Danish book!

I've been spinning off small bits and pieces of this WIP commit over the last few weeks in the PRs you've reviewed.

mgeisler added 3 commits June 25, 2026 22:41
This moves the remaining two tools into Bazel: `i18n-report` and
`mdbook` itself. They are still installed with

    cargo xtask install-tools

to make this less disruptive. This will go away as we start using the
`mdbook` rule in Bazel to build the many books.
This ensures that future use of the `mdbook` rule will use `mdbook`
version 5.0.3 to match #3207.
bazel: add repository rule to generate per-renderer book.toml

When `mdbook` is running, it renders output for each of the `output`
keys. This happens sequentially and we need different output for
different cases:

| Renderer     | English | Translations | Use Case                    |
| ------------ | ------- | ------------ | --------------------------- |
| `html`       | ✓       | ✓            | Website HTML output         |
| `pandoc`     | ✓       | ✓            | PDF generation              |
| `exerciser`  | ✓       | ✗            | Exercise starter code       |
| `xgettext`   | ✓       | ✗            | `.pot` file for translators |
| `linkcheck2` | ✓       | ✗            | Link validation in CI       |

This little repository rule is a step towards this: it lets us trim
the `book.toml` file down to the renderers we want to each case. We
can thus keep maintaining the overall set of renderers in the checked
in `book.toml` file, and then select a subset of the settings at build
time.
@mgeisler

Copy link
Copy Markdown
Collaborator Author

From this infrastructure, it's a small step to make a :website target which builds all known languages, puts them into the correct sub-directory and voila, we can now move all logic out of shell scripts and YAML files (and into .bzl files).

The complexity is still there... but it's now suddenly in a form that allows us to reproduce things locally that we could not really do easily today.

Comment thread backdated_sources.bzl
# Patch language-specific settings.
book["book"]["language"] = lang
book["output"]["html"]["site-url"] = "/comprehensive-rust/{}/".format(lang)
book["output"]["html"].pop("redirect", None)

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.

is that removing the redirects completely? In my understanding this is necessary to be kept at the state at which it was backdated.

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.

Hey @michael-kerscher, it removes them just like we do today in build.sh:

# TODO: Clearing the redirects is no longer necessary since we restore book.toml.
export MDBOOK_BOOK__LANGUAGE=$book_lang
export MDBOOK_OUTPUT__HTML__SITE_URL=/comprehensive-rust/$book_lang/
export MDBOOK_OUTPUT__HTML__REDIRECT='{}'

But as the comment says, we might not need to do this?

My gut feeling would be that we should not expect translators to know about or maintain redirects. But I guess they get them from free via updates to main, so yeah, we could stop clearing them.

That would be a change in functionality and so far I've only aimed at re-creating our current workflow, but in Bazel.

Comment thread backdated_sources.bzl
book["output"]["html"].pop("redirect", None)

book["output"].pop("linkcheck", None)
book["output"].pop("linkcheck2", None)

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.

When we are modifying the entire file alrready, should we care about the linkcheck2 results? #2996 - this would have been avoidable or at least we could have fixed the translations if linkcheck2 would have been enabled

Comment thread backdated_sources.bzl
load("@toml.bzl", "toml")
load("@yaml.bzl", "yaml")

def _book_sources_repo_impl(repository_ctx):

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.

this function has a high mental load. I would prefer to split that into multiple rules. Maybe we could even separate some build rules and depend on them here. e.g. the archive.tar.gz creation, the config (book.toml) modification and reassembly

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 agree that there is a lot going on! I have oscillated between having things more split and more centralized... the version here is more centralized.

I found that the split versions were complicated because of another reason: they would have implicit dependencies between different files and rules. So one rule would register a @backdated_sources//:da_srcs and another rule in another file would use this... that's (also) not nice.

@mgeisler

Copy link
Copy Markdown
Collaborator Author

Hey folks, just a note that this PR was only for demonstration so you could get a feeling for what I've been experimenting with over the last few months.

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