git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/7] meson: use precompiled headers for unit tests

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 24, 2026, 14:09 UTC
Message-ID
<20260924-pks-meson-improvements-v1-4-90b7f79f1c4e@pks.im>
In-Reply-To
<20260924-pks-meson-improvements-v1-0-90b7f79f1c4e@pks.im>

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>
---
 t/meson.build | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/t/meson.build b/t/meson.build
index 3ca7b27104..9f1ee9ad59 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -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)
-- 
2.56.0.rc2.329.gd58861e689.dirty
Previous: Karthik NayakNext: Kaartic Sivaraam
Message 8 of 20 in “A couple of Meson improvements”
  1. 0/7 A couple of Meson improvementsPatrick Steinhardt, Sep 24, 2026
  2. 1/7 meson: avoid recompiling HTTP sources several timesPatrick Steinhardt, Sep 24, 2026
  3. Karthik NayakSep 30, 2026
  4. Kaartic SivaraamOct 5, 2026
  5. 2/7 meson: don't recompile git-remote-http(1) multiple times for testsPatrick Steinhardt, Sep 24, 2026
  6. 3/7 meson: use precompiled headers for our test-helperPatrick Steinhardt, Sep 24, 2026
  7. Karthik NayakSep 30, 2026
  8. 4/7 meson: use precompiled headers for unit testsPatrick Steinhardt, Sep 24, 2026
  9. Kaartic SivaraamOct 5, 2026
  10. Patrick SteinhardtOct 5, 2026
  11. 5/7 meson: fix outdated completion helpersPatrick Steinhardt, Sep 24, 2026
  12. 6/7 meson: update wrappersPatrick Steinhardt, Sep 24, 2026
  13. Karthik NayakSep 30, 2026
  14. Kaartic SivaraamOct 5, 2026
  15. Patrick SteinhardtOct 5, 2026
  16. 7/7 gitlab-ci: fix hanging MSVC jobsPatrick Steinhardt, Sep 24, 2026
  17. Karthik NayakSep 30, 2026
  18. Patrick SteinhardtSep 30, 2026
  19. Karthik NayakSep 30, 2026
  20. Kaartic SivaraamOct 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.