Skip to content

Commit 9532dbc

Browse files
committed
book.tom.l must configure path to Cargo.toml, not just root folder of project: changed config rust.package-dir to rust.manifest
1 parent 1703aa1 commit 9532dbc

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

guide/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ language = "en"
66

77
[rust]
88
## not needed, and will cause an error, if using Cargo.toml: edition = "2021"
9-
package-dir = "."
9+
manifest = "Cargo.toml"
1010

1111
[output.html]
1212
smart-punctuation = true

src/book/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ impl MDBook {
309309
// get extra args we'll need for rustdoc, if config points to a cargo project.
310310

311311
let mut extern_args = ExternArgs::new();
312-
if let Some(package_dir) = &self.config.rust.package_dir {
313-
extern_args.load(&package_dir)?;
312+
if let Some(manifest) = &self.config.rust.manifest {
313+
extern_args.load(&manifest)?;
314314
}
315315

316316
let mut failed = false;

src/cmd/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn make_subcommand() -> Command {
2828
.value_parser(NonEmptyStringValueParser::new())
2929
.action(ArgAction::Append)
3030
.help(
31-
"A comma-separated list of directories to add to the crate \
31+
"[deprecated] A comma-separated list of directories to add to the crate \
3232
search path when building tests",
3333
),
3434
)

src/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ impl Default for BuildConfig {
497497
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
498498
#[serde(default, rename_all = "kebab-case")]
499499
pub struct RustConfig {
500-
/// Path to a Cargo package
501-
pub package_dir: Option<PathBuf>,
500+
/// Path to a Cargo.toml
501+
pub manifest: Option<PathBuf>,
502502
/// Rust edition used in playground
503503
pub edition: Option<RustEdition>,
504504
}
@@ -801,7 +801,7 @@ mod tests {
801801
use-default-preprocessors = true
802802
803803
[rust]
804-
package-dir = "."
804+
manifest = "./Cargo.toml"
805805
806806
[output.html]
807807
theme = "./themedir"
@@ -845,7 +845,7 @@ mod tests {
845845
extra_watch_dirs: Vec::new(),
846846
};
847847
let rust_should_be = RustConfig {
848-
package_dir: Some(PathBuf::from(".")),
848+
manifest: Some(PathBuf::from("./Cargo.toml")),
849849
edition: None,
850850
};
851851
let playground_should_be = Playground {
@@ -926,7 +926,7 @@ mod tests {
926926
assert_eq!(got.book, book_should_be);
927927

928928
let rust_should_be = RustConfig {
929-
package_dir: None,
929+
manifest: None,
930930
edition: Some(RustEdition::E2015),
931931
};
932932
let got = Config::from_str(src).unwrap();
@@ -946,7 +946,7 @@ mod tests {
946946
"#;
947947

948948
let rust_should_be = RustConfig {
949-
package_dir: None,
949+
manifest: None,
950950
edition: Some(RustEdition::E2018),
951951
};
952952

@@ -967,7 +967,7 @@ mod tests {
967967
"#;
968968

969969
let rust_should_be = RustConfig {
970-
package_dir: None,
970+
manifest: None,
971971
edition: Some(RustEdition::E2021),
972972
};
973973

src/utils/extern_args.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Get "compiler" args from cargo
22
33
use crate::errors::*;
4+
use anyhow::anyhow;
45
use cargo_manifest::{Edition, Manifest, MaybeInherited::Local};
56
use log::{debug, info};
67
use std::fs;
@@ -27,9 +28,9 @@ use std::process::Command;
2728
///
2829
/// # fn main() -> Result<()> {
2930
/// // Get cargo to say what the compiler args need to be...
30-
/// let proj_root = std::env::current_dir()?; // or other path to `Cargo.toml`
31+
/// let manifest_file = std::env::current_dir()?.join("Cargo.toml"); // or other path to `Cargo.toml`
3132
/// let mut extern_args = ExternArgs::new();
32-
/// extern_args.load(&proj_root)?;
33+
/// extern_args.load(&manifest_file)?;
3334
///
3435
/// // then, when actually invoking rustdoc or some other compiler-like tool...
3536
///
@@ -61,11 +62,14 @@ impl ExternArgs {
6162
/// Run a `cargo build` to see what args Cargo is using for library paths and extern crates.
6263
/// Touch a source file in the crate to ensure something is compiled and the args will be visible.
6364
64-
pub fn load(&mut self, proj_root: &Path) -> Result<&Self> {
65+
pub fn load(&mut self, cargo_path: &Path) -> Result<&Self> {
6566
// find Cargo.toml and determine the package name and lib or bin source file.
66-
let cargo_path = proj_root.join("Cargo.toml");
67+
let proj_root = cargo_path
68+
.canonicalize()?
69+
.parent()
70+
.ok_or(anyhow!("can't find parent of {:?}", cargo_path))?.to_owned();
6771
let mut manifest = Manifest::from_path(&cargo_path)?;
68-
manifest.complete_from_path(proj_root)?; // try real hard to determine bin or lib
72+
manifest.complete_from_path(&proj_root)?; // try real hard to determine bin or lib
6973
let package = manifest
7074
.package
7175
.expect("doctest Cargo.toml must include a [package] section");
@@ -75,7 +79,7 @@ impl ExternArgs {
7579
self.edition = if let Some(Local(edition)) = package.edition {
7680
my_display_edition(edition)
7781
} else {
78-
"".to_owned() //
82+
"".to_owned() //
7983
};
8084

8185
debug!(
@@ -91,7 +95,7 @@ impl ExternArgs {
9195
let try_path: PathBuf = proj_root.join("src").join(fname);
9296
if try_path.exists() {
9397
touch(&try_path)?;
94-
self.run_cargo(proj_root, &cargo_path)?;
98+
self.run_cargo(&proj_root, &cargo_path)?;
9599
return Ok(self);
96100
// file should be closed when f goes out of scope at bottom of this loop
97101
}

0 commit comments

Comments
 (0)