-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating entire crates during build.rs #8709
Comments
Note that with idea 1 - if the build.rs updates some existing generated crates - those would need to be rebuilt. Eg
We'd need to make sure that the build.rs runs before Perhaps there's some other way of achieving this. I see in the docs there is a section for code generation https://doc.rust-lang.org/cargo/reference/build-script-examples.html#code-generation - but it does not seem to include generating entire crates in this way. |
Most of Cargo unfortunately isn't really architected to support a use case like this. Injecting dependencies or updating the crate resolution graph dynamically during build time would require a lot of refactoring internally inside of Cargo. This is likely a situation where a non-Cargo wrapper will need to be used to prepare crates to get built by Cargo. |
Am curious if something like Idea-2 would be easier based on how cargo is architected? Then the non-Cargo wrapper would be pretty simple (something like this)
It would be nice if the non-cargo-wrapper could execute a pair of cargo commands based out of a single Cargo.toml. Thanks for taking a look! |
Unfortunately I think even that would be pretty difficult. One issue is that every execution of Cargo needs to perform version resolution and figure out the crate graph. In a hypothetical |
@nipunn1313 did you find a workaround for it? I am also trying to dynamically generate a crate and I want to be able to include it. |
@alexcrichton is there any way to trick Cargo to:
|
workaround I found is to write a separate (not build.rs) script to dynamically generate the crate and run it before cargo build. Separate script could even be written in rust, but the build has to be in two phases. |
@nipunn1313 right! I just noticed you have a different requirement.
I am looking for a way to generate and include the project in a project without modifying its My goal is to integrate pip to Cargo [package.metadata.pip]
diffusers = "0.28.2" The tool is supposed to download the package, parse it, generate the Rust code in a Cargo project and include it in the same project that uses the |
yeah - it will be tough to do in a single You might be able to do something like this Make a
Then go to parent directory and build
|
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
This is because
proto_pbtest
is generated in the build phase.Current workarounds include
Describe the solution you'd like
Idea 1
Idea 2
cargo build --prebuild-only
followed bycargo build
for projects like thisOne idea, may be to
Idea 3 [hacky workaround]
cargo build --tolerate-missing-path-deps
cargo build ; cargo build
Notes
The text was updated successfully, but these errors were encountered: