Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
25a3fb3
extern_args module to get proper compiler args from Cargo.
bobhy Dec 9, 2024
a166f21
Add config.rust.package-dir and fix cargo output parser (maybe not fo…
bobhy Dec 10, 2024
c926113
Force --extern <name>=<path>.rmeta to .rlib. Cargo sometimes tries t…
bobhy Dec 10, 2024
3eb20b3
Modify user guide so code samples can reference external crates.
bobhy Dec 10, 2024
96c2aee
Update guide to describe configuring book for external crates;
bobhy Dec 10, 2024
7b3a1e2
Fix CI nits.
bobhy Dec 10, 2024
138256f
Replace unstable fs::set_modified() with ad-hoc "touch" function.
bobhy Dec 11, 2024
3306d20
Fuzzy up touch file test in case sleep() is not totally precise.
bobhy Dec 11, 2024
d9d1f35
trigger rebuild if project has main.rs (but broken for other binary t…
bobhy Dec 12, 2024
6104051
Make guide into workspace child so it can share same dependencies wit…
bobhy Dec 14, 2024
cb77a89
When running build, pull dependencies from the build of the doctest c…
bobhy Dec 14, 2024
7fa966f
Compile, but do not run the preprocessor examples.
bobhy Dec 14, 2024
1703aa1
fix broken unit tests
bobhy Dec 14, 2024
9532dbc
book.tom.l must configure path to Cargo.toml, not just root folder of…
bobhy Dec 15, 2024
9cbd047
Doc changes to cover how to use external crates in doctests (and rela…
bobhy Dec 15, 2024
9c5dec2
fix fmt not caught locally
bobhy Dec 15, 2024
658221c
Document deprecating `mdbook test -L`
bobhy Dec 16, 2024
a3fc58b
fix `mdbook test <path/to/root>;
bobhy Dec 17, 2024
d62904b
revert pulldown-cmark from 0.12.2 to 0.10.0 (sigh)
bobhy Dec 17, 2024
b2eb96c
finalize doc updates for new feature
bobhy Dec 17, 2024
248f490
All doctests in mdbook project now pass.
bobhy Dec 17, 2024
38c8f5b
Provide error context if can't find or open Cargo.toml;
bobhy Dec 18, 2024
ab5b3ab
Fix unintended change, per review
bobhy Jan 2, 2025
730e11c
fix clippy nags in files I changed
bobhy Jan 2, 2025
c209369
fix unit test failure
bobhy Jan 2, 2025
19859b0
Try to merge (it's been a while)
bobhy Nov 8, 2025
b9be9bc
Migrate changes for ExternArgs from root to crates mdbook-core and md…
bobhy Nov 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Provide error context if can't find or open Cargo.toml;
Prefer edition setting from Cargo.toml over book.toml; sadly, Cargo also overrides command line.
  • Loading branch information
bobhy committed Dec 18, 2024
commit 38c8f5bfee00502641b984116a053d5b0a537f87
7 changes: 6 additions & 1 deletion src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ impl MDBook {
.args(&library_args) // also need --extern for doctest to actually work
.args(extern_args.get_args());

if let Some(edition) = self.config.rust.edition {
// rustdoc edition from cargo manifest takes precedence over book.toml
// bugbug but also takes precedence over command line flag -- that seems rude.
if extern_args.edition != "" {
cmd.args(["--edition", &extern_args.edition]);
} else if let Some(edition) = self.config.rust.edition {
match edition {
RustEdition::E2015 => {
cmd.args(["--edition", "2015"]);
Expand All @@ -361,6 +365,7 @@ impl MDBook {
}
}

// bugbug Why show color in hidden invocation of rustdoc?
if color_output {
cmd.args(["--color", "always"]);
}
Expand Down
23 changes: 15 additions & 8 deletions src/utils/extern_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ use std::process::Command;

#[derive(Debug)]
pub struct ExternArgs {
edition: String, // where default value of "" means arg wasn't specified
crate_name: String,
/// rust edition as specified in manifest
pub edition: String, // where default value of "" means arg wasn't specified
/// crate name as specified in manifest
pub crate_name: String,
// accumulated library path(s), as observed from live cargo run
lib_list: Vec<String>,
// explicit extern crates, as observed from live cargo run
extern_list: Vec<String>,
}

Expand All @@ -65,11 +69,18 @@ impl ExternArgs {
pub fn load(&mut self, cargo_path: &Path) -> Result<&Self> {
// find Cargo.toml and determine the package name and lib or bin source file.
let proj_root = cargo_path
.canonicalize()?
.canonicalize()
.context(format!(
"can't find cargo manifest {}",
&cargo_path.to_string_lossy()
))?
.parent()
.ok_or(anyhow!("can't find parent of {:?}", cargo_path))?
.to_owned();
let mut manifest = Manifest::from_path(&cargo_path)?;
let mut manifest = Manifest::from_path(&cargo_path).context(format!(
"can't open cargo manifest {}",
&cargo_path.to_string_lossy()
))?;
manifest.complete_from_path(&proj_root)?; // try real hard to determine bin or lib
let package = manifest
.package
Expand Down Expand Up @@ -204,10 +215,6 @@ impl ExternArgs {
/// provide the parsed external args used to invoke rustdoc (--edition, -L and --extern).
pub fn get_args(&self) -> Vec<String> {
let mut ret_val: Vec<String> = vec![];
if self.edition != "" {
ret_val.push("--edition".to_owned());
ret_val.push(self.edition.clone());
};
for i in &self.lib_list {
ret_val.push("-L".to_owned());
ret_val.push(i.clone());
Expand Down