dependenciesrust-cargobuild-script

Can Cargo include a set of dynamic dependencies based on code generated by a build script?


I'm writing a build script that parses an XML file and generates a pair of Rust modules containing various struct and enum declarations that allow the "parent" app to consume an XML feed at runtime.

However, the generated code has its own set of runtime dependencies on crates such as quick-xml and rust_decimal that the "parent" app must list in its Cargo.toml file.

These dependencies can of course be added manually, but can Cargo be configured to include what amounts to a set of dynamic dependencies automatically?

Thanks


Solution

  • So, this can't be done automatically; however, by adding extern crate ... dependencies at the start of the generated modules, rustc will be able to generate explicit error messages telling which crates are needed in your Cargo.toml file