pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH v12 15/15] meson: Add support for building with precompiled headers
11+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2022-10-06 4289263cf2  windows: Adjust FD_SETSIZE via commandline define
* [PATCH v12 15/15] meson: Add support for building with precompiled headers
@ 2022-08-27 16:49 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-08-27 16:49 UTC (permalink / raw)

This substantially speeds up building for windows. A cross build with mingw
goes from

real	0m29.884s
user	15m41.900s
sys	1m58.257s

to

real	0m13.196s
user	6m52.330s
sys	1m15.140s

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers).
---
 src/include/meson.build           | 1 +
 src/include/pch/c_pch.h           | 1 +
 src/include/pch/meson.build       | 4 ++++
 src/include/pch/postgres_fe_pch.h | 1 +
 src/include/pch/postgres_pch.h    | 1 +
 src/common/meson.build            | 2 ++
 src/port/meson.build              | 2 ++
 src/backend/meson.build           | 5 +++++
 src/backend/snowball/meson.build  | 1 +
 src/fe_utils/meson.build          | 1 +
 src/bin/pg_dump/meson.build       | 1 +
 src/bin/pg_upgrade/meson.build    | 1 +
 src/bin/psql/meson.build          | 1 +
 src/pl/plperl/meson.build         | 1 +
 src/pl/plpgsql/src/meson.build    | 1 +
 src/pl/plpython/meson.build       | 1 +
 src/pl/tcl/meson.build            | 1 +
 contrib/bloom/meson.build         | 1 +
 contrib/btree_gist/meson.build    | 1 +
 contrib/hstore/meson.build        | 1 +
 contrib/pg_trgm/meson.build       | 1 +
 contrib/pgcrypto/meson.build      | 1 +
 contrib/pgstattuple/meson.build   | 1 +
 contrib/sepgsql/meson.build       | 1 +
 contrib/xml2/meson.build          | 1 +
 .cirrus.yml                       | 4 ++--
 meson.build                       | 8 ++++++++
 27 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 src/include/pch/c_pch.h
 create mode 100644 src/include/pch/meson.build
 create mode 100644 src/include/pch/postgres_fe_pch.h
 create mode 100644 src/include/pch/postgres_pch.h

inline patch 1: src/include/meson.build, src/include/pch/c_pch.h, src/include/pch/meson.build and 24 more (+44/-2 lines) download inline-1.patchdiff --git a/src/include/meson.build b/src/include/meson.build index 66991c43d35..d1b58f14842 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -111,6 +111,7 @@ install_headers( subdir('catalog') subdir('nodes') subdir('parser') +subdir('pch') subdir('storage') subdir('utils') diff --git a/src/include/pch/c_pch.h b/src/include/pch/c_pch.h new file mode 100644 index 00000000000..f40c757ca62 --- /dev/null +++ b/src/include/pch/c_pch.h @@ -0,0 +1 @@ +#include "c.h" diff --git a/src/include/pch/meson.build b/src/include/pch/meson.build new file mode 100644 index 00000000000..2bcec49c3a2 --- /dev/null +++ b/src/include/pch/meson.build @@ -0,0 +1,4 @@ +# See https://github.com/mesonbuild/meson/issues/10338 +pch_c_h = meson.source_root() / meson.current_source_dir() / 'c_pch.h' +pch_postgres_h = meson.source_root() / meson.current_source_dir() / 'postgres_pch.h' +pch_postgres_fe_h = meson.source_root() / meson.current_source_dir() / 'postgres_fe_pch.h' diff --git a/src/include/pch/postgres_fe_pch.h b/src/include/pch/postgres_fe_pch.h new file mode 100644 index 00000000000..f3ea20912d3 --- /dev/null +++ b/src/include/pch/postgres_fe_pch.h @@ -0,0 +1 @@ +#include "postgres_fe.h" diff --git a/src/include/pch/postgres_pch.h b/src/include/pch/postgres_pch.h new file mode 100644 index 00000000000..71b2f35f76b --- /dev/null +++ b/src/include/pch/postgres_pch.h @@ -0,0 +1 @@ +#include "postgres.h" diff --git a/src/common/meson.build b/src/common/meson.build index 23842e1ffef..1c9b8a3a018 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -147,6 +147,7 @@ foreach name, opts : pgcommon_variants endif c_args = opts.get('c_args', []) + common_cflags[cflagname] cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname), + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'sources': sources, @@ -159,6 +160,7 @@ foreach name, opts : pgcommon_variants lib = static_library('libpgcommon@0@'.format(name), link_with: cflag_libs, + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], diff --git a/src/port/meson.build b/src/port/meson.build index ced2e014db8..c2222696f1b 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -161,6 +161,7 @@ foreach name, opts : pgport_variants c_args = opts.get('c_args', []) + pgport_cflags[cflagname] cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname), sources, + c_pch: pch_c_h, kwargs: opts + { 'c_args': c_args, 'build_by_default': false, @@ -172,6 +173,7 @@ foreach name, opts : pgport_variants lib = static_library('libpgport@0@'.format(name), pgport_sources, link_with: cflag_libs, + c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], } diff --git a/src/backend/meson.build b/src/backend/meson.build index 3a2fc51bda3..784a8ba7072 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -59,6 +59,7 @@ postgres_lib = static_library('postgres', backend_sources + timezone_sources + generated_backend_sources, link_whole: backend_link_with, dependencies: backend_build_deps, + c_pch: pch_postgres_h, kwargs: internal_lib_args, ) @@ -78,6 +79,10 @@ if cc.get_id() == 'msvc' backend_link_args += '/DEF:@0@'.format(postgres_def.full_path()) backend_link_depends += postgres_def + # Due to the way msvc and meson's precompiled headers implementation + # interact, we need to have symbols from the full library available. Could + # be restricted to b_pch=true. + backend_link_with += postgres_lib elif host_system == 'aix' # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build index 8c6f685cb32..2747026c729 100644 --- a/src/backend/snowball/meson.build +++ b/src/backend/snowball/meson.build @@ -60,6 +60,7 @@ stemmer_inc = include_directories('../../include/snowball') dict_snowball = shared_module('dict_snowball', dict_snowball_sources, + c_pch: pch_postgres_h, kwargs: pg_mod_args + { 'include_directories': [stemmer_inc], } diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index 29c24257328..6e1cce9bd0d 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,6 +23,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, + c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], dependencies: frontend_common_code, kwargs: default_lib_args, diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index ee8daa7d06a..9be697daef4 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -23,6 +23,7 @@ endif pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq, zlib], kwargs: internal_lib_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index 52324601181..59e06b761fd 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -18,6 +18,7 @@ pg_upgrade_sources = files( pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq], kwargs: default_bin_args, ) diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index 626ac8cd105..20939b0740c 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -48,6 +48,7 @@ endif executable('psql', psql_sources, + c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), dependencies: [frontend_code, libpq, readline], kwargs: default_bin_args, diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build index 6831011edac..5be58ceaa19 100644 --- a/src/pl/plperl/meson.build +++ b/src/pl/plperl/meson.build @@ -41,6 +41,7 @@ endforeach plperl_inc = include_directories('.') shared_module('plperl', plperl_sources, + c_pch: pch_postgres_h, include_directories: [plperl_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [perl_dep, pg_mod_args['dependencies']], diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build index c4c94a312e1..39302f8d032 100644 --- a/src/pl/plpgsql/src/meson.build +++ b/src/pl/plpgsql/src/meson.build @@ -42,6 +42,7 @@ plpgsql_sources += pl_unreserved shared_module('plpgsql', plpgsql_sources, + c_pch: pch_postgres_h, include_directories: include_directories('.'), kwargs: pg_mod_args, ) diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build index e9e77ae3691..d41f30c8022 100644 --- a/src/pl/plpython/meson.build +++ b/src/pl/plpython/meson.build @@ -30,6 +30,7 @@ plpython_inc = include_directories('.') shared_module('plpython3', plpython_sources, + c_pch: pch_postgres_h, include_directories: [plpython_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [python3_dep, pg_mod_args['dependencies']], diff --git a/src/pl/tcl/meson.build b/src/pl/tcl/meson.build index 1acb49f1637..16bfd7806b4 100644 --- a/src/pl/tcl/meson.build +++ b/src/pl/tcl/meson.build @@ -16,6 +16,7 @@ pltcl_sources += custom_target('pltclerrcodes.h', shared_module('pltcl', pltcl_sources, + c_pch: pch_postgres_h, include_directories: [include_directories('.'), postgres_inc], kwargs: pg_mod_args + { 'dependencies': [tcl_dep, pg_mod_args['dependencies']], diff --git a/contrib/bloom/meson.build b/contrib/bloom/meson.build index 311cc10c557..f2a73b06667 100644 --- a/contrib/bloom/meson.build +++ b/contrib/bloom/meson.build @@ -9,6 +9,7 @@ bloom_sources = files( bloom = shared_module('bloom', bloom_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build index 6bd91b88fc3..f33bae7f8fe 100644 --- a/contrib/btree_gist/meson.build +++ b/contrib/btree_gist/meson.build @@ -27,6 +27,7 @@ btree_gist_sources = files( btree_gist = shared_module('btree_gist', btree_gist_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) diff --git a/contrib/hstore/meson.build b/contrib/hstore/meson.build index 369c60d7f40..cac6d179351 100644 --- a/contrib/hstore/meson.build +++ b/contrib/hstore/meson.build @@ -10,6 +10,7 @@ hstore = shared_module('hstore', 'hstore_op.c', 'hstore_subs.c', ), + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) diff --git a/contrib/pg_trgm/meson.build b/contrib/pg_trgm/meson.build index 37931279f65..6818cddc63f 100644 --- a/contrib/pg_trgm/meson.build +++ b/contrib/pg_trgm/meson.build @@ -5,6 +5,7 @@ pg_trgm = shared_module('pg_trgm', 'trgm_op.c', 'trgm_regexp.c', ), + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) diff --git a/contrib/pgcrypto/meson.build b/contrib/pgcrypto/meson.build index 647bea8559e..ec022096c31 100644 --- a/contrib/pgcrypto/meson.build +++ b/contrib/pgcrypto/meson.build @@ -72,6 +72,7 @@ endif pgcrypto = shared_module('pgcrypto', pgcrypto_sources, link_with: pgcrypto_link_with, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [pgcrypto_deps, contrib_mod_args['dependencies']] }, diff --git a/contrib/pgstattuple/meson.build b/contrib/pgstattuple/meson.build index 190f8b5d92b..8e765fc997a 100644 --- a/contrib/pgstattuple/meson.build +++ b/contrib/pgstattuple/meson.build @@ -4,6 +4,7 @@ pgstattuple = shared_module('pgstattuple', 'pgstatindex.c', 'pgstattuple.c', ), + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) diff --git a/contrib/sepgsql/meson.build b/contrib/sepgsql/meson.build index 83e74f035b1..019c31750f2 100644 --- a/contrib/sepgsql/meson.build +++ b/contrib/sepgsql/meson.build @@ -16,6 +16,7 @@ sepgsql_sources = files( sepgsql = shared_module('sepgsql', sepgsql_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [selinux, contrib_mod_args['dependencies']], } diff --git a/contrib/xml2/meson.build b/contrib/xml2/meson.build index dcc7bf5bf69..d25549a1fb3 100644 --- a/contrib/xml2/meson.build +++ b/contrib/xml2/meson.build @@ -7,6 +7,7 @@ xml2 = shared_module('pgxml', 'xpath.c', 'xslt_proc.c', ), + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']], }, diff --git a/.cirrus.yml b/.cirrus.yml index 37fc5b551ec..88975bb017d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1158,7 +1158,7 @@ task: configure_script: - vcvarsall x64 - - meson setup --buildtype debug --backend ninja -Dcassert=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build + - meson setup --buildtype debug --backend ninja -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build build_script: - vcvarsall x64 @@ -1185,7 +1185,7 @@ task: configure_script: - vcvarsall x64 - - meson setup --buildtype debug --backend vs -Dcassert=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build + - meson setup --buildtype debug --backend vs -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build build_script: - vcvarsall x64 diff --git a/meson.build b/meson.build index b9eaad73628..bf4e561be89 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ project('postgresql', meson_version: '>=0.54', default_options: [ 'warning_level=2', + 'b_pch=false', 'buildtype=release', ] ) @@ -1716,6 +1717,13 @@ if cc.get_id() == 'msvc' '/wd4267', ] + # Dirty hack to disable warnings due to some files defining + # UMDF_USING_NTSTATUS before including postgres.h. We need a better fix, but + # for now this allows us to see "real" warnings. + if get_option('b_pch') + cflags_warn += '/wd4005' + endif + cppflags += [ '/DWIN32', '/DWINDOWS', -- 2.37.0.3.g30cc8d0f14
--3jz64y4qgcz5d4ku-- ^ permalink raw reply [nested|flat] 11+ messages in thread

* [PATCH v15 11/14] meson: Add support for building with precompiled headers
@ 2022-09-23 19:19 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-09-23 19:19 UTC (permalink / raw)

This substantially speeds up building for windows. A cross build with mingw
goes from

real	0m29.884s
user	15m41.900s
sys	1m58.257s

to

real	0m13.196s
user	6m52.330s
sys	1m15.140s

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers).
---
 src/include/meson.build           | 1 +
 src/include/pch/c_pch.h           | 1 +
 src/include/pch/meson.build       | 4 ++++
 src/include/pch/postgres_fe_pch.h | 1 +
 src/include/pch/postgres_pch.h    | 1 +
 src/common/meson.build            | 2 ++
 src/port/meson.build              | 2 ++
 src/backend/meson.build           | 5 +++++
 src/backend/snowball/meson.build  | 1 +
 src/fe_utils/meson.build          | 1 +
 src/bin/pg_dump/meson.build       | 1 +
 src/bin/pg_upgrade/meson.build    | 1 +
 src/bin/psql/meson.build          | 1 +
 src/interfaces/libpq/meson.build  | 1 +
 src/pl/plperl/meson.build         | 1 +
 src/pl/plpgsql/src/meson.build    | 1 +
 src/pl/plpython/meson.build       | 1 +
 src/pl/tcl/meson.build            | 1 +
 contrib/bloom/meson.build         | 1 +
 contrib/btree_gist/meson.build    | 1 +
 contrib/hstore/meson.build        | 1 +
 contrib/pg_trgm/meson.build       | 1 +
 contrib/pgcrypto/meson.build      | 1 +
 contrib/pgstattuple/meson.build   | 1 +
 contrib/sepgsql/meson.build       | 1 +
 contrib/xml2/meson.build          | 1 +
 .cirrus.yml                       | 4 ++--
 meson.build                       | 8 ++++++++
 28 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 src/include/pch/c_pch.h
 create mode 100644 src/include/pch/meson.build
 create mode 100644 src/include/pch/postgres_fe_pch.h
 create mode 100644 src/include/pch/postgres_pch.h

