#build-script #cargo-build #cargo-command #post #execute #cargo-check #run

build cargo-post

A cargo wrapper that executes a post build script after a successful build

8 releases

0.1.7 Apr 30, 2023
0.1.6 Dec 17, 2020
0.1.5 Jul 19, 2020
0.1.4 Jun 7, 2020
0.1.2 Mar 21, 2019

#172 in Build Utils

Download history 13/week @ 2024-07-26 12/week @ 2024-08-02 10/week @ 2024-08-09 24/week @ 2024-08-16 21/week @ 2024-08-23 7/week @ 2024-08-30 5/week @ 2024-09-06 5/week @ 2024-09-13 29/week @ 2024-09-20 12/week @ 2024-09-27 12/week @ 2024-10-04 42/week @ 2024-10-11 51/week @ 2024-10-18 15/week @ 2024-10-25 82/week @ 2024-11-01 109/week @ 2024-11-08

264 downloads per month

MIT/Apache

15KB
220 lines

cargo-post

A cargo wrapper that executes a post build script after a successful build.

Installation

cargo install cargo-post

Usage

Execute cargo CMD [ARGS] and run post_build.rs afterwards:

cargo post CMD [ARGS]

The post_build.rs is only run if CMD is a build command like build or xbuild.

In workspaces, you might have to pass a --package argument to cargo build to specify the package for which the post build script should be run.

Examples:

Build the crate and run post_build.rs afterwards:

cargo post build

Build the crate in release mode and run post_build.rs afterwards:

cargo post build --release

Builds the crate using cargo-xbuild:

cargo post xbuild

Check the crate without executing post_build:

cargo post check

The build script is not executed because cargo check is not a build command. The same behavior occurs for cargo post doc or cargo post update.

Post-Build Script Format

Post-build scripts are similar to cargo build scripts, but they get a different set of environment variables:

  • CRATE_BUILD_COMMAND: The full cargo command that was used for building without post
    • Example: When the crate is compiled using cargo post build --release, the environment variable has the value cargo build --release.
  • CRATE_MANIFEST_DIR: The directory where the Cargo.toml of the crates lives.
  • CRATE_MANIFEST_PATH: The path to the Cargo.toml of the crates.
  • CRATE_PROFILE: debug or release, depending on whether --release was passed in the build command.
  • CRATE_TARGET: The full content of what was passed as --target or the empty string if no --target was passed.
  • CRATE_TARGET_TRIPLE: The target triple of the passed --target or the empty string if no --target was passed.
    • Example: With cargo post xbuild --target /some/path/to/your/target-x86_64.json this environment variable has the value target-x86_64.
  • CRATE_TARGET_DIR: The path to the target directory of your crate.
  • CRATE_OUT_DIR: The path to the directory where cargo puts the compiled binaries. This path is constructed by appending CRATE_TARGET_TRIPLE and CRATE_PROFILE to CRATE_TARGET_DIR.

Dependencies

Dependencies for post build scripts can be specified in a [package.metadata.cargo-post.dependencies] table in your Cargo.toml.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.1–2MB
~43K SLoC