Don't build partition_alloc if it is not needed

Currently //base has a dependency on partition_alloc code even if
`use_partition_alloc` is false, with the rationale that this avoids
`gn check` errors, relying on the linker to remove the dead code.

The main problem with this approach is that even though the code does
not make it into the final binary (hopefully... assuming no accidental
code dependencies), we still attempt to build it. This is wasted work,
but more importantly it can cause build failures because partition_alloc
may contain code that does not build on all platforms where
use_partition_alloc is false. One example is when building Cronet in
AOSP - in this case this code is built against an older version of
glibc that does not support memfd_create(), leading to a compilation
error.

We could attempt to work around such problems by making partition_alloc
build on such platforms, but it seems silly to spend time implementing
workarounds in what is literally dead code. Instead, it makes more sense
to just not build partition_alloc when `use_partition_alloc` is false.
This is what this commit does.

Bug: b:381421702
Change-Id: I13edc01f693a1de945088c53b0e6a3c9d67d89c8
Cq-Include-Trybots: luci.chromium.try:android-cronet-x64-dbg-15-tests,android-cronet-x86-dbg-marshmallow-tests
Cq-Include-Trybots: chromium/try:android-rust-arm32-rel
Cq-Include-Trybots: chromium/try:android-rust-arm64-dbg
Cq-Include-Trybots: chromium/try:android-rust-arm64-rel
Cq-Include-Trybots: chromium/try:linux-rust-x64-dbg
Cq-Include-Trybots: chromium/try:linux-rust-x64-rel
Cq-Include-Trybots: chromium/try:win-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6097975
Commit-Queue: Etienne Dechamps <edechamps@google.com>
Reviewed-by: Ɓukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1398613}
NOKEYCHECK=True
GitOrigin-RevId: 4dacf2b61c359950d2c2f1b5f9b9d079a01290a4
2 files changed