From 5db50e3f777888b18336e9dcc065ef0e9057c6cf Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 3 Aug 2025 00:07:03 +0300 Subject: [PATCH] meson: Disable PCH for GCC GCC doesn't really benefit as much as Clang does from using precompiled headers. Another aspect to consider is that clangd doesn't really like GCC's PCH flags in the compilation database, so GCC based devshells would continue to work with clangd. This also has the slight advantage of ensuring that our includes are in order, since we build with both Clang and GCC. --- nix-meson-build-support/common/meson.build | 3 +++ src/libcmd/meson.build | 2 +- src/libexpr/meson.build | 2 +- src/libstore/meson.build | 2 +- src/libutil/meson.build | 2 +- src/nix/meson.build | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index df8b958c0..bb57ca941 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -19,6 +19,9 @@ add_project_arguments( language : 'cpp', ) +# GCC doesn't benefit much from precompiled headers. +do_pch = cxx.get_id() == 'clang' + # This is a clang-only option for improving build times. # It forces the instantiation of templates in the PCH itself and # not every translation unit it's included in. diff --git a/src/libcmd/meson.build b/src/libcmd/meson.build index 5c3dd91ee..0cb41b46f 100644 --- a/src/libcmd/meson.build +++ b/src/libcmd/meson.build @@ -92,7 +92,7 @@ this_library = library( link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, - cpp_pch : ['pch/precompiled-headers.hh'] + cpp_pch : do_pch ? ['pch/precompiled-headers.hh'] : [] ) install_headers(headers, subdir : 'nix/cmd', preserve_path : true) diff --git a/src/libexpr/meson.build b/src/libexpr/meson.build index fe795a607..9c8569293 100644 --- a/src/libexpr/meson.build +++ b/src/libexpr/meson.build @@ -178,7 +178,7 @@ this_library = library( link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, - cpp_pch : ['pch/precompiled-headers.hh'] + cpp_pch : do_pch ? ['pch/precompiled-headers.hh'] : [] ) install_headers(headers, subdir : 'nix/expr', preserve_path : true) diff --git a/src/libstore/meson.build b/src/libstore/meson.build index c243f19c9..708188178 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -350,7 +350,7 @@ this_library = library( link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, - cpp_pch : ['pch/precompiled-headers.hh'] + cpp_pch : do_pch ? ['pch/precompiled-headers.hh'] : [] ) install_headers(headers, subdir : 'nix/store', preserve_path : true) diff --git a/src/libutil/meson.build b/src/libutil/meson.build index ced9c424d..881a8674c 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -191,7 +191,7 @@ this_library = library( link_args: linker_export_flags, prelink : true, # For C++ static initializers install : true, - cpp_pch : 'pch/precompiled-headers.hh' + cpp_pch : do_pch ? ['pch/precompiled-headers.hh'] : [] ) install_headers(headers, subdir : 'nix/util', preserve_path : true) diff --git a/src/nix/meson.build b/src/nix/meson.build index 586ee15c3..23b876690 100644 --- a/src/nix/meson.build +++ b/src/nix/meson.build @@ -186,7 +186,7 @@ this_exe = executable( include_directories : include_dirs, link_args: linker_export_flags, install : true, - cpp_pch : ['pch/precompiled-headers.hh'] + cpp_pch : do_pch ? ['pch/precompiled-headers.hh'] : [] ) meson.override_find_program('nix', this_exe)