rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.56k stars 2.38k forks source link

Post-build script execution #545

Open vosen opened 10 years ago

vosen commented 10 years ago

Currently, cargo execute scrips before the build starts with the build field. I propose renaming build to pre_build and adding post_build (which would run after every successful build). It's useful for general postprocessing: running executable packers, zipping files, copying stuff, logging, etc.

Systemcluster commented 9 months 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.

leryn1122 commented 9 months ago

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.

timboudreau commented 5 months ago

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:

While 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.

Gronis commented 5 months ago
  • Another do-nothing project which contains a 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 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.

RealSuperRyn commented 2 months ago

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.

correabuscar commented 2 months ago

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.

perhaps you can call the script via runner ie. via cargo run ?

Scramjet911 commented 1 month ago

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