#cli #cargo #build

bin+lib cargo-export

Utility to export compiler artifacts from cargo build process

6 releases

0.2.5 Dec 21, 2023
0.2.4 Dec 21, 2023
0.1.0 May 7, 2023

#224 in Cargo plugins

Download history 1/week @ 2023-11-02 2/week @ 2023-11-09 6/week @ 2023-11-16 4/week @ 2023-11-23 113/week @ 2023-11-30 123/week @ 2023-12-07 51/week @ 2023-12-14 113/week @ 2023-12-21 9/week @ 2023-12-28 13/week @ 2024-01-04 6/week @ 2024-01-11 8/week @ 2024-01-18 19/week @ 2024-01-25 15/week @ 2024-02-01 17/week @ 2024-02-08 112/week @ 2024-02-15

168 downloads per month

MIT license

12KB
196 lines

Exporting cargo compiler artifacts (tests, benches)

Motivation

It's quite challenging to export secondary artifacts like tests and benchmark executables. Those kind of artifacts can be very valuable for different reasons:

  1. packing test executables in the contaier to run them later on a different platform
  2. comparing and analyzing assembly of performance benchmarks

For final artifacts we have target/(release|debug)/{crate-name}, but test and benchmark executables are containing hash like target/release/deps/app-25de5d28a523d3c2. Moreover it changes every time compiler options are changed. For this reason methods like find and cp doesn't work well for extracting such artifacts.

Thankfully, compiler provide service messages (cargo build --message-format=json) which allows to list all the artifacts generated by the compiler.

Installing

$ cargo install cargo-export

Using

  • export all test binaries to target/tests directory

    $ cargo export target/tests -- test
    

    Under the hood this command will run cargo test --no-run --message-format=json and copy all the generated binaries in the target/tests directory.

  • export all benchmark binaries to target/bench directory

    $ cargo export target/bench -- bench
    
  • export all benchmark binaries to target/bench directory and add postfix -main to each executable

    $ cargo export target/bench -t main -- bench
    
  • build and export benchmarks with a specific feature

    $ cargo export target/bench -- bench --feature=my-feature
    
  • build and export benchmarks using nightly

    $ cargo +nightly export target/bench -- bench
    

Dependencies

~0.8–1.6MB
~36K SLoC