cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Cargo config doesn't work sometimes

Open GuillaumeGomez opened this issue 7 months ago • 12 comments

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

  1. git clone https://github.com/scattered-systems/scsys
  2. cd scsys/macros
  3. git checkout v0.2.6
  4. Run the cargo command from above

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.87.0-nightly (6cf826701 2025-03-14)

GuillaumeGomez avatar May 23 '25 14:05 GuillaumeGomez

Same problem with the 0.2.7 versions.

GuillaumeGomez avatar May 23 '25 14:05 GuillaumeGomez

Could you try moving all --config flags to before --lib?

Edit: that might not be the issue. Was just guessing.

weihanglo avatar May 23 '25 14:05 weihanglo

Is there an expected order for the flags?

GuillaumeGomez avatar May 23 '25 14:05 GuillaumeGomez

Could you try moving all --config flags to before --lib?

already tried, no change

syphar avatar May 23 '25 14:05 syphar

odd thing: this same command works perfectly for other normal & proc-macro crates (it's coming from the docs.rs JSON build)

syphar avatar May 23 '25 14:05 syphar

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.

weihanglo avatar May 23 '25 14:05 weihanglo

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.

weihanglo avatar May 23 '25 14:05 weihanglo

Rustdoc doesn't see the --config arguments, I checked that first.

GuillaumeGomez avatar May 23 '25 14:05 GuillaumeGomez

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?

syphar avatar May 23 '25 14:05 syphar

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.

GuillaumeGomez avatar May 23 '25 14:05 GuillaumeGomez

kk, then I'll wait for a fix

syphar avatar May 23 '25 15:05 syphar

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.

weihanglo avatar May 23 '25 15:05 weihanglo