victe / rust-latex-doc-minimal-example

35 stars 0 forks source link

Interaction of `rustdocflags` in `config.toml` and dependencies #1

Open JohnScience opened 2 years ago

JohnScience commented 2 years ago

Thank you so much for this wonderful repo!

I was trying to add a markdown file with LaTeX that I exported from evcxr Jupyter notebook (.ipynb) into a crate that had several dependencies. So far it seems that rustdocflags is invasive and applies to ALL crates for which rustdoc builds documentation. As a result, building documentation fails because as error suggests

error: error reading `./src/docs-header.html`: The system cannot find the path specified. (os error 3)

none of the crates-dependencies have docs-header.html in their ./src/ directory.

How to reproduce the error

The error can be reproduced by adding a dependency to Cargo.toml

[package]
name = "rust-latex-doc-minimal-example"
version = "0.2.0"
authors = ["Vicente Ramirez Perea <victe@ramper.net>"]
edition = "2018"
description = "Minimal crate example for getting latex in docs."
readme = "crates-io.md"
homepage = "https://github.com/victe/rust-latex-doc-minimal-example"
repository = "https://github.com/victe/rust-latex-doc-minimal-example"

license = "CC0-1.0"
categories = ["development-tools", "mathematics", "science"]
keywords = ["latex", "rustdoc", "docs"]

[dependencies]
num-traits = "0.2.14" # example of a dependency

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "./src/docs-header.html" ]

Output

PS C:\Users\demen\Documents\GitHub\rust-latex-doc-minimal-example> cargo doc
 Documenting num-traits v0.2.14
error: error reading `./src/docs-header.html`: The system cannot find the file specified. (os error 2)

error: could not document `num-traits`

Caused by:
  process didn't exit successfully: `rustdoc --crate-type lib --crate-name num_traits C:\Users\demen\.cargo\registry\src\github.com-1ecc6299db9ec823\num-traits-0.2.14\src\lib.rs --cap-lints allow -o C:\Users\demen\Documents\GitHub\rust-latex-doc-minimal-example\target\doc --cfg "feature=\"default\"" --cfg "feature=\"std\"" --error-format=json --json=diagnostic-rendered-ansi,future-incompat -C metadata=1018f75cfa6d9b1f -L dependency=C:\Users\demen\Documents\GitHub\rust-latex-doc-minimal-example\target\debug\deps --html-in-header ./src/docs-header.html --crate-version 0.2.14 --cfg has_i128 --cfg has_to_int_unchecked` (exit code: 1)
PS C:\Users\demen\Documents\GitHub\rust-latex-doc-minimal-example>
JohnScience commented 2 years ago

Screenshot 2021-12-30 052211

for docs.rs, only the root crate is documented, so all rustdocflags set in package.metadata.docs.rs are only applied to that crate

when running rustdoc locally, you can use cargo rustdoc -- to run a doc-build of the root crate using specific rustdocflags

(or alternatively RUSTDOCFLAGS= cargo doc --no-deps; but I find cargo rustdoc much more meaningful as "document this one crate with flags")

JohnScience commented 2 years ago

Screenshot 2021-12-30 052949

JohnScience commented 2 years ago

Screenshot 2021-12-30 053556