inline patch 1: src/include/meson.build, src/include/pch/c_pch.h, src/include/pch/meson.build and 25 more (+45/-2 lines) download inline-1.patchdiff --git a/src/include/meson.build b/src/include/meson.build index e5390df0584..28ed9011c70 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -110,6 +110,7 @@ install_headers( subdir('catalog') subdir('nodes') +subdir('pch') subdir('storage') subdir('utils') diff --git a/src/include/pch/c_pch.h b/src/include/pch/c_pch.h new file mode 100644 index 00000000000..f40c757ca62 --- /dev/null +++ b/src/include/pch/c_pch.h @@ -0,0 +1 @@ +#include "c.h" diff --git a/src/include/pch/meson.build b/src/include/pch/meson.build new file mode 100644 index 00000000000..2bcec49c3a2 --- /dev/null +++ b/src/include/pch/meson.build @@ -0,0 +1,4 @@ +# See https://github.com/mesonbuild/meson/issues/10338 +pch_c_h = meson.source_root() / meson.current_source_dir() / 'c_pch.h' +pch_postgres_h = meson.source_root() / meson.current_source_dir() / 'postgres_pch.h' +pch_postgres_fe_h = meson.source_root() / meson.current_source_dir() / 'postgres_fe_pch.h' diff --git a/src/include/pch/postgres_fe_pch.h b/src/include/pch/postgres_fe_pch.h new file mode 100644 index 00000000000..f3ea20912d3 --- /dev/null +++ b/src/include/pch/postgres_fe_pch.h @@ -0,0 +1 @@ +#include "postgres_fe.h" diff --git a/src/include/pch/postgres_pch.h b/src/include/pch/postgres_pch.h new file mode 100644 index 00000000000..71b2f35f76b --- /dev/null +++ b/src/include/pch/postgres_pch.h @@ -0,0 +1 @@ +#include "postgres.h" diff --git a/src/common/meson.build b/src/common/meson.build index 23842e1ffef..1c9b8a3a018 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -147,6 +147,7 @@ foreach name, opts : pgcommon_variants endif c_args = opts.get('c_args', []) + common_cflags[cflagname] cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname), + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'sources': sources, @@ -159,6 +160,7 @@ foreach name, opts : pgcommon_variants lib = static_library('libpgcommon@0@'.format(name), link_with: cflag_libs, + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], diff --git a/src/port/meson.build b/src/port/meson.build index ced2e014db8..c2222696f1b 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -161,6 +161,7 @@ foreach name, opts : pgport_variants c_args = opts.get('c_args', []) + pgport_cflags[cflagname] cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname), sources, + c_pch: pch_c_h, kwargs: opts + { 'c_args': c_args, 'build_by_default': false, @@ -172,6 +173,7 @@ foreach name, opts : pgport_variants lib = static_library('libpgport@0@'.format(name), pgport_sources, link_with: cflag_libs, + c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], } diff --git a/src/backend/meson.build b/src/backend/meson.build index 1cb4cd3431f..a535543ee9e 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -62,6 +62,7 @@ postgres_lib = static_library('postgres_lib', backend_sources + timezone_sources + generated_backend_sources, link_whole: backend_link_with, dependencies: backend_build_deps, + c_pch: pch_postgres_h, kwargs: internal_lib_args, ) @@ -81,6 +82,10 @@ if cc.get_id() == 'msvc' backend_link_args += '/DEF:@0@'.format(postgres_def.full_path()) backend_link_depends += postgres_def + # Due to the way msvc and meson's precompiled headers implementation + # interact, we need to have symbols from the full library available. Could + # be restricted to b_pch=true. + backend_link_with += postgres_lib elif host_system == 'aix' # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build index 974401d187e..72959fa29d6 100644 --- a/src/backend/snowball/meson.build +++ b/src/backend/snowball/meson.build @@ -66,6 +66,7 @@ endif dict_snowball = shared_module('dict_snowball', dict_snowball_sources, + c_pch: pch_postgres_h, kwargs: pg_mod_args + { 'include_directories': [stemmer_inc], } diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index b6bf8e1ca21..f1ba5ac8c14 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,6 +23,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, + c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], dependencies: frontend_common_code, kwargs: default_lib_args, diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index 3527a25c288..e66f632b54e 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -13,6 +13,7 @@ pg_dump_common_sources = files( pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq, zlib], kwargs: internal_lib_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index a7b927a45c7..212bc9ce6ef 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -24,6 +24,7 @@ endif pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq], kwargs: default_bin_args, ) diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index 3474389d3b6..8ec07260d1b 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -46,6 +46,7 @@ endif psql = executable('psql', psql_sources, + c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), dependencies: [frontend_code, libpq, readline], kwargs: default_bin_args, diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 2c9edeaa088..72102521edc 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -49,6 +49,7 @@ libpq_st = static_library('libpq', pic: true, include_directories: [libpq_inc, postgres_inc], c_args: ['-DSO_MAJOR_VERSION=5'], + c_pch: pch_postgres_fe_h, dependencies: libpq_deps, kwargs: default_lib_args, ) diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build index 535660085dd..cd3894e6a73 100644 --- a/src/pl/plperl/meson.build +++ b/src/pl/plperl/meson.build @@ -45,6 +45,7 @@ endif plperl = shared_module('plperl', plperl_sources, + c_pch: pch_postgres_h, include_directories: [plperl_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [perl_dep, pg_mod_args['dependencies']], diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build index c46c0a1da2a..27b2f5ef529 100644 --- a/src/pl/plpgsql/src/meson.build +++ b/src/pl/plpgsql/src/meson.build @@ -48,6 +48,7 @@ endif plpgsql = shared_module('plpgsql', plpgsql_sources, + c_pch: pch_postgres_h, include_directories: include_directories('.'), kwargs: pg_mod_args, ) diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build index 40888386b5f..7bd683580e8 100644 --- a/src/pl/plpython/meson.build +++ b/src/pl/plpython/meson.build @@ -36,6 +36,7 @@ endif plpython = shared_module('plpython3', plpython_sources, + c_pch: pch_postgres_h, include_directories: [plpython_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [python3_dep, pg_mod_args['dependencies']], diff --git a/src/pl/tcl/meson.build b/src/pl/tcl/meson.build index f09bb14c950..7a708776c99 100644 --- a/src/pl/tcl/meson.build +++ b/src/pl/tcl/meson.build @@ -22,6 +22,7 @@ endif pltcl = shared_module('pltcl', pltcl_sources, + c_pch: pch_postgres_h, include_directories: [include_directories('.'), postgres_inc], kwargs: pg_mod_args + { 'dependencies': [tcl_dep, pg_mod_args['dependencies']], diff --git a/contrib/bloom/meson.build b/contrib/bloom/meson.build index 16f3b83e4d2..163a93c98fb 100644 --- a/contrib/bloom/meson.build +++ b/contrib/bloom/meson.build @@ -15,6 +15,7 @@ endif bloom = shared_module('bloom', bloom_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += bloom diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build index e98c91dacc8..bfb7865d213 100644 --- a/contrib/btree_gist/meson.build +++ b/contrib/btree_gist/meson.build @@ -33,6 +33,7 @@ endif btree_gist = shared_module('btree_gist', btree_gist_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += btree_gist diff --git a/contrib/hstore/meson.build b/contrib/hstore/meson.build index 2bb26bb772b..a2a4ec36cb0 100644 --- a/contrib/hstore/meson.build +++ b/contrib/hstore/meson.build @@ -18,6 +18,7 @@ endif hstore = shared_module('hstore', hstore_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += hstore diff --git a/contrib/pg_trgm/meson.build b/contrib/pg_trgm/meson.build index c8c7c07b308..839d6c4a7f6 100644 --- a/contrib/pg_trgm/meson.build +++ b/contrib/pg_trgm/meson.build @@ -13,6 +13,7 @@ endif pg_trgm = shared_module('pg_trgm', pg_trgm_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pg_trgm diff --git a/contrib/pgcrypto/meson.build b/contrib/pgcrypto/meson.build index 7fc7bbc7ca1..cc782578b49 100644 --- a/contrib/pgcrypto/meson.build +++ b/contrib/pgcrypto/meson.build @@ -78,6 +78,7 @@ endif pgcrypto = shared_module('pgcrypto', pgcrypto_sources, link_with: pgcrypto_link_with, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [pgcrypto_deps, contrib_mod_args['dependencies']] }, diff --git a/contrib/pgstattuple/meson.build b/contrib/pgstattuple/meson.build index 05e4cd46a5c..42d0b0e6ce9 100644 --- a/contrib/pgstattuple/meson.build +++ b/contrib/pgstattuple/meson.build @@ -12,6 +12,7 @@ endif pgstattuple = shared_module('pgstattuple', pgstattuple_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pgstattuple diff --git a/contrib/sepgsql/meson.build b/contrib/sepgsql/meson.build index 8bef239e3c2..1ac0fa388ab 100644 --- a/contrib/sepgsql/meson.build +++ b/contrib/sepgsql/meson.build @@ -22,6 +22,7 @@ endif sepgsql = shared_module('sepgsql', sepgsql_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [selinux, contrib_mod_args['dependencies']], } diff --git a/contrib/xml2/meson.build b/contrib/xml2/meson.build index 89b0d677516..92ab3368428 100644 --- a/contrib/xml2/meson.build +++ b/contrib/xml2/meson.build @@ -15,6 +15,7 @@ endif xml2 = shared_module('pgxml', xml2_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']], }, diff --git a/.cirrus.yml b/.cirrus.yml index 965483550d1..a0e7acf5ec9 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -602,7 +602,7 @@ task: # Use /DEBUG:FASTLINK to avoid high memory usage during linking configure_script: | vcvarsall x64 - meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 @@ -630,7 +630,7 @@ task: configure_script: | vcvarsall x64 - meson setup --buildtype debug --backend vs -Dcassert=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --buildtype debug --backend vs -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 diff --git a/meson.build b/meson.build index 2b0cbb9a5a7..6ee9bbb3f46 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ project('postgresql', meson_version: '>=0.54', default_options: [ 'warning_level=1', #-Wall equivalent + 'b_pch=false', 'buildtype=release', ] ) @@ -1767,6 +1768,13 @@ if cc.get_id() == 'msvc' '/wd4267', # conversion from 'size_t' to 'type', possible loss of data ] + # Dirty hack to disable warnings due to some files defining + # UMDF_USING_NTSTATUS before including postgres.h. We need a better fix, but + # for now this allows us to see "real" warnings. + if get_option('b_pch') + cflags_warn += '/wd4005' # macro redefinition + endif + cppflags += [ '/DWIN32', '/DWINDOWS', -- 2.37.3.542.gdd3f6c4cae
--ayx3t42hstokjw3l Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v15-0012-meson-Add-xmllint-xsltproc-wrapper-script-to-han.patch" ^ permalink raw reply [nested|flat] 11+ messages in thread

* [PATCH v16 12/16] meson: Add support for building with precompiled headers
@ 2022-09-23 19:19 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-09-23 19:19 UTC (permalink / raw)

This substantially speeds up building for windows. A cross build with mingw
goes from

real	0m29.884s
user	15m41.900s
sys	1m58.257s

to

real	0m13.196s
user	6m52.330s
sys	1m15.140s

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers).
---
 src/include/meson.build           | 1 +
 src/include/pch/c_pch.h           | 1 +
 src/include/pch/meson.build       | 4 ++++
 src/include/pch/postgres_fe_pch.h | 1 +
 src/include/pch/postgres_pch.h    | 1 +
 src/common/meson.build            | 2 ++
 src/port/meson.build              | 2 ++
 src/backend/meson.build           | 5 +++++
 src/backend/snowball/meson.build  | 1 +
 src/fe_utils/meson.build          | 1 +
 src/bin/pg_dump/meson.build       | 1 +
 src/bin/pg_upgrade/meson.build    | 1 +
 src/bin/psql/meson.build          | 1 +
 src/interfaces/libpq/meson.build  | 1 +
 src/pl/plperl/meson.build         | 1 +
 src/pl/plpgsql/src/meson.build    | 1 +
 src/pl/plpython/meson.build       | 1 +
 src/pl/tcl/meson.build            | 1 +
 contrib/bloom/meson.build         | 1 +
 contrib/btree_gist/meson.build    | 1 +
 contrib/hstore/meson.build        | 1 +
 contrib/pg_trgm/meson.build       | 1 +
 contrib/pgcrypto/meson.build      | 1 +
 contrib/pgstattuple/meson.build   | 1 +
 contrib/sepgsql/meson.build       | 1 +
 contrib/xml2/meson.build          | 1 +
 .cirrus.yml                       | 4 ++--
 meson.build                       | 1 +
 28 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 src/include/pch/c_pch.h
 create mode 100644 src/include/pch/meson.build
 create mode 100644 src/include/pch/postgres_fe_pch.h
 create mode 100644 src/include/pch/postgres_pch.h

