Open vosen opened 10 years ago
A workaround for some use-cases is using a workspace and using the build.rs
of the top-level crate to invoke cargo
and build the inner crates.
So I argued on the officiality. It could be solved with third party cargo-post
, cargo-make
mentioned above, sometimes de-normalized in my point of view. An official hook would be the expected solution for complex intergration so far.
FWIW, as a workaround I have had some success (I'm building a MacOS xcframework which needs to be consumed by Swift and C code) with the following - this only is practical if your projects are set up as a Cargo workspace:
cbindgen
against itself (another thing that post-build scripts would be useful for)build.rs
that runs cbindgen
takes the .a
file and the generated bindings and creates or updates the Apple xcframework
the C and Swift code depend onWhile it's not pretty, and it involves a lot of fishing around in build directories, it does work as a way to have code that can only run after a dependency is built.
I do not think this sort of thing is outside the scope of Cargo's purpose - it is a very common activity to need to post-process a binary or generate some additional artifacts that should only be generated at the conclusion of a successful build - foreign language bindings are the perfect example of that.
- Another do-nothing project which contains a
build.rs
that runscbindgen
takes the.a
file and the generated bindings and creates or updates the Applexcframework
the C and Swift code depend on
How did you setup the dependencies in this do-nothing-project so that the original project has finished compiling and produced a .a
static library when build.rs of do-nothing-project starts executing? I had to do some weird buzy-wait and check modified timestamp so that I don't accidentally link an old version of the library.
I tried to use build-dependencies (so that it will be built before build.rs starts) but that attempts to link the original project to build.rs code which is not what I want.
In an OS project I am doing, I need the compiled bootloader files to be put into position and then have a virtual machine run using those files. My current solution is a hacked together shell script that I annoyingly must run in place of cargo build
or cargo run
. Post-build scripts would be much appreciated, as it would make my workflow much more bearable.
In an OS project I am doing, I need the compiled bootloader files to be put into position and then have a virtual machine run using those files. My current solution is a hacked together shell script that I annoyingly must run in place of
cargo build
orcargo run
. Post-build scripts would be much appreciated, as it would make my workflow much more bearable.
perhaps you can call the script via runner
ie. via cargo run
?
Those coming from other languages with different package managers might expect a postbuild option and be sad not to find it.
I hope something comes up, or atleast a standardized way to do it which doesn't involve experimenting with different packages for a basic use case
Currently, cargo execute scrips before the build starts with the
build
field. I propose renamingbuild
topre_build
and addingpost_build
(which would run after every successful build). It's useful for general postprocessing: running executable packers, zipping files, copying stuff, logging, etc.