From c105846646d3bdb5ebc71a1b5929d59445eebb67 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Wed, 8 Oct 2025 02:51:19 +0300 Subject: [PATCH] meson: Add option for controlling PCH In practice it turns out that turning off PCH is pretty useful when debugging incorrect includes. I didn't want to add this option initially because of the sheer amount of copy-pasta that meson requires. But considering that this is useful and the cost of copying the option a single time is not too high this seems acceptable. --- meson.options | 10 ++++++++++ nix-meson-build-support/common/meson.build | 8 ++++++-- src/libcmd/meson.options | 10 ++++++++++ src/libexpr-tests/meson.options | 10 ++++++++++ src/libexpr/meson.options | 10 ++++++++++ src/libfetchers/meson.options | 10 ++++++++++ src/libstore-tests/meson.options | 10 ++++++++++ src/libstore/meson.options | 10 ++++++++++ src/libutil-tests/meson.options | 10 ++++++++++ src/libutil/meson.options | 10 ++++++++++ src/nix/meson.options | 10 ++++++++++ 11 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/libexpr-tests/meson.options create mode 100644 src/libfetchers/meson.options create mode 100644 src/libutil-tests/meson.options diff --git a/meson.options b/meson.options index d2c9fa40c..8ca104e64 100644 --- a/meson.options +++ b/meson.options @@ -27,3 +27,13 @@ option( value : false, description : 'Build benchmarks (requires gbenchmark)', ) + +# Emulating 'auto' options, since we don't want auto_features to affect this +# and there's no other way of conditionally defaulting the value. +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', +) diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 8c4e98862..97eddf165 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -29,7 +29,11 @@ add_project_arguments( ) # GCC doesn't benefit much from precompiled headers. -do_pch = cxx.get_id() == 'clang' +if get_option('pch') == 'auto' + do_pch = cxx.get_id() == 'clang' +else + do_pch = get_option('pch') == 'enabled' +endif # This is a clang-only option for improving build times. # It forces the instantiation of templates in the PCH itself and @@ -38,7 +42,7 @@ do_pch = cxx.get_id() == 'clang' # bother checking the version. # This feature helps in particular with the expensive nlohmann::json template # instantiations in libutil and libstore. -if cxx.get_id() == 'clang' +if cxx.get_id() == 'clang' and do_pch add_project_arguments('-fpch-instantiate-templates', language : 'cpp') endif diff --git a/src/libcmd/meson.options b/src/libcmd/meson.options index 31178d82f..cbfd20934 100644 --- a/src/libcmd/meson.options +++ b/src/libcmd/meson.options @@ -13,3 +13,13 @@ option( value : 'editline', description : 'Which library to use for nice line editing with the Nix language REPL', ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) + diff --git a/src/libexpr-tests/meson.options b/src/libexpr-tests/meson.options new file mode 100644 index 000000000..d74758b9a --- /dev/null +++ b/src/libexpr-tests/meson.options @@ -0,0 +1,10 @@ +# vim: filetype=meson + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) diff --git a/src/libexpr/meson.options b/src/libexpr/meson.options index 847bb211d..058c6483d 100644 --- a/src/libexpr/meson.options +++ b/src/libexpr/meson.options @@ -3,3 +3,13 @@ option( type : 'feature', description : 'enable garbage collection in the Nix expression evaluator (requires Boehm GC)', ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) + diff --git a/src/libfetchers/meson.options b/src/libfetchers/meson.options new file mode 100644 index 000000000..d74758b9a --- /dev/null +++ b/src/libfetchers/meson.options @@ -0,0 +1,10 @@ +# vim: filetype=meson + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) diff --git a/src/libstore-tests/meson.options b/src/libstore-tests/meson.options index 2b3c1af60..bdfb66a02 100644 --- a/src/libstore-tests/meson.options +++ b/src/libstore-tests/meson.options @@ -7,3 +7,13 @@ option( description : 'Build benchmarks (requires gbenchmark)', yield : true, ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) + diff --git a/src/libstore/meson.options b/src/libstore/meson.options index edc43bd45..7e848e3a2 100644 --- a/src/libstore/meson.options +++ b/src/libstore/meson.options @@ -40,3 +40,13 @@ option( value : 'disabled', description : 'Enable curl-based S3 binary cache store support (requires aws-crt-cpp and curl >= 7.75.0)', ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) + diff --git a/src/libutil-tests/meson.options b/src/libutil-tests/meson.options new file mode 100644 index 000000000..d74758b9a --- /dev/null +++ b/src/libutil-tests/meson.options @@ -0,0 +1,10 @@ +# vim: filetype=meson + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) diff --git a/src/libutil/meson.options b/src/libutil/meson.options index a82806162..bb90ab875 100644 --- a/src/libutil/meson.options +++ b/src/libutil/meson.options @@ -5,3 +5,13 @@ option( type : 'feature', description : 'determine microarchitecture levels with libcpuid (only relevant on x86_64)', ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) + diff --git a/src/nix/meson.options b/src/nix/meson.options index 0fc680cfe..a9859ecda 100644 --- a/src/nix/meson.options +++ b/src/nix/meson.options @@ -7,3 +7,13 @@ option( value : 'etc/profile.d', description : 'the path to install shell profile files', ) + +option( + 'pch', + type : 'combo', + choices : [ 'auto', 'enabled', 'disabled' ], + value : 'auto', + description : 'Use C++ Precompiled Headers to speed up compilation', + yield : true, +) +