rust-lang / rust-lang/cargo

Generating entire crates during build.rs

Open
#8,709 9 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-build-execution C-feature-request S-needs-team-input
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Describe the problem you are trying to solve
When having entire autogenerated crates (eg https://github.com/dropbox/pb-jelly) - there isn't a good way to generate the crate at build time via build.rs.

Eg when building https://github.com/dropbox/pb-jelly/blob/a0c0550/examples/Cargo.toml, we get

nipunn-mbp:examples nipunn$ cargo build
error: failed to read `/Users/nipunn/src/pb-jelly/pb-test/gen/pb-jelly/proto_pbtest/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

This is because proto_pbtest is generated in the build phase.

Current workarounds include

  • commenting out the proto_pbtest dependency, building, uncommenting, building again
  • Creating a dummy empty proto_pbtest Cargo.toml to be overwritten
  • Splitting the build phase out into a separate crate

Describe the solution you'd like

Idea 1

  • Parse the Cargo.toml - tolerating missing path dependencies
  • Build the build.rs - only looking at build dependencies - ensuring they're all available
  • Run build.rs
  • Re-evaluate cargo task graph to search for the missing dependencies
  • Run rest of the build

Idea 2

  • Provide a command (eg cargo build --prebuild-only) to only run the build.rs build phase tolerating missing path dependencies in the other phases
  • Developer can run cargo build --prebuild-only followed by cargo build for projects like this
    One idea, may be to

Idea 3 [hacky workaround]

  • Provide a mode to tolerate missing path dependencies cargo build --tolerate-missing-path-deps
  • Developer can run cargo build ; cargo build

Notes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the pb-jelly examples/Cargo.toml and inspect how its build.rs generates pb-test/gen/pb-jelly/proto_pbtest/Cargo.toml. Compare the three proposed approaches and determine which Cargo behavior should support generated path dependencies; done means the generated crate builds without the listed manual workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.