Is there a step in the build process where I can run some rust before Cargo.toml is parsed?
In my never ending struggles to get sane management of/synchronise 3rd party dependencies in my workspace, I am considering having a single properties file with the versions in and then doing something clever in
build.rs to set the versions in the various
Cargo.tomls in the workspace.
I could do this outside of
build.rs and alias
cargo to call my thing, but
build.rs seems neater.
You're going to need to wrap it in some other build system (e.g.
make), or hack it hard in
RUSTC_WRAPPER that may let you do some horrible hacks, but that will happen after Cargo.toml is parsed.
Also consider writing an xtask, such as
cargo xtask fix-deps
Cargo can be extended.
You could make a program or "bash script" to do what you want and call it cargo-before.
js@flower:~/learn/rust/comli$ cat ~/bin/cargo-before
echo "It works!"
js@flower:~/learn/rust/comli$ cargo before
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
And if in a directory with no Cargo.toml you will notice the "It works!" is before the Cargo.toml parse error.
js@flower:~$ cargo before
error: could not find `Cargo.toml` in `/home/js` or any parent directory
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.