rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

Support Profile Guided Optimization (PGO) #68

Open errantmind opened 3 years ago

errantmind commented 3 years ago

When building with cargo, using -Z build-std, I cannot generate profiles for PGO

The build fails when it gets to the step where it (attempts to) build core :

`rustc --crate-name core --edition=2018 /home/errant/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C linker-plugin-lto -C codegen-units=1 -C metadata=48bb6e05f939071a -C extra-filename=-48bb6e05f939071a --out-dir /home/errant/dev/projects/faf-epoll/target/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -Z force-unstable-if-unmarked -L dependency=/home/errant/dev/projects/faf-epoll/target/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/errant/dev/projects/faf-epoll/target/release/deps --cap-lints allow -Ctarget-cpu=native -Clinker=/usr/bin/clang-12 -Clink-arg=-fuse-ld=lld-12 -Clto=thin -Cembed-bitcode=yes -Copt-level=3 -Ccodegen-units=1 -Cprofile-generate=/home/errant/dev/projects/faf-epoll/prof`
error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]
12101111 commented 3 years ago

This is not possible currently.

profiler_builtins is no_std crate, so it need a core(the prebuilt one).

But rustc don't allow link two core:

// Since libcore defines many fundamental lang items, all tests live in a
// separate crate, libcoretest, to avoid bizarre issues.
//
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
// this, both the generated test artifact and the linked libtest (which
// transitively includes libcore) will both define the same set of lang items,
// and this will cause the E0152 "found duplicate lang item" error. See
// discussion in #50466 for details.
//
// This cfg won't affect doc tests.
12101111 commented 3 years ago

Related PR: https://github.com/rust-lang/rust/pull/79958

errantmind commented 3 years ago

Alright, thanks for the explanation. It would be helpful to have this feature at some point