inline patch 1: src/include/meson.build, src/include/pch/c_pch.h, src/include/pch/meson.build and 25 more (+38/-2 lines) download inline-1.patchdiff --git a/src/include/meson.build b/src/include/meson.build index e5390df0584..28ed9011c70 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -110,6 +110,7 @@ install_headers( subdir('catalog') subdir('nodes') +subdir('pch') subdir('storage') subdir('utils') diff --git a/src/include/pch/c_pch.h b/src/include/pch/c_pch.h new file mode 100644 index 00000000000..f40c757ca62 --- /dev/null +++ b/src/include/pch/c_pch.h @@ -0,0 +1 @@ +#include "c.h" diff --git a/src/include/pch/meson.build b/src/include/pch/meson.build new file mode 100644 index 00000000000..2bcec49c3a2 --- /dev/null +++ b/src/include/pch/meson.build @@ -0,0 +1,4 @@ +# See https://github.com/mesonbuild/meson/issues/10338 +pch_c_h = meson.source_root() / meson.current_source_dir() / 'c_pch.h' +pch_postgres_h = meson.source_root() / meson.current_source_dir() / 'postgres_pch.h' +pch_postgres_fe_h = meson.source_root() / meson.current_source_dir() / 'postgres_fe_pch.h' diff --git a/src/include/pch/postgres_fe_pch.h b/src/include/pch/postgres_fe_pch.h new file mode 100644 index 00000000000..f3ea20912d3 --- /dev/null +++ b/src/include/pch/postgres_fe_pch.h @@ -0,0 +1 @@ +#include "postgres_fe.h" diff --git a/src/include/pch/postgres_pch.h b/src/include/pch/postgres_pch.h new file mode 100644 index 00000000000..71b2f35f76b --- /dev/null +++ b/src/include/pch/postgres_pch.h @@ -0,0 +1 @@ +#include "postgres.h" diff --git a/src/common/meson.build b/src/common/meson.build index 23842e1ffef..1c9b8a3a018 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -147,6 +147,7 @@ foreach name, opts : pgcommon_variants endif c_args = opts.get('c_args', []) + common_cflags[cflagname] cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname), + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'sources': sources, @@ -159,6 +160,7 @@ foreach name, opts : pgcommon_variants lib = static_library('libpgcommon@0@'.format(name), link_with: cflag_libs, + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], diff --git a/src/port/meson.build b/src/port/meson.build index ced2e014db8..c2222696f1b 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -161,6 +161,7 @@ foreach name, opts : pgport_variants c_args = opts.get('c_args', []) + pgport_cflags[cflagname] cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname), sources, + c_pch: pch_c_h, kwargs: opts + { 'c_args': c_args, 'build_by_default': false, @@ -172,6 +173,7 @@ foreach name, opts : pgport_variants lib = static_library('libpgport@0@'.format(name), pgport_sources, link_with: cflag_libs, + c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], } diff --git a/src/backend/meson.build b/src/backend/meson.build index 1cb4cd3431f..a535543ee9e 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -62,6 +62,7 @@ postgres_lib = static_library('postgres_lib', backend_sources + timezone_sources + generated_backend_sources, link_whole: backend_link_with, dependencies: backend_build_deps, + c_pch: pch_postgres_h, kwargs: internal_lib_args, ) @@ -81,6 +82,10 @@ if cc.get_id() == 'msvc' backend_link_args += '/DEF:@0@'.format(postgres_def.full_path()) backend_link_depends += postgres_def + # Due to the way msvc and meson's precompiled headers implementation + # interact, we need to have symbols from the full library available. Could + # be restricted to b_pch=true. + backend_link_with += postgres_lib elif host_system == 'aix' # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build index 974401d187e..72959fa29d6 100644 --- a/src/backend/snowball/meson.build +++ b/src/backend/snowball/meson.build @@ -66,6 +66,7 @@ endif dict_snowball = shared_module('dict_snowball', dict_snowball_sources, + c_pch: pch_postgres_h, kwargs: pg_mod_args + { 'include_directories': [stemmer_inc], } diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index 3e226c260ac..fe0b801387c 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,6 +23,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, + c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], dependencies: frontend_common_code, diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index 3527a25c288..e66f632b54e 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -13,6 +13,7 @@ pg_dump_common_sources = files( pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq, zlib], kwargs: internal_lib_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index a7b927a45c7..212bc9ce6ef 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -24,6 +24,7 @@ endif pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq], kwargs: default_bin_args, ) diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index 1264fc19fbd..a4c46bf5385 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -44,6 +44,7 @@ endif psql = executable('psql', psql_sources, + c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), dependencies: [frontend_code, libpq, readline], kwargs: default_bin_args, diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 2c9edeaa088..72102521edc 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -49,6 +49,7 @@ libpq_st = static_library('libpq', pic: true, include_directories: [libpq_inc, postgres_inc], c_args: ['-DSO_MAJOR_VERSION=5'], + c_pch: pch_postgres_fe_h, dependencies: libpq_deps, kwargs: default_lib_args, ) diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build index 535660085dd..cd3894e6a73 100644 --- a/src/pl/plperl/meson.build +++ b/src/pl/plperl/meson.build @@ -45,6 +45,7 @@ endif plperl = shared_module('plperl', plperl_sources, + c_pch: pch_postgres_h, include_directories: [plperl_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [perl_dep, pg_mod_args['dependencies']], diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build index c46c0a1da2a..27b2f5ef529 100644 --- a/src/pl/plpgsql/src/meson.build +++ b/src/pl/plpgsql/src/meson.build @@ -48,6 +48,7 @@ endif plpgsql = shared_module('plpgsql', plpgsql_sources, + c_pch: pch_postgres_h, include_directories: include_directories('.'), kwargs: pg_mod_args, ) diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build index 40888386b5f..7bd683580e8 100644 --- a/src/pl/plpython/meson.build +++ b/src/pl/plpython/meson.build @@ -36,6 +36,7 @@ endif plpython = shared_module('plpython3', plpython_sources, + c_pch: pch_postgres_h, include_directories: [plpython_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [python3_dep, pg_mod_args['dependencies']], diff --git a/src/pl/tcl/meson.build b/src/pl/tcl/meson.build index f09bb14c950..7a708776c99 100644 --- a/src/pl/tcl/meson.build +++ b/src/pl/tcl/meson.build @@ -22,6 +22,7 @@ endif pltcl = shared_module('pltcl', pltcl_sources, + c_pch: pch_postgres_h, include_directories: [include_directories('.'), postgres_inc], kwargs: pg_mod_args + { 'dependencies': [tcl_dep, pg_mod_args['dependencies']], diff --git a/contrib/bloom/meson.build b/contrib/bloom/meson.build index 16f3b83e4d2..163a93c98fb 100644 --- a/contrib/bloom/meson.build +++ b/contrib/bloom/meson.build @@ -15,6 +15,7 @@ endif bloom = shared_module('bloom', bloom_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += bloom diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build index e98c91dacc8..bfb7865d213 100644 --- a/contrib/btree_gist/meson.build +++ b/contrib/btree_gist/meson.build @@ -33,6 +33,7 @@ endif btree_gist = shared_module('btree_gist', btree_gist_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += btree_gist diff --git a/contrib/hstore/meson.build b/contrib/hstore/meson.build index 2bb26bb772b..a2a4ec36cb0 100644 --- a/contrib/hstore/meson.build +++ b/contrib/hstore/meson.build @@ -18,6 +18,7 @@ endif hstore = shared_module('hstore', hstore_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += hstore diff --git a/contrib/pg_trgm/meson.build b/contrib/pg_trgm/meson.build index c8c7c07b308..839d6c4a7f6 100644 --- a/contrib/pg_trgm/meson.build +++ b/contrib/pg_trgm/meson.build @@ -13,6 +13,7 @@ endif pg_trgm = shared_module('pg_trgm', pg_trgm_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pg_trgm diff --git a/contrib/pgcrypto/meson.build b/contrib/pgcrypto/meson.build index 7fc7bbc7ca1..cc782578b49 100644 --- a/contrib/pgcrypto/meson.build +++ b/contrib/pgcrypto/meson.build @@ -78,6 +78,7 @@ endif pgcrypto = shared_module('pgcrypto', pgcrypto_sources, link_with: pgcrypto_link_with, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [pgcrypto_deps, contrib_mod_args['dependencies']] }, diff --git a/contrib/pgstattuple/meson.build b/contrib/pgstattuple/meson.build index 05e4cd46a5c..42d0b0e6ce9 100644 --- a/contrib/pgstattuple/meson.build +++ b/contrib/pgstattuple/meson.build @@ -12,6 +12,7 @@ endif pgstattuple = shared_module('pgstattuple', pgstattuple_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pgstattuple diff --git a/contrib/sepgsql/meson.build b/contrib/sepgsql/meson.build index 8bef239e3c2..1ac0fa388ab 100644 --- a/contrib/sepgsql/meson.build +++ b/contrib/sepgsql/meson.build @@ -22,6 +22,7 @@ endif sepgsql = shared_module('sepgsql', sepgsql_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [selinux, contrib_mod_args['dependencies']], } diff --git a/contrib/xml2/meson.build b/contrib/xml2/meson.build index 89b0d677516..92ab3368428 100644 --- a/contrib/xml2/meson.build +++ b/contrib/xml2/meson.build @@ -15,6 +15,7 @@ endif xml2 = shared_module('pgxml', xml2_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']], }, diff --git a/.cirrus.yml b/.cirrus.yml index efb2d2c4832..aea25fd7525 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -602,7 +602,7 @@ task: # Use /DEBUG:FASTLINK to avoid high memory usage during linking configure_script: | vcvarsall x64 - meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 @@ -630,7 +630,7 @@ task: configure_script: | vcvarsall x64 - meson setup --buildtype debug --backend vs -Dcassert=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --buildtype debug --backend vs -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 diff --git a/meson.build b/meson.build index 2b0cbb9a5a7..c50a414628d 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ project('postgresql', meson_version: '>=0.54', default_options: [ 'warning_level=1', #-Wall equivalent + 'b_pch=false', 'buildtype=release', ] ) -- 2.37.3.542.gdd3f6c4cae
--ngschxobz5ssor62 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v16-0013-meson-Add-xmllint-xsltproc-wrapper-script-to-han.patch" ^ permalink raw reply [nested|flat] 11+ messages in thread

* [PATCH v2 2/2] meson: Add support for building with precompiled headers
@ 2022-10-05 19:01 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-10-05 19:01 UTC (permalink / raw)

This substantially speeds up building for windows, due to the vast amount of
headers included via windows.h. A cross build from linux targetting mingw goes
from

994.11user 136.43system 0:31.58elapsed 3579%CPU
to
422.41user 89.05system 0:14.35elapsed 3562%CPU

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers). Targetting other operating systems the wins are far
smaller (tested linux, macOS, FreeBSD).

