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
# 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
bloom = shared_module('bloom',
bloom_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args,
)
contrib_targets += bloom
btree_gist = shared_module('btree_gist',
btree_gist_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args,
)
contrib_targets += btree_gist
hstore = shared_module('hstore',
hstore_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args,
)
contrib_targets += hstore
pg_trgm = shared_module('pg_trgm',
pg_trgm_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args,
)
contrib_targets += pg_trgm
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']]
},
pgstattuple = shared_module('pgstattuple',
pgstattuple_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args,
)
contrib_targets += pgstattuple
sepgsql = shared_module('sepgsql',
sepgsql_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args + {
'dependencies': [selinux, contrib_mod_args['dependencies']],
}
xml2 = shared_module('pgxml',
xml2_sources,
+ c_pch: pch_postgres_h,
kwargs: contrib_mod_args + {
'dependencies': [libxml, libxslt, contrib_mod_args['dependencies']],
},
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
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,
)
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
dict_snowball = shared_module('dict_snowball',
dict_snowball_sources,
+ c_pch: pch_postgres_h,
kwargs: pg_mod_args + {
'include_directories': [stemmer_inc],
}
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,
)
pg_upgrade = executable('pg_upgrade',
pg_upgrade_sources,
+ c_pch: pch_postgres_fe_h,
dependencies: [frontend_code, libpq],
kwargs: default_bin_args,
)
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,
)
psql = executable('psql',
psql_sources,
+ c_pch: pch_postgres_fe_h,
include_directories: include_directories('.'),
dependencies: [frontend_code, libpq, readline],
kwargs: default_bin_args,
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,
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],
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,
subdir('catalog')
subdir('nodes')
+subdir('pch')
subdir('storage')
subdir('utils')
--- /dev/null
+#include "c.h"
--- /dev/null
+# 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'
--- /dev/null
+#include "postgres_fe.h"
--- /dev/null
+#include "postgres.h"
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,
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' : '',
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,
)
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' : '',
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,
)
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,
)
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()],
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']],
plpgsql = shared_module('plpgsql',
plpgsql_sources,
+ c_pch: pch_postgres_h,
include_directories: include_directories('.'),
kwargs: pg_mod_args,
)
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']],
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']],
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,
lib = static_library('libpgport@0@'.format(name),
pgport_sources,
link_with: cflag_libs,
+ c_pch: pch_c_h,
kwargs: opts + {
'dependencies': opts['dependencies'] + [ssl],
}