mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Codegen/profile options in configuration

Open jedbrown opened this issue 11 months ago • 0 comments

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

jedbrown avatar Mar 14 '24 17:03 jedbrown