For now precompiled headers are disabled by default, it's not clear how well
they work on all platforms. E.g. on FreeBSD gcc doesn't seem to have working
support, but clang does.

When doing a full build precompiled headers are only beneficial for targets
with multiple .c files, as meson builds a separate precompiled header for each
target (so that different compilation options take effect). This commit
therefore only changes target with at least two .c files to use precompiled
headers.

Because this commit adds b_pch=false to the default_options new build
directories will have precompiled headers disabled by default, however
existing build directories will continue use the default value of b_pch, which
is true.

Note that using precompiled headers with ccache requires setting
CCACHE_SLOPPINESS=pch_defines,time_macros to get hits.

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com
Discussion: https://postgr.es/m/c5736f70-bb6d-8d25-e35c-e3d886e4e905@enterprisedb.com
Discussion: https://postgr.es/m/20190826054000.GE7005%40paquier.xyz
---
 src/include/meson.build                    | 1 +
 src/include/pch/c_pch.h                    | 1 +
 src/include/pch/meson.build                | 4 ++++
 src/include/pch/postgres_fe_pch.h          | 1 +
 src/include/pch/postgres_pch.h             | 1 +
 src/common/meson.build                     | 2 ++
 src/port/meson.build                       | 2 ++
 src/backend/meson.build                    | 5 +++++
 src/backend/snowball/meson.build           | 1 +
 src/fe_utils/meson.build                   | 1 +
 src/bin/pg_dump/meson.build                | 1 +
 src/bin/pg_upgrade/meson.build             | 1 +
 src/bin/pgbench/meson.build                | 1 +
 src/bin/psql/meson.build                   | 1 +
 src/interfaces/libpq/meson.build           | 2 ++
 src/pl/plperl/meson.build                  | 1 +
 src/pl/plpgsql/src/meson.build             | 1 +
 src/pl/plpython/meson.build                | 1 +
 src/pl/tcl/meson.build                     | 1 +
 contrib/bloom/meson.build                  | 1 +
 contrib/btree_gist/meson.build             | 1 +
 contrib/hstore/meson.build                 | 1 +
 contrib/pg_trgm/meson.build                | 1 +
 contrib/pgcrypto/meson.build               | 1 +
 contrib/pgstattuple/meson.build            | 1 +
 contrib/sepgsql/meson.build                | 1 +
 contrib/xml2/meson.build                   | 1 +
 src/interfaces/ecpg/ecpglib/meson.build    | 2 ++
 src/interfaces/ecpg/pgtypeslib/meson.build | 2 ++
 src/interfaces/ecpg/preproc/meson.build    | 1 +
 .cirrus.yml                                | 2 +-
 meson.build                                | 1 +
 32 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 src/include/pch/c_pch.h
 create mode 100644 src/include/pch/meson.build
 create mode 100644 src/include/pch/postgres_fe_pch.h
 create mode 100644 src/include/pch/postgres_pch.h

