Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfg(docsrs) isn't being set properly? #11

Closed
CAD97 opened this issue Mar 3, 2024 · 1 comment · Fixed by #19
Closed

cfg(docsrs) isn't being set properly? #11

CAD97 opened this issue Mar 3, 2024 · 1 comment · Fixed by #19

Comments

@CAD97
Copy link

CAD97 commented Mar 3, 2024

Example:

#[cfg(docsrs)]
compile_error!("cfg(docsrs) set");

#[cfg(not(docsrs))]
compile_error!("cfg(docsrs) not set");
> cargo +nightly docs-rs --verbose
       Dirty cstr8 v0.1.3 (D:\git\cad97\cstr8): the precalculated components changed
 Documenting cstr8 v0.1.3 (D:\git\cad97\cstr8)
     Running `rustdoc --edition=2021 --crate-type lib --crate-name cstr8 src\lib.rs -o D:\.rust\target\doc --cfg "feature=\"alloc\"" --cfg "feature=\"default\"" --cfg "feature=\"std\"" --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 -C metadata=2fab72609bfd58bc -L dependency=D:\.rust\target\debug\deps --crate-version 0.1.3`
error: cfg(docsrs) not set
  --> src\lib.rs:28:1
   |
28 | compile_error!("cfg(docsrs) not set");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not document `cstr8`

> $env.RUSTDOCFLAGS = "--cfg=docsrs"
> cargo +nightly doc --verbose
       Dirty cstr8 v0.1.3 (D:\git\cad97\cstr8): the profile configuration changed
 Documenting cstr8 v0.1.3 (D:\git\cad97\cstr8)
     Running `rustdoc --edition=2021 --crate-type lib --crate-name cstr8 src\lib.rs -o D:\.rust\target\doc --cfg "feature=\"alloc\"" --cfg "feature=\"default\"" --cfg "feature=\"std\"" --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 -C metadata=6c16e02dedfb218b -L dependency=D:\.rust\target\debug\deps --cfg=docsrs --crate-version 0.1.3`
error: cfg(docsrs) set
  --> src\lib.rs:25:1
   |
25 | compile_error!("cfg(docsrs) set");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not document `cstr8`

> cargo +nightly docs-rs --version
cargo-docs-rs 0.1.10

Attempting to diagnose, this seems to be caused by -Zhost-config, as removing that flag from the execution results in --cfg=docsrs being included in the rustdoc invocation.

> cargo +nightly rustdoc --verbose -Zunstable-options --config 'build.rustdocflags=["--cfg=docsrs"]' -Ztarget-applies-to-host
       Dirty cstr8 v0.1.3 (D:\git\cad97\cstr8): the rustflags changed
 Documenting cstr8 v0.1.3 (D:\git\cad97\cstr8)
     Running `rustdoc --edition=2021 --crate-type lib --crate-name cstr8 src\lib.rs -o D:\.rust\target\doc --cfg "feature=\"alloc\"" --cfg "feature=\"default\"" --cfg "feature=\"std\"" --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 -C metadata=2fab72609bfd58bc -L dependency=D:\.rust\target\debug\deps --cfg=docsrs --crate-version 0.1.3`
error: cfg(docsrs) set
  --> src\lib.rs:25:1
   |
25 | compile_error!("cfg(docsrs) set");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> cargo +nightly rustdoc --verbose -Zunstable-options --config 'build.rustdocflags=["--cfg=docsrs"]' -Ztarget-applies-to-host -Zhost-config
       Dirty cstr8 v0.1.3 (D:\git\cad97\cstr8): the config settings changed
 Documenting cstr8 v0.1.3 (D:\git\cad97\cstr8)
     Running `rustdoc --edition=2021 --crate-type lib --crate-name cstr8 src\lib.rs -o D:\.rust\target\doc --cfg "feature=\"alloc\"" --cfg "feature=\"default\"" --cfg "feature=\"std\"" --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 -C metadata=2fab72609bfd58bc -L dependency=D:\.rust\target\debug\deps --crate-version 0.1.3`
error: cfg(docsrs) not set
  --> src\lib.rs:28:1
   |
28 | compile_error!("cfg(docsrs) not set");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> cargo +nightly -Vv
cargo 1.78.0-nightly (f772ec022 2024-03-01)
release: 1.78.0-nightly
commit-hash: f772ec0224d3755ce52ac5128a80319fb2eb45d0
commit-date: 2024-03-01
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.22631 (Windows 11 Education) [64-bit]

That might mean this is an upstream issue but I legitimately don't know and this is where I ran into it.

@CAD97
Copy link
Author

CAD97 commented Mar 3, 2024

I can now confirm that this is an issue with cargo-docs-rs and not with docs-rs itself, as the just published cstr8 docs use cfg(docsrs) to turn on doc_auto_cfg which is showing up in the rendered docs. So there's a difference somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant