Kobzol / cargo-pgo

Cargo subcommand for optimizing Rust binaries/libraries with PGO and BOLT.
MIT License
563 stars 11 forks source link

Stream output of `cargo` #19

Closed Kobzol closed 2 years ago

Kobzol commented 2 years ago

Currently, cargo-pgo runs cargo, gathers its output and then writes it to the output. However, it would be much nicer if we could instead stream the output of cargo interactively, so that the user can see it immediately and not just at the end.

Use-case: https://github.com/Kobzol/cargo-pgo/issues/5#issuecomment-1265031077

pkolaczk commented 2 years ago

BTW - if possible, try to propagate color formatting as well. I guess cargo disables color automatically when it detects its output is redirected, so it might involve passing an option to cargo to override this.

zeroflaw commented 2 years ago

When I do a cargo build after a cargo pgo it causes a full dependency rebuild. I'm not sure if my "config.toml" rustflags are being honoured? I have them set as ["-C", "target-cpu=native", "-Z", "tune-cpu=native"]

I did a RUSTFLAGS="-C target-cpu=native -Z tune-cpu=native" cargo pgo optimize and it did seem to produce a different binary, but still did a full dependency rebuild when running cargo build.

Will this change allow the verbose cargo output to be streamed as well? So I can see what flags are being set during the build.

Great tool by the way 👍

Kobzol commented 2 years ago

Rustflags from the config file should be honored, but cargo build will always do a rebuild AFAIK, because cargo pgo uses PGO flags (instrumentation/optimization) that will invalidate other builds. You would have to pass e.g. RUSTFLAGS="-Cprofile-generate" to avoid a rebuild, but then you'd just use PGO again.. :)

Yes, with the streaming change, verbose output is also streamed and printed:

$ cargo pgo build -- --verbose
Kobzol commented 2 years ago

I published version 0.2.2 with cargo output streaming.