meson: use precompiled headers for unit tests

Same as in the preceding commit, our unit tests don't use precompiled
headers yet. In this case though it's a tiny bit more complicated to
make use of them, as we do not want to include "git-compat-util.h" for
"clar.c", as that code file is a third-party implementation that is
independent of the Git codebase.

But there's an easy workaround: instead of linking that file into the
executable directly, we can easily adapt it to be built into a static
library first. Like that we can trivially have separate build flags for
that one file.

Do so and adapt the remaining sources to use precompiled headers. This
results in a small but noticeable build speedup:

  Benchmark 1: meson compile (version = HEAD~)
    Time (mean ± σ):      5.343 s ±  0.019 s    [User: 75.478 s, System: 20.382 s]
    Range (min … max):    5.308 s …  5.376 s    10 runs

  Benchmark 2: meson compile (version = HEAD)
    Time (mean ± σ):      5.077 s ±  0.017 s    [User: 70.557 s, System: 19.999 s]
    Range (min … max):    5.047 s …  5.103 s    10 runs

  Summary
    meson compile (version = HEAD) ran
      1.05 ± 0.01 times faster than meson compile (version = HEAD~)

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-09-24 16:09:13 +02:00 committed by Junio C Hamano
parent ae24379dd4
commit 3d7418e351
1 changed files with 8 additions and 2 deletions

View File

@ -30,7 +30,6 @@ clar_test_suites = [
]

clar_sources = [
'unit-tests/clar/clar.c',
'unit-tests/unit-test.c',
'unit-tests/lib-oid.c',
'unit-tests/lib-reftable.c'
@ -49,7 +48,7 @@ clar_decls_h = custom_target(
)
clar_sources += clar_decls_h

clar_sources += custom_target(
clar_suite_h = custom_target(
input: clar_decls_h,
output: 'clar.suite',
command : [
@ -66,6 +65,13 @@ clar_unit_tests = executable('unit-tests',
c_args: [
'-DGIT_CLAR_DECLS_H="' + clar_decls_h.full_path() + '"',
],
c_pch: '../tools/precompiled.h',
link_with: static_library('clar',
sources: [
'unit-tests/clar/clar.c',
clar_suite_h,
],
),
dependencies: [libgit_commonmain],
)
test('unit-tests', clar_unit_tests, kwargs: test_kwargs)