build: compile controller.capnp.c once -- libxce_dep passes only the header

libxce_dep's sources:[gen_srcs] handed every consumer target the generated
.c output, so 143 targets each compiled controller.capnp.c independently:
a 9.5s / 293MB-RSS / 3.3MB-object TU under the asan profile, ~35% of a
clean build's serial work and ~470MB of duplicate objects on disk.

Index the dep's sources to gen_srcs[1] (the .h output) instead: the
custom_target edge still orders every consumer's compiles after codegen
(bug-1798's guarantee, unchanged), .h sources are never compiled, and the
.c is compiled exactly once inside libxce. libxce_src keeps the unindexed
custom_target for the same reason it always did.

Verified: fresh asan tree builds green (1934 steps vs 2076), meson test
134/134 including the three --wrap interposition tests; tree size 2.0G ->
1.3G.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
lei.chen 2026-10-21 13:55:33 +00:00
parent a905baf013
commit 678163adb8

View file

@ -191,7 +191,17 @@ libxce = static_library('xce',
# for consumers OUTSIDE the libxce target itself. link_with alone does not
# propagate this: it only orders the LINK step after libxce is built, not
# a consumer's own COMPILE steps against a header libxce never installs.
libxce_dep = declare_dependency(link_with: libxce, sources: [gen_srcs],
#
# build-time dedup: this used to pass the WHOLE custom_target, which made
# every consumer target compile controller.capnp.c itself -- 143 separate
# compiles of a 9.5s/293MB-RSS/3.3MB-object TU (asan profile), ~35% of a
# full clean build's serial work and ~470MB of duplicate .o files on disk.
# Indexing to gen_srcs[1] (the .h output only) keeps everything bug-1798
# needed: a custom_target output still carries the dependency edge on the
# whole codegen step (custom_target always builds ALL of its outputs
# atomically), and a .h source is never compiled. The .c output is compiled
# exactly once, inside libxce above, and every consumer links the archive.
libxce_dep = declare_dependency(link_with: libxce, sources: [gen_srcs[1]],
dependencies: libxce_deps)
# libxce_shared_dep = declare_dependency(link_with: libxce_shared)