rust-lang / rust-lang/mdBook

Codegen/profile options in configuration

Open
#2,337 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

I'd like to use mdbook test on a book that uses #![feature(autodiff)] (an approved MCP being implemented to hopefully land on nightly later this year). This feature requires -C lto=fat. I hacked mdBook with the following and it works, but I'd like a change that can be upstreamed.

diff --git i/src/book/mod.rs w/src/book/mod.rs
index c0ab8a5..409482f 100644
--- i/src/book/mod.rs
+++ w/src/book/mod.rs
@@ -319,7 +319,11 @@ impl MDBook {
                 tmpf.write_all(ch.content.as_bytes())?;
 
                 let mut cmd = Command::new("rustdoc");
-                cmd.arg(&path).arg("--test").args(&library_args);
+                cmd.arg(&path)
+                    .arg("--test")
+                    .args(&library_args)
+                    .arg("-C")
+                    .arg("lto=fat");
 
                 if let Some(edition) = self.config.rust.edition {
                     match edition {
Proposed Solution

I see rustdoc is invoked directly, not via cargo, so the concept of cargo profiles does not directly apply. The narrowest solution would be to support the following as a special case

[rust]
lto = "fat"

More generally, we could have

[rust.codegen]
lto = "fat"

where all the key-values are passed along with rustdoc -C (--codegen).
A more comprehensive approach might be to invoke cargo rustdoc and thereby be able to use cargo profiles.

Which of these (or an alternative) would the maintainers prefer?

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/book/mod.rs at the rustdoc invocation used by mdBook test, then inspect the Rust configuration structures and related tests. Compare the proposed [rust] and [rust.codegen] shapes with the existing command construction; done means an agreed configuration design is implemented and verified for passing codegen options to rustdoc.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.