taiki-e / cargo-hack

Cargo subcommand to provide various options useful for testing and continuous integration.
Apache License 2.0
628 stars 28 forks source link

Keeping compilation artifacts of each run #243

Open cyqsimon opened 7 months ago

cyqsimon commented 7 months ago

Is there a way for me to make cargo-hack keep the compiled binary after each run? I'm thinking of something like this:

# Assume crate foo has features alpha and bravo
$ cargo hack build --feature-powerset --keep-artifacts
$ ls target/debug/cargo-hack-artifacts
foo
foo-alpha
foo-bravo
foo-alpha-bravo

This would be useful if for example, you would like to upload them as CI artifacts.

If this is currently not possible, I would like to volunteer to work on a PR, thanks.

taiki-e commented 7 months ago

It is probably possible to write a script that does this using --print-command-list (https://github.com/taiki-e/cargo-hack/pull/175), but adding a flag to do this in a single command seems reasonable to me.

cyqsimon commented 7 months ago

I'm in the middle of implementing this, and it turns out it's quite complicated with a lot to add.

First of all, cargo can produce a lot of different types of binary objects, and they are all placed under different paths. The behaviour is well-documented here, but still it's a lot of work to implement.

Second, cargo allows target selection (not to be confused with the target triple) using flags like --lib, --bins, --bin, etc. See cargo build -h. Right now these flags are of "passthrough" type, but they need to be changed to "propagated" type instead so that we can know which objects to copy.

This is all to say that it's more work than I expected. Not too difficult; just tedious. Give me some time.