Skip to content

Generating entire crates during build.rs #8709

Open
@nipunn1313

Description

@nipunn1313

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-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