inline patch 1: src/include/meson.build, src/include/pch/c_pch.h, src/include/pch/meson.build and 29 more (+44/-1 lines) download inline-1.patchdiff --git a/src/include/meson.build b/src/include/meson.build index f2f7d03ff27..35c06c4856a 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -114,6 +114,7 @@ install_headers( subdir('catalog') subdir('nodes') +subdir('pch') subdir('storage') subdir('utils') diff --git a/src/include/pch/c_pch.h b/src/include/pch/c_pch.h new file mode 100644 index 00000000000..f40c757ca62 --- /dev/null +++ b/src/include/pch/c_pch.h @@ -0,0 +1 @@ +#include "c.h" diff --git a/src/include/pch/meson.build b/src/include/pch/meson.build new file mode 100644 index 00000000000..2bcec49c3a2 --- /dev/null +++ b/src/include/pch/meson.build @@ -0,0 +1,4 @@ +# See https://github.com/mesonbuild/meson/issues/10338 +pch_c_h = meson.source_root() / meson.current_source_dir() / 'c_pch.h' +pch_postgres_h = meson.source_root() / meson.current_source_dir() / 'postgres_pch.h' +pch_postgres_fe_h = meson.source_root() / meson.current_source_dir() / 'postgres_fe_pch.h' diff --git a/src/include/pch/postgres_fe_pch.h b/src/include/pch/postgres_fe_pch.h new file mode 100644 index 00000000000..f3ea20912d3 --- /dev/null +++ b/src/include/pch/postgres_fe_pch.h @@ -0,0 +1 @@ +#include "postgres_fe.h" diff --git a/src/include/pch/postgres_pch.h b/src/include/pch/postgres_pch.h new file mode 100644 index 00000000000..71b2f35f76b --- /dev/null +++ b/src/include/pch/postgres_pch.h @@ -0,0 +1 @@ +#include "postgres.h" diff --git a/src/common/meson.build b/src/common/meson.build index 23842e1ffef..1c9b8a3a018 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -147,6 +147,7 @@ foreach name, opts : pgcommon_variants endif c_args = opts.get('c_args', []) + common_cflags[cflagname] cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname), + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'sources': sources, @@ -159,6 +160,7 @@ foreach name, opts : pgcommon_variants lib = static_library('libpgcommon@0@'.format(name), link_with: cflag_libs, + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], diff --git a/src/port/meson.build b/src/port/meson.build index ced2e014db8..c2222696f1b 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -161,6 +161,7 @@ foreach name, opts : pgport_variants c_args = opts.get('c_args', []) + pgport_cflags[cflagname] cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname), sources, + c_pch: pch_c_h, kwargs: opts + { 'c_args': c_args, 'build_by_default': false, @@ -172,6 +173,7 @@ foreach name, opts : pgport_variants lib = static_library('libpgport@0@'.format(name), pgport_sources, link_with: cflag_libs, + c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], } diff --git a/src/backend/meson.build b/src/backend/meson.build index fefa40ddb64..676cb714d79 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -62,6 +62,7 @@ postgres_lib = static_library('postgres_lib', backend_sources + timezone_sources + generated_backend_sources, link_whole: backend_link_with, dependencies: backend_build_deps, + c_pch: pch_postgres_h, kwargs: internal_lib_args, ) @@ -81,6 +82,10 @@ if cc.get_id() == 'msvc' backend_link_args += '/DEF:@0@'.format(postgres_def.full_path()) backend_link_depends += postgres_def + # Due to the way msvc and meson's precompiled headers implementation + # interact, we need to have symbols from the full library available. Could + # be restricted to b_pch=true. + backend_link_with += postgres_lib elif host_system == 'aix' # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build index 974401d187e..72959fa29d6 100644 --- a/src/backend/snowball/meson.build +++ b/src/backend/snowball/meson.build @@ -66,6 +66,7 @@ endif dict_snowball = shared_module('dict_snowball', dict_snowball_sources, + c_pch: pch_postgres_h, kwargs: pg_mod_args + { 'include_directories': [stemmer_inc], } diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index 3e226c260ac..fe0b801387c 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,6 +23,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, + c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], dependencies: frontend_common_code, diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index 3527a25c288..e66f632b54e 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -13,6 +13,7 @@ pg_dump_common_sources = files( pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq, zlib], kwargs: internal_lib_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index a7b927a45c7..212bc9ce6ef 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -24,6 +24,7 @@ endif pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq], kwargs: default_bin_args, ) diff --git a/src/bin/pgbench/meson.build b/src/bin/pgbench/meson.build index 3cc393d17ea..1a3ec5d1295 100644 --- a/src/bin/pgbench/meson.build +++ b/src/bin/pgbench/meson.build @@ -27,6 +27,7 @@ pgbench = executable('pgbench', pgbench_sources, dependencies: [frontend_code, libpq, thread_dep], include_directories: include_directories('.'), + c_pch: pch_postgres_fe_h, c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], kwargs: default_bin_args, ) diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index 1264fc19fbd..a4c46bf5385 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -44,6 +44,7 @@ endif psql = executable('psql', psql_sources, + c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), dependencies: [frontend_code, libpq, readline], kwargs: default_bin_args, diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 533b2e6f773..8e696f1183c 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -58,6 +58,7 @@ libpq_st = static_library('libpq', libpq_sources, include_directories: [libpq_inc], c_args: libpq_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_stlib_code, libpq_deps], kwargs: default_lib_args, ) @@ -66,6 +67,7 @@ libpq_so = shared_library('libpq', libpq_sources + libpq_so_sources, include_directories: [libpq_inc, postgres_inc], c_args: libpq_c_args, + c_pch: pch_postgres_fe_h, version: '5.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '5' : '', darwin_versions: ['5', '5.' + pg_version_major.to_string()], diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build index 535660085dd..cd3894e6a73 100644 --- a/src/pl/plperl/meson.build +++ b/src/pl/plperl/meson.build @@ -45,6 +45,7 @@ endif plperl = shared_module('plperl', plperl_sources, + c_pch: pch_postgres_h, include_directories: [plperl_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [perl_dep, pg_mod_args['dependencies']], diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build index c46c0a1da2a..27b2f5ef529 100644 --- a/src/pl/plpgsql/src/meson.build +++ b/src/pl/plpgsql/src/meson.build @@ -48,6 +48,7 @@ endif plpgsql = shared_module('plpgsql', plpgsql_sources, + c_pch: pch_postgres_h, include_directories: include_directories('.'), kwargs: pg_mod_args, ) diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build index 40888386b5f..7bd683580e8 100644 --- a/src/pl/plpython/meson.build +++ b/src/pl/plpython/meson.build @@ -36,6 +36,7 @@ endif plpython = shared_module('plpython3', plpython_sources, + c_pch: pch_postgres_h, include_directories: [plpython_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [python3_dep, pg_mod_args['dependencies']], diff --git a/src/pl/tcl/meson.build b/src/pl/tcl/meson.build index f09bb14c950..7a708776c99 100644 --- a/src/pl/tcl/meson.build +++ b/src/pl/tcl/meson.build @@ -22,6 +22,7 @@ endif pltcl = shared_module('pltcl', pltcl_sources, + c_pch: pch_postgres_h, include_directories: [include_directories('.'), postgres_inc], kwargs: pg_mod_args + { 'dependencies': [tcl_dep, pg_mod_args['dependencies']], diff --git a/contrib/bloom/meson.build b/contrib/bloom/meson.build index 16f3b83e4d2..163a93c98fb 100644 --- a/contrib/bloom/meson.build +++ b/contrib/bloom/meson.build @@ -15,6 +15,7 @@ endif bloom = shared_module('bloom', bloom_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += bloom diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build index e98c91dacc8..bfb7865d213 100644 --- a/contrib/btree_gist/meson.build +++ b/contrib/btree_gist/meson.build @@ -33,6 +33,7 @@ endif btree_gist = shared_module('btree_gist', btree_gist_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += btree_gist diff --git a/contrib/hstore/meson.build b/contrib/hstore/meson.build index 2bb26bb772b..a2a4ec36cb0 100644 --- a/contrib/hstore/meson.build +++ b/contrib/hstore/meson.build @@ -18,6 +18,7 @@ endif hstore = shared_module('hstore', hstore_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += hstore diff --git a/contrib/pg_trgm/meson.build b/contrib/pg_trgm/meson.build index c8c7c07b308..839d6c4a7f6 100644 --- a/contrib/pg_trgm/meson.build +++ b/contrib/pg_trgm/meson.build @@ -13,6 +13,7 @@ endif pg_trgm = shared_module('pg_trgm', pg_trgm_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pg_trgm diff --git a/contrib/pgcrypto/meson.build b/contrib/pgcrypto/meson.build index 7fc7bbc7ca1..cc782578b49 100644 --- a/contrib/pgcrypto/meson.build +++ b/contrib/pgcrypto/meson.build @@ -78,6 +78,7 @@ endif pgcrypto = shared_module('pgcrypto', pgcrypto_sources, link_with: pgcrypto_link_with, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [pgcrypto_deps, contrib_mod_args['dependencies']] }, diff --git a/contrib/pgstattuple/meson.build b/contrib/pgstattuple/meson.build index 05e4cd46a5c..42d0b0e6ce9 100644 --- a/contrib/pgstattuple/meson.build +++ b/contrib/pgstattuple/meson.build @@ -12,6 +12,7 @@ endif pgstattuple = shared_module('pgstattuple', pgstattuple_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pgstattuple diff --git a/contrib/sepgsql/meson.build b/contrib/sepgsql/meson.build index 8bef239e3c2..1ac0fa388ab 100644 --- a/contrib/sepgsql/meson.build +++ b/contrib/sepgsql/meson.build @@ -22,6 +22,7 @@ endif sepgsql = shared_module('sepgsql', sepgsql_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [selinux, contrib_mod_args['dependencies']], } diff --git a/contrib/xml2/meson.build b/contrib/xml2/meson.build index 89b0d677516..92ab3368428 100644 --- a/contrib/xml2/meson.build +++ b/contrib/xml2/meson.build @@ -15,6 +15,7 @@ endif xml2 = shared_module('pgxml', xml2_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']], }, diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build index 7e6e6fbf5c0..2d07da1ff4c 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -27,6 +27,7 @@ ecpglib_st = static_library('libecpg', ecpglib_sources, include_directories: ecpglib_inc, c_args: ecpglib_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_stlib_code, thread_dep, libpq], link_with: [ecpg_pgtypes_st], kwargs: default_lib_args, @@ -37,6 +38,7 @@ ecpglib_so = shared_library('libecpg', ecpglib_sources + ecpglib_so_sources, include_directories: ecpglib_inc, c_args: ecpglib_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_shlib_code, libpq, thread_dep], link_with: ecpg_pgtypes_so, soversion: host_system != 'windows' ? '6' : '', diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build index 530dd2c602d..d7e1a94d24d 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -23,6 +23,7 @@ ecpg_pgtypes_st = static_library('libpgtypes', ecpg_pgtypes_sources, include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, + c_pch: pch_postgres_fe_h, dependencies: frontend_stlib_code, kwargs: default_lib_args, ) @@ -32,6 +33,7 @@ ecpg_pgtypes_so = shared_library('libpgtypes', ecpg_pgtypes_sources + ecpg_pgtypes_so_sources, include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, + c_pch: pch_postgres_fe_h, dependencies: frontend_shlib_code, version: '3.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '3' : '', diff --git a/src/interfaces/ecpg/preproc/meson.build b/src/interfaces/ecpg/preproc/meson.build index 74876f039c9..3d42ee439ff 100644 --- a/src/interfaces/ecpg/preproc/meson.build +++ b/src/interfaces/ecpg/preproc/meson.build @@ -102,6 +102,7 @@ endif ecpg_exe = executable('ecpg', ecpg_sources, include_directories: ['.', ecpg_inc, postgres_inc, libpq_inc], + c_pch: pch_postgres_fe_h, dependencies: [frontend_code], kwargs: default_bin_args, ) diff --git a/.cirrus.yml b/.cirrus.yml index 531cfe96f65..9f2282471a9 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -447,7 +447,7 @@ task: # Use /DEBUG:FASTLINK to avoid high memory usage during linking configure_script: | vcvarsall x64 - meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 diff --git a/meson.build b/meson.build index 25a6fa941cc..f0cb01c0015 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ project('postgresql', meson_version: '>=0.54', default_options: [ 'warning_level=1', #-Wall equivalent + 'b_pch=false', 'buildtype=release', # For compatibility with the autoconf build, set a default prefix. This # works even on windows, where it's a drive-relative path (i.e. when on -- 2.37.3.542.gdd3f6c4cae
--ius2gpssq5qejbb6-- ^ permalink raw reply [nested|flat] 11+ messages in thread

* meson: Add support for building with precompiled headers
@ 2022-10-05 19:08 Andres Freund <andres@anarazel.de>
  2022-10-05 20:09 ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-06 07:06 ` Re: meson: Add support for building with precompiled headers Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 2 replies; 11+ messages in thread

From: Andres Freund @ 2022-10-05 19:08 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@enterprisedb.com>

Hi,

This is a patch split off from the initial meson thread [1] as it's
functionally largely independent (as suggested in [2]).

Using precompiled headers substantially speeds up building for windows, due to
the vast amount of headers included via windows.h. A cross build from
linux targetting mingw goes from

994.11user 136.43system 0:31.58elapsed 3579%CPU
to
422.41user 89.05system 0:14.35elapsed 3562%CPU

The wins on windows are similar-ish (but I don't have a system at hand just
now for actual numbers). Targetting other operating systems the wins are far
smaller (tested linux, macOS, FreeBSD).

This is particularly interesting for cfbot, which spends a lot of time
building on windows.  It also makes developing on windows less painful as the
gains are bigger when compiling incrementally, because the precompiled headers
don't typically have to be rebuilt.


As a prerequisite this requires changing the way FD_SETSIZE is defined when
targetting windows.

When using precompiled headers we cannot override macros in system headers
from within .c files, as headers are already processed before the #define in
the C file is reached.

A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I
am hesitant to change FD_SETSIZE globally on windows, due to
src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add
-DFD_SETSIZE=1024 when building the specific targets needing it.

We likely should move away from using select() in those places, but that's a
larger change.


Michael, CCing you wrt the second patch, as Thomas noticed [3] that you were
looking at where to define FD_SETSIZE.

Greetings,

Andres Freund

[1] https://www.postgresql.org/message-id/20211012083721.hvixq4pnh2pixr3j%40alap3.anarazel.de
[2] https://www.postgresql.org/message-id/e0c44fb2-8b66-a4b9-b274-7ed3a1a0ab74%40enterprisedb.com
[3] https://www.postgresql.org/message-id/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail...
[4] https://www.postgresql.org/message-id/20190826054000.GE7005%40paquier.xyz

Attachments: download all (2 files, .tar.gz)

v2-0001-windows-adjust-FD_SETSIZE-via-commandline-define.patch (text/x-diff, 6.4K) download From 7c0a0cff9b366367b8cfd51302f944de83579dca Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@anarazel.de> Date: Sun, 25 Sep 2022 12:07:29 -0700 Subject: [PATCH v2 1/2] windows: adjust FD_SETSIZE via commandline define When using precompiled headers we cannot override macros in system headers from within .c files, as headers are already processed before the #define in the C file is reached. A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I am hesitant to change FD_SETSIZE globally on windows, due to src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add -DFD_SETSIZE=1024 when building the specific targets needing it. We likely should move away from using select() in those places, but that's a larger change. Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com Discussion: https://postgr.es/m/20190826054000.GE7005%40paquier.xyz --- src/fe_utils/Makefile | 4 ++++ src/fe_utils/meson.build | 1 + src/fe_utils/parallel_slot.c | 4 ++-- src/bin/pgbench/Makefile | 2 ++ src/bin/pgbench/meson.build | 1 + src/bin/pgbench/pgbench.c | 4 ++-- src/tools/msvc/Mkvcbuild.pm | 27 +++++++++++++++++++-------- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/fe_utils/Makefile b/src/fe_utils/Makefile index 44bc7a1215d..40d4b1d8698 100644 --- a/src/fe_utils/Makefile +++ b/src/fe_utils/Makefile @@ -34,6 +34,10 @@ OBJS = \ simple_list.o \ string_utils.o +ifeq ($(PORTNAME), win32) +override CFLAGS += -DFD_SETSIZE=1024 +endif + all: libpgfeutils.a libpgfeutils.a: $(OBJS) diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index b6bf8e1ca21..3e226c260ac 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -24,6 +24,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, include_directories: [postgres_inc, libpq_inc], + c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], dependencies: frontend_common_code, kwargs: default_lib_args, ) diff --git a/src/fe_utils/parallel_slot.c b/src/fe_utils/parallel_slot.c index 2be2903c9c6..767256757f2 100644 --- a/src/fe_utils/parallel_slot.c +++ b/src/fe_utils/parallel_slot.c @@ -12,8 +12,8 @@ *------------------------------------------------------------------------- */ -#ifdef WIN32 -#define FD_SETSIZE 1024 /* must set before winsock2.h is included */ +#if defined(WIN32) && FD_SETSIZE < 1024 +#error FD_SETSIZE needs to have been increased #endif #include "postgres_fe.h" diff --git a/src/bin/pgbench/Makefile b/src/bin/pgbench/Makefile index 6647c9fe97d..68e9f03e79f 100644 --- a/src/bin/pgbench/Makefile +++ b/src/bin/pgbench/Makefile @@ -18,6 +18,8 @@ LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) ifneq ($(PORTNAME), win32) override CFLAGS += $(PTHREAD_CFLAGS) +else +override CFLAGS += -DFD_SETSIZE=1024 endif LIBS += $(PTHREAD_LIBS) diff --git a/src/bin/pgbench/meson.build b/src/bin/pgbench/meson.build index a32eb51fe07..3cc393d17ea 100644 --- a/src/bin/pgbench/meson.build +++ b/src/bin/pgbench/meson.build @@ -27,6 +27,7 @@ pgbench = executable('pgbench', pgbench_sources, dependencies: [frontend_code, libpq, thread_dep], include_directories: include_directories('.'), + c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], kwargs: default_bin_args, ) bin_targets += pgbench diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index aa1a3541fe6..7da7c36fbe6 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -27,8 +27,8 @@ * */ -#ifdef WIN32 -#define FD_SETSIZE 1024 /* must set before winsock2.h is included */ +#if defined(WIN32) && FD_SETSIZE < 1024 +#error FD_SETSIZE needs to have been increased #endif #include "postgres_fe.h" diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index ddb4f25eb12..83a3e404254 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -35,6 +35,7 @@ my $libpq; my @unlink_on_exit; # Set of variables for modules in contrib/ and src/test/modules/ +my $contrib_defines = {}; my @contrib_uselibpq = (); my @contrib_uselibpgport = (); my @contrib_uselibpgcommon = (); @@ -52,6 +53,7 @@ my @contrib_excludes = ( 'unsafe_tests'); # Set of variables for frontend modules +my $frontend_defines = { 'pgbench' => 'FD_SETSIZE=1024' }; my @frontend_uselibpq = ('pg_amcheck', 'pg_ctl', 'pg_upgrade', 'pgbench', 'psql', 'initdb'); my @frontend_uselibpgport = ( @@ -175,6 +177,7 @@ sub mkvcbuild $libpgfeutils = $solution->AddProject('libpgfeutils', 'lib', 'misc'); $libpgfeutils->AddDefine('FRONTEND'); + $libpgfeutils->AddDefine('FD_SETSIZE=1024'); $libpgfeutils->AddIncludeDir('src/interfaces/libpq'); $libpgfeutils->AddFiles('src/fe_utils', @pgfeutilsfiles); @@ -1120,10 +1123,10 @@ sub AdjustContribProj { my $proj = shift; AdjustModule( - $proj, \@contrib_uselibpq, - \@contrib_uselibpgport, \@contrib_uselibpgcommon, - $contrib_extralibs, $contrib_extrasource, - $contrib_extraincludes); + $proj, $contrib_defines, + \@contrib_uselibpq, \@contrib_uselibpgport, + \@contrib_uselibpgcommon, $contrib_extralibs, + $contrib_extrasource, $contrib_extraincludes); return; } @@ -1131,16 +1134,17 @@ sub AdjustFrontendProj { my $proj = shift; AdjustModule( - $proj, \@frontend_uselibpq, - \@frontend_uselibpgport, \@frontend_uselibpgcommon, - $frontend_extralibs, $frontend_extrasource, - $frontend_extraincludes); + $proj, $frontend_defines, + \@frontend_uselibpq, \@frontend_uselibpgport, + \@frontend_uselibpgcommon, $frontend_extralibs, + $frontend_extrasource, $frontend_extraincludes); return; } sub AdjustModule { my $proj = shift; + my $module_defines = shift; my $module_uselibpq = shift; my $module_uselibpgport = shift; my $module_uselibpgcommon = shift; @@ -1149,6 +1153,13 @@ sub AdjustModule my $module_extraincludes = shift; my $n = $proj->{name}; + if ($module_defines->{$n}) + { + foreach my $d ($module_defines->{$n}) + { + $proj->AddDefine($d); + } + } if (grep { /^$n$/ } @{$module_uselibpq}) { $proj->AddIncludeDir('src\interfaces\libpq'); -- 2.37.3.542.gdd3f6c4cae
v2-0002-meson-Add-support-for-building-with-precompiled-h.patch (text/x-diff, 18.6K) download From f051aa26e1611aa2cb80aa727e0972f27086a680 Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@anarazel.de> Date: Wed, 5 Oct 2022 12:01:19 -0700 Subject: [PATCH v2 2/2] meson: Add support for building with precompiled headers This substantially speeds up building for windows, due to the vast amount of headers included via windows.h. A cross build from linux targetting mingw goes from 994.11user 136.43system 0:31.58elapsed 3579%CPU to 422.41user 89.05system 0:14.35elapsed 3562%CPU The wins on windows are similar-ish (but I don't have a system at hand just now for actual numbers). Targetting other operating systems the wins are far smaller (tested linux, macOS, FreeBSD). For now precompiled headers are disabled by default, it's not clear how well they work on all platforms. E.g. on FreeBSD gcc doesn't seem to have working support, but clang does. When doing a full build precompiled headers are only beneficial for targets with multiple .c files, as meson builds a separate precompiled header for each target (so that different compilation options take effect). This commit therefore only changes target with at least two .c files to use precompiled headers. Because this commit adds b_pch=false to the default_options new build directories will have precompiled headers disabled by default, however existing build directories will continue use the default value of b_pch, which is true. Note that using precompiled headers with ccache requires setting CCACHE_SLOPPINESS=pch_defines,time_macros to get hits. Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com Discussion: https://postgr.es/m/c5736f70-bb6d-8d25-e35c-e3d886e4e905@enterprisedb.com Discussion: https://postgr.es/m/20190826054000.GE7005%40paquier.xyz --- src/include/meson.build | 1 + src/include/pch/c_pch.h | 1 + src/include/pch/meson.build | 4 ++++ src/include/pch/postgres_fe_pch.h | 1 + src/include/pch/postgres_pch.h | 1 + src/common/meson.build | 2 ++ src/port/meson.build | 2 ++ src/backend/meson.build | 5 +++++ src/backend/snowball/meson.build | 1 + src/fe_utils/meson.build | 1 + src/bin/pg_dump/meson.build | 1 + src/bin/pg_upgrade/meson.build | 1 + src/bin/pgbench/meson.build | 1 + src/bin/psql/meson.build | 1 + src/interfaces/libpq/meson.build | 2 ++ src/pl/plperl/meson.build | 1 + src/pl/plpgsql/src/meson.build | 1 + src/pl/plpython/meson.build | 1 + src/pl/tcl/meson.build | 1 + contrib/bloom/meson.build | 1 + contrib/btree_gist/meson.build | 1 + contrib/hstore/meson.build | 1 + contrib/pg_trgm/meson.build | 1 + contrib/pgcrypto/meson.build | 1 + contrib/pgstattuple/meson.build | 1 + contrib/sepgsql/meson.build | 1 + contrib/xml2/meson.build | 1 + src/interfaces/ecpg/ecpglib/meson.build | 2 ++ src/interfaces/ecpg/pgtypeslib/meson.build | 2 ++ src/interfaces/ecpg/preproc/meson.build | 1 + .cirrus.yml | 2 +- meson.build | 1 + 32 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/include/pch/c_pch.h create mode 100644 src/include/pch/meson.build create mode 100644 src/include/pch/postgres_fe_pch.h create mode 100644 src/include/pch/postgres_pch.h diff --git a/src/include/meson.build b/src/include/meson.build index f2f7d03ff27..35c06c4856a 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -114,6 +114,7 @@ install_headers( subdir('catalog') subdir('nodes') +subdir('pch') subdir('storage') subdir('utils') diff --git a/src/include/pch/c_pch.h b/src/include/pch/c_pch.h new file mode 100644 index 00000000000..f40c757ca62 --- /dev/null +++ b/src/include/pch/c_pch.h @@ -0,0 +1 @@ +#include "c.h" diff --git a/src/include/pch/meson.build b/src/include/pch/meson.build new file mode 100644 index 00000000000..2bcec49c3a2 --- /dev/null +++ b/src/include/pch/meson.build @@ -0,0 +1,4 @@ +# See https://github.com/mesonbuild/meson/issues/10338 +pch_c_h = meson.source_root() / meson.current_source_dir() / 'c_pch.h' +pch_postgres_h = meson.source_root() / meson.current_source_dir() / 'postgres_pch.h' +pch_postgres_fe_h = meson.source_root() / meson.current_source_dir() / 'postgres_fe_pch.h' diff --git a/src/include/pch/postgres_fe_pch.h b/src/include/pch/postgres_fe_pch.h new file mode 100644 index 00000000000..f3ea20912d3 --- /dev/null +++ b/src/include/pch/postgres_fe_pch.h @@ -0,0 +1 @@ +#include "postgres_fe.h" diff --git a/src/include/pch/postgres_pch.h b/src/include/pch/postgres_pch.h new file mode 100644 index 00000000000..71b2f35f76b --- /dev/null +++ b/src/include/pch/postgres_pch.h @@ -0,0 +1 @@ +#include "postgres.h" diff --git a/src/common/meson.build b/src/common/meson.build index 23842e1ffef..1c9b8a3a018 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -147,6 +147,7 @@ foreach name, opts : pgcommon_variants endif c_args = opts.get('c_args', []) + common_cflags[cflagname] cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname), + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'sources': sources, @@ -159,6 +160,7 @@ foreach name, opts : pgcommon_variants lib = static_library('libpgcommon@0@'.format(name), link_with: cflag_libs, + c_pch: pch_c_h, include_directories: include_directories('.'), kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], diff --git a/src/port/meson.build b/src/port/meson.build index ced2e014db8..c2222696f1b 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -161,6 +161,7 @@ foreach name, opts : pgport_variants c_args = opts.get('c_args', []) + pgport_cflags[cflagname] cflag_libs += static_library('libpgport@0@_@1@'.format(name, cflagname), sources, + c_pch: pch_c_h, kwargs: opts + { 'c_args': c_args, 'build_by_default': false, @@ -172,6 +173,7 @@ foreach name, opts : pgport_variants lib = static_library('libpgport@0@'.format(name), pgport_sources, link_with: cflag_libs, + c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], } diff --git a/src/backend/meson.build b/src/backend/meson.build index fefa40ddb64..676cb714d79 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -62,6 +62,7 @@ postgres_lib = static_library('postgres_lib', backend_sources + timezone_sources + generated_backend_sources, link_whole: backend_link_with, dependencies: backend_build_deps, + c_pch: pch_postgres_h, kwargs: internal_lib_args, ) @@ -81,6 +82,10 @@ if cc.get_id() == 'msvc' backend_link_args += '/DEF:@0@'.format(postgres_def.full_path()) backend_link_depends += postgres_def + # Due to the way msvc and meson's precompiled headers implementation + # interact, we need to have symbols from the full library available. Could + # be restricted to b_pch=true. + backend_link_with += postgres_lib elif host_system == 'aix' # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build index 974401d187e..72959fa29d6 100644 --- a/src/backend/snowball/meson.build +++ b/src/backend/snowball/meson.build @@ -66,6 +66,7 @@ endif dict_snowball = shared_module('dict_snowball', dict_snowball_sources, + c_pch: pch_postgres_h, kwargs: pg_mod_args + { 'include_directories': [stemmer_inc], } diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index 3e226c260ac..fe0b801387c 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -23,6 +23,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, + c_pch: pch_postgres_fe_h, include_directories: [postgres_inc, libpq_inc], c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], dependencies: frontend_common_code, diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index 3527a25c288..e66f632b54e 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -13,6 +13,7 @@ pg_dump_common_sources = files( pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq, zlib], kwargs: internal_lib_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index a7b927a45c7..212bc9ce6ef 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -24,6 +24,7 @@ endif pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, + c_pch: pch_postgres_fe_h, dependencies: [frontend_code, libpq], kwargs: default_bin_args, ) diff --git a/src/bin/pgbench/meson.build b/src/bin/pgbench/meson.build index 3cc393d17ea..1a3ec5d1295 100644 --- a/src/bin/pgbench/meson.build +++ b/src/bin/pgbench/meson.build @@ -27,6 +27,7 @@ pgbench = executable('pgbench', pgbench_sources, dependencies: [frontend_code, libpq, thread_dep], include_directories: include_directories('.'), + c_pch: pch_postgres_fe_h, c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], kwargs: default_bin_args, ) diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index 1264fc19fbd..a4c46bf5385 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -44,6 +44,7 @@ endif psql = executable('psql', psql_sources, + c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), dependencies: [frontend_code, libpq, readline], kwargs: default_bin_args, diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 533b2e6f773..8e696f1183c 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -58,6 +58,7 @@ libpq_st = static_library('libpq', libpq_sources, include_directories: [libpq_inc], c_args: libpq_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_stlib_code, libpq_deps], kwargs: default_lib_args, ) @@ -66,6 +67,7 @@ libpq_so = shared_library('libpq', libpq_sources + libpq_so_sources, include_directories: [libpq_inc, postgres_inc], c_args: libpq_c_args, + c_pch: pch_postgres_fe_h, version: '5.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '5' : '', darwin_versions: ['5', '5.' + pg_version_major.to_string()], diff --git a/src/pl/plperl/meson.build b/src/pl/plperl/meson.build index 535660085dd..cd3894e6a73 100644 --- a/src/pl/plperl/meson.build +++ b/src/pl/plperl/meson.build @@ -45,6 +45,7 @@ endif plperl = shared_module('plperl', plperl_sources, + c_pch: pch_postgres_h, include_directories: [plperl_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [perl_dep, pg_mod_args['dependencies']], diff --git a/src/pl/plpgsql/src/meson.build b/src/pl/plpgsql/src/meson.build index c46c0a1da2a..27b2f5ef529 100644 --- a/src/pl/plpgsql/src/meson.build +++ b/src/pl/plpgsql/src/meson.build @@ -48,6 +48,7 @@ endif plpgsql = shared_module('plpgsql', plpgsql_sources, + c_pch: pch_postgres_h, include_directories: include_directories('.'), kwargs: pg_mod_args, ) diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build index 40888386b5f..7bd683580e8 100644 --- a/src/pl/plpython/meson.build +++ b/src/pl/plpython/meson.build @@ -36,6 +36,7 @@ endif plpython = shared_module('plpython3', plpython_sources, + c_pch: pch_postgres_h, include_directories: [plpython_inc, postgres_inc], kwargs: pg_mod_args + { 'dependencies': [python3_dep, pg_mod_args['dependencies']], diff --git a/src/pl/tcl/meson.build b/src/pl/tcl/meson.build index f09bb14c950..7a708776c99 100644 --- a/src/pl/tcl/meson.build +++ b/src/pl/tcl/meson.build @@ -22,6 +22,7 @@ endif pltcl = shared_module('pltcl', pltcl_sources, + c_pch: pch_postgres_h, include_directories: [include_directories('.'), postgres_inc], kwargs: pg_mod_args + { 'dependencies': [tcl_dep, pg_mod_args['dependencies']], diff --git a/contrib/bloom/meson.build b/contrib/bloom/meson.build index 16f3b83e4d2..163a93c98fb 100644 --- a/contrib/bloom/meson.build +++ b/contrib/bloom/meson.build @@ -15,6 +15,7 @@ endif bloom = shared_module('bloom', bloom_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += bloom diff --git a/contrib/btree_gist/meson.build b/contrib/btree_gist/meson.build index e98c91dacc8..bfb7865d213 100644 --- a/contrib/btree_gist/meson.build +++ b/contrib/btree_gist/meson.build @@ -33,6 +33,7 @@ endif btree_gist = shared_module('btree_gist', btree_gist_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += btree_gist diff --git a/contrib/hstore/meson.build b/contrib/hstore/meson.build index 2bb26bb772b..a2a4ec36cb0 100644 --- a/contrib/hstore/meson.build +++ b/contrib/hstore/meson.build @@ -18,6 +18,7 @@ endif hstore = shared_module('hstore', hstore_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += hstore diff --git a/contrib/pg_trgm/meson.build b/contrib/pg_trgm/meson.build index c8c7c07b308..839d6c4a7f6 100644 --- a/contrib/pg_trgm/meson.build +++ b/contrib/pg_trgm/meson.build @@ -13,6 +13,7 @@ endif pg_trgm = shared_module('pg_trgm', pg_trgm_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pg_trgm diff --git a/contrib/pgcrypto/meson.build b/contrib/pgcrypto/meson.build index 7fc7bbc7ca1..cc782578b49 100644 --- a/contrib/pgcrypto/meson.build +++ b/contrib/pgcrypto/meson.build @@ -78,6 +78,7 @@ endif pgcrypto = shared_module('pgcrypto', pgcrypto_sources, link_with: pgcrypto_link_with, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [pgcrypto_deps, contrib_mod_args['dependencies']] }, diff --git a/contrib/pgstattuple/meson.build b/contrib/pgstattuple/meson.build index 05e4cd46a5c..42d0b0e6ce9 100644 --- a/contrib/pgstattuple/meson.build +++ b/contrib/pgstattuple/meson.build @@ -12,6 +12,7 @@ endif pgstattuple = shared_module('pgstattuple', pgstattuple_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args, ) contrib_targets += pgstattuple diff --git a/contrib/sepgsql/meson.build b/contrib/sepgsql/meson.build index 8bef239e3c2..1ac0fa388ab 100644 --- a/contrib/sepgsql/meson.build +++ b/contrib/sepgsql/meson.build @@ -22,6 +22,7 @@ endif sepgsql = shared_module('sepgsql', sepgsql_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [selinux, contrib_mod_args['dependencies']], } diff --git a/contrib/xml2/meson.build b/contrib/xml2/meson.build index 89b0d677516..92ab3368428 100644 --- a/contrib/xml2/meson.build +++ b/contrib/xml2/meson.build @@ -15,6 +15,7 @@ endif xml2 = shared_module('pgxml', xml2_sources, + c_pch: pch_postgres_h, kwargs: contrib_mod_args + { 'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']], }, diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build index 7e6e6fbf5c0..2d07da1ff4c 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -27,6 +27,7 @@ ecpglib_st = static_library('libecpg', ecpglib_sources, include_directories: ecpglib_inc, c_args: ecpglib_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_stlib_code, thread_dep, libpq], link_with: [ecpg_pgtypes_st], kwargs: default_lib_args, @@ -37,6 +38,7 @@ ecpglib_so = shared_library('libecpg', ecpglib_sources + ecpglib_so_sources, include_directories: ecpglib_inc, c_args: ecpglib_c_args, + c_pch: pch_postgres_fe_h, dependencies: [frontend_shlib_code, libpq, thread_dep], link_with: ecpg_pgtypes_so, soversion: host_system != 'windows' ? '6' : '', diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build index 530dd2c602d..d7e1a94d24d 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -23,6 +23,7 @@ ecpg_pgtypes_st = static_library('libpgtypes', ecpg_pgtypes_sources, include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, + c_pch: pch_postgres_fe_h, dependencies: frontend_stlib_code, kwargs: default_lib_args, ) @@ -32,6 +33,7 @@ ecpg_pgtypes_so = shared_library('libpgtypes', ecpg_pgtypes_sources + ecpg_pgtypes_so_sources, include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, + c_pch: pch_postgres_fe_h, dependencies: frontend_shlib_code, version: '3.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '3' : '', diff --git a/src/interfaces/ecpg/preproc/meson.build b/src/interfaces/ecpg/preproc/meson.build index 74876f039c9..3d42ee439ff 100644 --- a/src/interfaces/ecpg/preproc/meson.build +++ b/src/interfaces/ecpg/preproc/meson.build @@ -102,6 +102,7 @@ endif ecpg_exe = executable('ecpg', ecpg_sources, include_directories: ['.', ecpg_inc, postgres_inc, libpq_inc], + c_pch: pch_postgres_fe_h, dependencies: [frontend_code], kwargs: default_bin_args, ) diff --git a/.cirrus.yml b/.cirrus.yml index 531cfe96f65..9f2282471a9 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -447,7 +447,7 @@ task: # Use /DEBUG:FASTLINK to avoid high memory usage during linking configure_script: | vcvarsall x64 - meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build + meson setup --backend ninja --buildtype debug -Dc_link_args=/DEBUG:FASTLINK -Dcassert=true -Db_pch=true -Dssl=openssl -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -DPG_TEST_EXTRA="%PG_TEST_EXTRA%" build build_script: | vcvarsall x64 diff --git a/meson.build b/meson.build index 25a6fa941cc..f0cb01c0015 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,7 @@ project('postgresql', meson_version: '>=0.54', default_options: [ 'warning_level=1', #-Wall equivalent + 'b_pch=false', 'buildtype=release', # For compatibility with the autoconf build, set a default prefix. This # works even on windows, where it's a drive-relative path (i.e. when on -- 2.37.3.542.gdd3f6c4cae
^ permalink raw reply [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
@ 2022-10-05 20:09 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-05 20:17   ` Re: meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  1 sibling, 1 reply; 11+ messages in thread

From: Tom Lane @ 2022-10-05 20:09 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@enterprisedb.com>

Andres Freund <andres@anarazel.de> writes:
> When using precompiled headers we cannot override macros in system headers
> from within .c files, as headers are already processed before the #define in
> the C file is reached.

> A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I
> am hesitant to change FD_SETSIZE globally on windows, due to
> src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add
> -DFD_SETSIZE=1024 when building the specific targets needing it.

Color me confused, but how does it work to #define that from the command
line if it can't be overridden from within the program?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  2022-10-05 20:09 ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-10-05 20:17   ` Andres Freund <andres@anarazel.de>
  2022-10-05 20:21     ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 11+ messages in thread

From: Andres Freund @ 2022-10-05 20:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@enterprisedb.com>

Hi,

On 2022-10-05 16:09:14 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > When using precompiled headers we cannot override macros in system headers
> > from within .c files, as headers are already processed before the #define in
> > the C file is reached.
> 
> > A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I
> > am hesitant to change FD_SETSIZE globally on windows, due to
> > src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add
> > -DFD_SETSIZE=1024 when building the specific targets needing it.
> 
> Color me confused, but how does it work to #define that from the command
> line if it can't be overridden from within the program?

If specified on the commandline it's also used when generating the precompiled
header - of course that's not possible when it's just #define'd in some .c
file.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  2022-10-05 20:09 ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-05 20:17   ` Re: meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
@ 2022-10-05 20:21     ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-05 20:27       ` Re: meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 11+ messages in thread

From: Tom Lane @ 2022-10-05 20:21 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@enterprisedb.com>

Andres Freund <andres@anarazel.de> writes:
> On 2022-10-05 16:09:14 -0400, Tom Lane wrote:
>> Color me confused, but how does it work to #define that from the command
>> line if it can't be overridden from within the program?

> If specified on the commandline it's also used when generating the precompiled
> header - of course that's not possible when it's just #define'd in some .c
> file.

Ah, so there's a separate cache of precompiled headers for each set of
compiler command-line arguments?  Got it.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  2022-10-05 20:09 ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-05 20:17   ` Re: meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  2022-10-05 20:21     ` Re: meson: Add support for building with precompiled headers Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-10-05 20:27       ` Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-10-05 20:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>; Peter Eisentraut <peter.eisentraut@enterprisedb.com>

Hi,

On 2022-10-05 16:21:55 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2022-10-05 16:09:14 -0400, Tom Lane wrote:
> >> Color me confused, but how does it work to #define that from the command
> >> line if it can't be overridden from within the program?
> 
> > If specified on the commandline it's also used when generating the precompiled
> > header - of course that's not possible when it's just #define'd in some .c
> > file.
> 
> Ah, so there's a separate cache of precompiled headers for each set of
> compiler command-line arguments?  Got it.

Worse, it builds the precompiled header for each "target" (static/shared lib,
executable), right now. Hence I've only added them for targets that have
multiple .c files. I've been planning to submit an improvement to meson that
does what you propose, it'd not be hard, but before it's actually usable, it
didn't seem worth investing time in that.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
@ 2022-10-06 07:06 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  2022-10-07 00:25   ` Re: meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  1 sibling, 1 reply; 11+ messages in thread

From: Peter Eisentraut @ 2022-10-06 07:06 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>

On 05.10.22 21:08, Andres Freund wrote:
> This is a patch split off from the initial meson thread [1] as it's
> functionally largely independent (as suggested in [2]).
> 
> Using precompiled headers substantially speeds up building for windows, due to
> the vast amount of headers included via windows.h. A cross build from
> linux targetting mingw goes from

These patches look ok to me.  I can't really comment on the Windows 
details, but it sounds all reasonable.

Small issue:

+override CFLAGS += -DFD_SETSIZE=1024

(and similar)

should be CPPFLAGS.






^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: meson: Add support for building with precompiled headers
  2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
  2022-10-06 07:06 ` Re: meson: Add support for building with precompiled headers Peter Eisentraut <peter.eisentraut@enterprisedb.com>
@ 2022-10-07 00:25   ` Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 11+ messages in thread

From: Andres Freund @ 2022-10-07 00:25 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; +Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>; Justin Pryzby <pryzby@telsasoft.com>; Michael Paquier <michael.paquier@gmail.com>

Hi,

On 2022-10-06 09:06:42 +0200, Peter Eisentraut wrote:
> On 05.10.22 21:08, Andres Freund wrote:
> > This is a patch split off from the initial meson thread [1] as it's
> > functionally largely independent (as suggested in [2]).
> > 
> > Using precompiled headers substantially speeds up building for windows, due to
> > the vast amount of headers included via windows.h. A cross build from
> > linux targetting mingw goes from
> 
> These patches look ok to me.  I can't really comment on the Windows details,
> but it sounds all reasonable.

Thanks for reviewing!


> Small issue:
> 
> +override CFLAGS += -DFD_SETSIZE=1024
> 
> (and similar)
> 
> should be CPPFLAGS.

Pushed with that adjusted.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2022-10-07 00:25 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 16:49 [PATCH v12 15/15] meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
2022-09-23 19:19 [PATCH v15 11/14] meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
2022-09-23 19:19 [PATCH v16 12/16] meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
2022-10-05 19:01 [PATCH v2 2/2] meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
2022-10-05 19:08 meson: Add support for building with precompiled headers Andres Freund <andres@anarazel.de>
2022-10-05 20:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-05 20:17   ` Andres Freund <andres@anarazel.de>
2022-10-05 20:21     ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-05 20:27       ` Andres Freund <andres@anarazel.de>
2022-10-06 07:06 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
2022-10-07 00:25   ` Andres Freund <andres@anarazel.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox