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

Re: [PATCH v3 6/8] git-compat-util.h: move warning infra to prepare for PCHs

From
Toon Claes <toon@iotcl.com>
Date
Mar 20, 2026, 12:34 UTC
Message-ID
<87y0jm1xxx.fsf@iotcl.com>
In-Reply-To
<20260319-b4-pks-build-infra-improvements-v3-6-82f5fb3edc3f@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 55 quoted lines
> The "git-compat-util.h" header is supposed to be the first header
> included by every code compilation unit. As such, a subsequent commit
> will start to precompile this header to speed up compilation of Git.
>
> This will cause an issue though with the way that we have set up the
> "-Wsign-compare" warnings. It is expected that any compilation unit that
> fails with that compiler warning sets `DISABLE_SIGN_COMPARE_WARNINGS`
> before including "git-compat-util.h". If so, we'll disable the warning
> right away via a compiler pragma.
>
> But with precompiled headers we do not know ahead of time whether the
> code unit wants to disable those warnings, and thus we'll have to
> precompile the header without defining `DISABLE_SIGN_COMPARE_WARNINGS`.
> But as the pragma statement is wrapped by our include guards, the second
> include of that file will not have the desired effect of disabling the
> warnings anymore.
>
> We could fix this issue by declaring a new macro that compilation units
> are expected to invoke after having included the file. In retrospect,
> that would have been the better way to handle this as it allows for
> more flexibility: we could for example toggle the warning for specific
> code blocks, only. But changing this now would require a bunch of
> changes, and the churn feels excessive for what we gain.
>
> Instead, prepare for the precompiled headers by moving the code outside
> of the include guards.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  git-compat-util.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index bebcf9f698..4b4ea2498f 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -34,10 +34,6 @@ struct strbuf;
>  #  define DISABLE_WARNING(warning)
>  #endif
>  
> -#ifdef DISABLE_SIGN_COMPARE_WARNINGS
> -DISABLE_WARNING(-Wsign-compare)
> -#endif
> -
>  #undef FLEX_ARRAY
>  #define FLEX_ARRAY /* empty - weather balloon to require C99 FAM */
>  
> @@ -1099,3 +1095,7 @@ extern int not_supposed_to_survive;
>  #endif /* CHECK_ASSERTION_SIDE_EFFECTS */
>  
>  #endif
> +
> +#ifdef DISABLE_SIGN_COMPARE_WARNINGS
> +DISABLE_WARNING(-Wsign-compare)
> +#endif

Okay, so with all patches applied, when a .c file is compiled, tools/precompiled.h is included as the first one. That one includes git-compat-util.h and processes everything inside the include guards. Then it starts processing the contents of that files and that file might #define DISABLE_SIGN_COMPARE_WARNINGS. Usually git-compat-util.h is then included again, but thanks to the include guards, most of it is ignored, except for this last bit.

Okay, makes sense.
-- 
Cheers,
Toon
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 47 of 53 in “Some build system improvements”
  1. 0/8 Some build system improvementsPatrick Steinhardt, Mar 10, 2026
  2. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 10, 2026
  3. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 10, 2026
  4. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 10, 2026
  5. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 10, 2026
  6. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 10, 2026
  7. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 10, 2026
  8. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 10, 2026
  9. Phillip WoodMar 11, 2026
  10. Phillip WoodMar 11, 2026
  11. SZEDER GáborMar 11, 2026
  12. Patrick SteinhardtMar 12, 2026
  13. Phillip WoodMar 13, 2026
  14. Patrick SteinhardtMar 16, 2026
  15. SZEDER GáborApr 10, 2026
  16. Patrick SteinhardtMar 12, 2026
  17. Phillip WoodMar 13, 2026
  18. Patrick SteinhardtMar 16, 2026
  19. Phillip WoodMar 16, 2026
  20. Kristoffer HaugsbakkMar 17, 2026
  21. Patrick SteinhardtMar 19, 2026
  22. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 10, 2026
  23. Phillip WoodMar 11, 2026
  24. Patrick SteinhardtMar 12, 2026
  25. Junio C HamanoMar 10, 2026
  26. Patrick SteinhardtMar 11, 2026
  27. Junio C HamanoMar 13, 2026
  28. Patrick SteinhardtMar 16, 2026
  29. 0/8 Some build system improvementsPatrick Steinhardt, Mar 16, 2026
  30. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 16, 2026
  31. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 16, 2026
  32. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 16, 2026
  33. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 16, 2026
  34. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 16, 2026
  35. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 16, 2026
  36. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 16, 2026
  37. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 16, 2026
  38. Phillip WoodMar 16, 2026
  39. 0/8 Some build system improvementsPatrick Steinhardt, Mar 19, 2026
  40. 1/8 Introduce new "tools/" directoryPatrick Steinhardt, Mar 19, 2026
  41. 2/8 contrib: move "coccinelle/" directory into "tools/"Patrick Steinhardt, Mar 19, 2026
  42. 3/8 contrib: move "coverage-diff.sh" script into "tools/"Patrick Steinhardt, Mar 19, 2026
  43. Toon ClaesMar 20, 2026
  44. 4/8 contrib: move "update-unicode.sh" script into "tools/"Patrick Steinhardt, Mar 19, 2026
  45. 5/8 builds: move build scripts into "tools/"Patrick Steinhardt, Mar 19, 2026
  46. 6/8 git-compat-util.h: move warning infra to prepare for PCHsPatrick Steinhardt, Mar 19, 2026
  47. Toon ClaesMar 20, 2026
  48. 7/8 meson: compile compatibility sources separatelyPatrick Steinhardt, Mar 19, 2026
  49. 8/8 meson: precompile "git-compat-util.h"Patrick Steinhardt, Mar 19, 2026
  50. Toon ClaesMar 20, 2026
  51. SZEDER GáborApr 10, 2026
  52. Phillip WoodApr 10, 2026
  53. SZEDER GáborApr 10, 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.