Cargo config doesn't work sometimes
Problem
When running this command on docs.rs to generate JSON output:
cargo "+nightly" "rustdoc" "--lib" "-Zrustdoc-map" "--all-features" "--config" "build.rustflags=[\"--cfg\", \"docsrs\"]" "-Zhost-config" "-Ztarget-applies-to-host" "--config" "host.rustflags=[\"--cfg\", \"docsrs\"]" "--config" "build.rustdocflags=[\"--cfg\", \"docsrs\", \"-Z\", \"unstable-options\", \"--output-format\", \"json\", \"--static-root-path\", \"/-/rustdoc.static/\", \"--cap-lints\", \"warn\", \"--extern-html-root-takes-precedence\"]" "--offline" "-Zunstable-options" "--config=doc.extern-map.registries.crates-io=\"https://docs.rs/{pkg_name}/{version}/x86_64-unknown-linux-gnu\"" "-Zrustdoc-scrape-examples" "-j6"
We instead get the HTML format. It happened only on two crates so far: scsys-macros (version 0.2.6) and scsys-derive (version 0.2.6).
When checking what arguments rustdoc received, I saw nothing coming from --config, so I suspect the problem coming from cargo.
Steps
- git clone https://github.com/scattered-systems/scsys
- cd scsys/macros
- git checkout v0.2.6
- Run the cargo command from above
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.87.0-nightly (6cf826701 2025-03-14)
Same problem with the 0.2.7 versions.
Could you try moving all --config flags to before --lib?
Edit: that might not be the issue. Was just guessing.
Is there an expected order for the flags?
Could you try moving all --config flags to before --lib?
already tried, no change
odd thing: this same command works perfectly for other normal & proc-macro crates (it's coming from the docs.rs JSON build)
It is very possible a bug in host-config/target-applies-to-host. Not yet got time to look into it deeper but removing those helps.
Is there an expected order for the flags?
@GuillaumeGomez I was wonder if those --config were interpreted as trailing args in cargo rustdoc but no. If that had happened rustdoc would have failed.
Rustdoc doesn't see the --config arguments, I checked that first.
It is very possible a bug in host-config/target-applies-to-host. Not yet got time to look into it deeper but removing those helps.
@GuillaumeGomez I don't know what these do, do we need these for rustdoc json?
I don't think so but there is no reason to not pass them. It simplifies work for us on docs.rs. And if they are ever needed, doesn't hurt to keep them until then.
kk, then I'll wait for a fix
cargo +nightly rustdoc
--lib
--all-features
--offline
--verbose
-j6
-Zunstable-options
-Zrustdoc-map
-Zhost-config
-Ztarget-applies-to-host
-Zrustdoc-scrape-examples
--config "build.rustflags=['--cfg', 'docsrs']"
--config "host.rustflags=['--cfg', 'docsrs']"
--config "build.rustdocflags=['--cfg', 'docsrs', '-Z', 'unstable-options', '--output-format', 'json', '--static-root-path', '/-/rustdoc.static/', '--cap-lints', 'warn', '--extern-html-root-takes-precedence']"
--config "doc.extern-map.registries.crates-io='https://docs.rs/{pkg_name}/{version}/x86_64-unknown-linux-gnu'"
Just made the CLI flags a bit more readable. I'll check when I have time.