bazelbuild / bazelbuild/rules_rust
mdbook preprocessor written as a `py_binary` is silently skipped
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
**Description**
I have an `mdbook` target whose preprocessor is a `py_binary` listed in `plugins`. The build succeeds, but the preprocessor never runs: the marker it should expand is left unchanged, and nothing appears in the build log to say so.
**Reproduction steps**
`MODULE.bazel`
```python
module(name = "repro", version = "0.0.0")
bazel_dep(name = "rules_rust_mdbook", version = "0.73.0")
bazel_dep(name = "rules_python", version = "2.2.0")
```
`BUILD.bazel`
```python
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_rust_mdbook//:defs.bzl", "mdbook")
py_binary(
name = "mdbook_secret",
srcs = ["mdbook_secret.py"],
data = ["secret.txt"],
)
mdbook(
name = "book",
srcs = glob(["src/**/*.md"]),
book = "book.toml",
plugins = [":mdbook_secret"],
)
```
`book.toml`
```toml
[book]
title = "Plugin Runfiles Repro"
src = "src"
[preprocessor.secret]
command = "mdbook_secret"
```
`mdbook_secret.py`
```python
#!/usr/bin/env python3
"""Replaces {{secret}} with the contents of a data file."""
import json
import sys
from pathlib import Path
SECRET = Path(__file__).parent / "secret.txt"
def main() -> None:
if len(sys.argv) > 1 and sys.argv[1] == "supports":
sys.exit(0)
secret = SECRET.read_text().strip()
_context, book = json.load(sys.stdin)
for section in book["sections"]:
chapter = section.get("Chapter")
if chapter:
chapter["content"] = chapter["content"].replace("{{secret}}", secret)
print(json.dumps(book))
if __name__ == "__main__":
main()
```
`secret.txt`
```
42
```
`src/SUMMARY.md`
```markdown
# Summary
- [Chapter 1](./chapter_1.md)
```
`src/chapter_1.md`
```markdown
# Chapter 1
The secret is: {{secret}}.
```
Then:
```sh
$ bazel build //:book
INFO: Build completed successfully
$ grep -o "The secret is: [^<]*" bazel-bin/book/chapter_1.html
The secret is: {{secret}}.
```
**Bazel and rules_rust version**
Bazel version: 8.7.0
rules_python version 2.2.0
rules_rust_mdbook version: 0.73.0
Contributor guide
Research direction
Start with the mdbook rule loaded from @rules_rust_mdbook//:defs.bzl and trace how the plugins attribute handles the py_binary target and its executable. Reproduce the issue with the provided MODULE.bazel, BUILD.bazel, book.toml, and sample files; done means the preprocessor expands {{secret}} to 42 and the build output reflects the expansion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100