Skip to content

[cargo doc] build.rs does not cover the use cases very well #3053

Closed as not planned
@nagisa

Description

@nagisa

With docs.rs out, we’ve noticed a problem with cargo running build.rs scripts when documenting each crate, while it shouldn’t be necessary in majority of the cases.

Namely, most of the crates use build.rs scripts for one of these three large categories:

  • Native library discovery (pkgconfig/etc);
  • Building of dependencies written in other languages (gcc-rs/etc);
  • Generating rust code (syntex/lalrpop/etc).

First and second use case will not influence the resulting documentation in meaningful ways, while the third use-case almost always will. First and second use-cases are target-dependent and may require cross-compilation toolchains, whereas the third use-case as well as documentation generation are obviously target-agnostic and can be done without any extra tooling or knowledge about the target platform.

It is counter-productive to not make any distinction between these cases. A project like docs.rs ideally shouldn’t need to install any native dependencies (see https://github.com/onur/docs.rs/issues/23) in order to generate documentation (because they are irrelevant for documentation generation purposes!)

There’s multiple ways one could proceed here:

  • Introduce generate.rs, do not run build.rs scripts on cargo doc;
  • Introduce extra keys to Cargo.toml (e.g. run_build_script_for_docs = false) defaulting to not running build.rs before generating documentation and making people using third use case specify that variable to true;
  • The least breaking change would be to add a way in cargo API to not run build.rs scripts when building docs, so docs.rs could implement some sort of scheme itself (e.g. via [metadata] Cargo.toml section instructing docs.rs to run build.rs);
  • etc.

cc @onur

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-docS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions