Kobzol / cargo-pgo

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

Flags not passed to `rustc` #18

Closed human-0 closed 2 years ago

human-0 commented 2 years ago

When cargo-pgo is used, the [build.rustflags] of .cargo\config.toml are ignored. Lto in cargo.toml seems to be ignored as well, judging by performance. The only way to pass flags seems to be through the RUSTFLAGS environment variable.

Kobzol commented 2 years ago

The only thing that cargo-pgo does when you execute cargo pgo build is basically that it runs

$ RUSTFLAGS="-Cprofile-generate=..." cargo build

so values from config.toml and Cargo.toml should be respected.

That being said, it looks like if you use RUSTFLAGS , it will override the [build.rustflags] section (https://github.com/rust-lang/cargo/issues/5376). This is the standard behaviour of cargo, so I'm not sure whether we can do anything about it. cargo-pgo could in theory parse the config.toml file, but that would reimplement what cargo does and it would deviate from the default behaviour of cargo.

For now I think that your best bet is to pass these flags using RUSTFLAGS. In any case, the LTO section from Cargo.toml should definitely be applied, if it's not, something is wrong.

human-0 commented 2 years ago

I can't reproduce the LTO issue anymore. It was probably just a benchmark inconsistency. (I couldn't find any way to check directly.) The RUSTFLAGS issue is definitely real, but I will probably just use the environment variable.