mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
meson: Add initial version of meson based build system
Autoconf is showing its age, fewer and fewer contributors know how to wrangle it. Recursive make has a lot of hard to resolve dependency issues and slow incremental rebuilds. Our home-grown MSVC build system is hard to maintain for developers not using Windows and runs tests serially. While these and other issues could individually be addressed with incremental improvements, together they seem best addressed by moving to a more modern build system. After evaluating different build system choices, we chose to use meson, to a good degree based on the adoption by other open source projects. We decided that it's more realistic to commit a relatively early version of the new build system and mature it in tree. This commit adds an initial version of a meson based build system. It supports building postgres on at least AIX, FreeBSD, Linux, macOS, NetBSD, OpenBSD, Solaris and Windows (however only gcc is supported on aix, solaris). For Windows/MSVC postgres can now be built with ninja (faster, particularly for incremental builds) and msbuild (supporting the visual studio GUI, but building slower). Several aspects (e.g. Windows rc file generation, PGXS compatibility, LLVM bitcode generation, documentation adjustments) are done in subsequent commits requiring further review. Other aspects (e.g. not installing test-only extensions) are not yet addressed. When building on Windows with msbuild, builds are slower when using a visual studio version older than 2019, because those versions do not support MultiToolTask, required by meson for intra-target parallelism. The plan is to remove the MSVC specific build system in src/tools/msvc soon after reaching feature parity. However, we're not planning to remove the autoconf/make build system in the near future. Likely we're going to keep at least the parts required for PGXS to keep working around until all supported versions build with meson. Some initial help for postgres developers is at https://wiki.postgresql.org/wiki/Meson With contributions from Thomas Munro, John Naylor, Stone Tickle and others. Author: Andres Freund <andres@anarazel.de> Author: Nazir Bilal Yavuz <byavuz81@gmail.com> Author: Peter Eisentraut <peter@eisentraut.org> Reviewed-By: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Discussion: https://postgr.es/m/20211012083721.hvixq4pnh2pixr3j@alap3.anarazel.de
This commit is contained in:
174
src/common/meson.build
Normal file
174
src/common/meson.build
Normal file
@@ -0,0 +1,174 @@
|
||||
common_sources = files(
|
||||
'archive.c',
|
||||
'base64.c',
|
||||
'checksum_helper.c',
|
||||
'compression.c',
|
||||
'controldata_utils.c',
|
||||
'encnames.c',
|
||||
'exec.c',
|
||||
'file_perm.c',
|
||||
'file_utils.c',
|
||||
'hashfn.c',
|
||||
'ip.c',
|
||||
'jsonapi.c',
|
||||
'keywords.c',
|
||||
'kwlookup.c',
|
||||
'link-canary.c',
|
||||
'md5_common.c',
|
||||
'pg_get_line.c',
|
||||
'pg_lzcompress.c',
|
||||
'pg_prng.c',
|
||||
'pgfnames.c',
|
||||
'psprintf.c',
|
||||
'relpath.c',
|
||||
'rmtree.c',
|
||||
'saslprep.c',
|
||||
'scram-common.c',
|
||||
'string.c',
|
||||
'stringinfo.c',
|
||||
'unicode_norm.c',
|
||||
'username.c',
|
||||
'wait_error.c',
|
||||
'wchar.c',
|
||||
)
|
||||
|
||||
if ssl.found()
|
||||
common_sources += files(
|
||||
'cryptohash_openssl.c',
|
||||
'hmac_openssl.c',
|
||||
'protocol_openssl.c',
|
||||
)
|
||||
else
|
||||
common_sources += files(
|
||||
'cryptohash.c',
|
||||
'hmac.c',
|
||||
'md5.c',
|
||||
'sha1.c',
|
||||
'sha2.c',
|
||||
)
|
||||
endif
|
||||
|
||||
common_kwlist = custom_target('kwlist',
|
||||
input: files('../include/parser/kwlist.h'),
|
||||
output: 'kwlist_d.h',
|
||||
command: [perl, '-I', '@SOURCE_ROOT@/src/tools', files('../tools/gen_keywordlist.pl'),
|
||||
'--extern', '--output', '@OUTDIR@', '@INPUT@'])
|
||||
generated_sources += common_kwlist
|
||||
common_sources += common_kwlist
|
||||
|
||||
# The code imported from Ryu gets a pass on declaration-after-statement,
|
||||
# in order to keep it more closely aligned with its upstream.
|
||||
ryu_sources = files(
|
||||
'd2s.c',
|
||||
'f2s.c',
|
||||
)
|
||||
ryu_cflags = []
|
||||
|
||||
if using_declaration_after_statement_warning
|
||||
ryu_cflags += ['-Wno-declaration-after-statement']
|
||||
endif
|
||||
|
||||
config_info_sources = files('config_info.c',)
|
||||
config_info_cflags = [
|
||||
'-DVAL_CC="@0@"'.format(var_cc),
|
||||
'-DVAL_CPPFLAGS="@0@"'.format(var_cppflags),
|
||||
'-DVAL_CFLAGS="@0@"'.format(var_cflags),
|
||||
'-DVAL_CFLAGS_SL="@0@"'.format(var_cflags_sl),
|
||||
'-DVAL_LDFLAGS="@0@"'.format(var_ldflags),
|
||||
'-DVAL_LDFLAGS_EX="@0@"'.format(var_ldflags_ex),
|
||||
'-DVAL_LDFLAGS_SL="@0@"'.format(var_ldflags_sl),
|
||||
'-DVAL_LIBS="@0@"'.format(var_libs),
|
||||
]
|
||||
|
||||
# Some files need to be built with different cflags. The different sets are
|
||||
# defined here.
|
||||
common_cflags = {
|
||||
'ryu': ryu_cflags,
|
||||
'config_info': config_info_cflags,
|
||||
}
|
||||
common_sources_cflags = {
|
||||
'ryu': ryu_sources,
|
||||
'config_info': config_info_sources
|
||||
}
|
||||
|
||||
|
||||
# A few files are currently only built for frontend, not server
|
||||
# (Mkvcbuild.pm has a copy of this list, too). logging.c is excluded
|
||||
# from OBJS_FRONTEND_SHLIB (shared library) as a matter of policy,
|
||||
# because it is not appropriate for general purpose libraries such
|
||||
# as libpq to report errors directly.
|
||||
|
||||
common_sources_frontend_shlib = common_sources
|
||||
common_sources_frontend_shlib += files(
|
||||
'fe_memutils.c',
|
||||
'restricted_token.c',
|
||||
'sprompt.c',
|
||||
)
|
||||
|
||||
common_sources_frontend_static = common_sources_frontend_shlib
|
||||
common_sources_frontend_static += files(
|
||||
'logging.c',
|
||||
)
|
||||
|
||||
# Build pgport once for backend, once for use in frontend binaries, and once
|
||||
# for use in shared libraries
|
||||
#
|
||||
# XXX: in most environments we could probably link_whole pgcommon_shlib
|
||||
# against pgcommon_static, instead of compiling twice.
|
||||
#
|
||||
# For the server build of pgcommon, depend on lwlocknames_h, because at least
|
||||
# cryptohash_openssl.c, hmac_openssl.c depend on it. That's arguably a
|
||||
# layering violation, but ...
|
||||
pgcommon = {}
|
||||
pgcommon_variants = {
|
||||
'_srv': internal_lib_args + {
|
||||
'sources': common_sources + [lwlocknames_h],
|
||||
'dependencies': [backend_common_code],
|
||||
},
|
||||
'': default_lib_args + {
|
||||
'sources': common_sources_frontend_static,
|
||||
'dependencies': [frontend_common_code],
|
||||
},
|
||||
'_shlib': default_lib_args + {
|
||||
'pic': true,
|
||||
'sources': common_sources_frontend_shlib,
|
||||
'dependencies': [frontend_common_code],
|
||||
},
|
||||
}
|
||||
|
||||
foreach name, opts : pgcommon_variants
|
||||
|
||||
# Build internal static libraries for sets of files that need to be built
|
||||
# with different cflags
|
||||
cflag_libs = []
|
||||
foreach cflagname, sources : common_sources_cflags
|
||||
if sources.length() == 0
|
||||
continue
|
||||
endif
|
||||
c_args = opts.get('c_args', []) + common_cflags[cflagname]
|
||||
cflag_libs += static_library('libpgcommon@0@_@1@'.format(name, cflagname),
|
||||
include_directories: include_directories('.'),
|
||||
kwargs: opts + {
|
||||
'sources': sources,
|
||||
'c_args': c_args,
|
||||
'build_by_default': false,
|
||||
'install': false,
|
||||
},
|
||||
)
|
||||
endforeach
|
||||
|
||||
lib = static_library('libpgcommon@0@'.format(name),
|
||||
link_with: cflag_libs,
|
||||
include_directories: include_directories('.'),
|
||||
kwargs: opts + {
|
||||
'dependencies': opts['dependencies'] + [ssl],
|
||||
}
|
||||
)
|
||||
pgcommon += {name: lib}
|
||||
endforeach
|
||||
|
||||
common_srv = pgcommon['_srv']
|
||||
common_shlib = pgcommon['_shlib']
|
||||
common_static = pgcommon['']
|
||||
|
||||
subdir('unicode')
|
106
src/common/unicode/meson.build
Normal file
106
src/common/unicode/meson.build
Normal file
@@ -0,0 +1,106 @@
|
||||
UNICODE_VERSION = '15.0.0'
|
||||
|
||||
unicode_data = {}
|
||||
unicode_baseurl = 'https://www.unicode.org/Public/@0@/ucd/@1@'
|
||||
|
||||
if not wget.found()
|
||||
subdir_done()
|
||||
endif
|
||||
|
||||
# These files are part of the Unicode Character Database. Download them on
|
||||
# demand.
|
||||
foreach f : ['UnicodeData.txt', 'EastAsianWidth.txt', 'DerivedNormalizationProps.txt', 'CompositionExclusions.txt', 'NormalizationTest.txt']
|
||||
url = unicode_baseurl.format(UNICODE_VERSION, f)
|
||||
target = custom_target(f,
|
||||
output: f,
|
||||
command: [wget, wget_flags, url],
|
||||
build_by_default: false,
|
||||
)
|
||||
unicode_data += {f: target}
|
||||
endforeach
|
||||
|
||||
|
||||
update_unicode_targets = []
|
||||
|
||||
update_unicode_targets += \
|
||||
custom_target('unicode_norm_table.h',
|
||||
input: [unicode_data['UnicodeData.txt'], unicode_data['CompositionExclusions.txt']],
|
||||
output: ['unicode_norm_table.h', 'unicode_norm_hashfunc.h'],
|
||||
command: [
|
||||
perl, files('generate-unicode_norm_table.pl'),
|
||||
'--outdir', '@OUTDIR@', '@INPUT@'],
|
||||
build_by_default: false,
|
||||
)
|
||||
|
||||
update_unicode_targets += \
|
||||
custom_target('unicode_nonspacing_table.h',
|
||||
input: [unicode_data['UnicodeData.txt']],
|
||||
output: ['unicode_nonspacing_table.h'],
|
||||
command: [perl, files('generate-unicode_nonspacing_table.pl'), '@INPUT@'],
|
||||
build_by_default: false,
|
||||
capture: true,
|
||||
)
|
||||
|
||||
update_unicode_targets += \
|
||||
custom_target('unicode_east_asian_fw_table.h',
|
||||
input: [unicode_data['EastAsianWidth.txt']],
|
||||
output: ['unicode_east_asian_fw_table.h'],
|
||||
command: [perl, files('generate-unicode_east_asian_fw_table.pl'), '@INPUT@'],
|
||||
build_by_default: false,
|
||||
capture: true,
|
||||
)
|
||||
|
||||
update_unicode_targets += \
|
||||
custom_target('unicode_normprops_table.h',
|
||||
input: [unicode_data['DerivedNormalizationProps.txt']],
|
||||
output: ['unicode_normprops_table.h'],
|
||||
command: [perl, files('generate-unicode_normprops_table.pl'), '@INPUT@'],
|
||||
build_by_default: false,
|
||||
capture: true,
|
||||
)
|
||||
|
||||
norm_test_table = custom_target('norm_test_table.h',
|
||||
input: [unicode_data['NormalizationTest.txt']],
|
||||
output: ['norm_test_table.h'],
|
||||
command: [perl, files('generate-norm_test_table.pl'), '@INPUT@', '@OUTPUT@'],
|
||||
build_by_default: false,
|
||||
)
|
||||
|
||||
inc = include_directories('.')
|
||||
|
||||
norm_test = executable('norm_test',
|
||||
['norm_test.c', norm_test_table],
|
||||
dependencies: [frontend_port_code],
|
||||
include_directories: inc,
|
||||
link_with: [common_static, pgport_static],
|
||||
build_by_default: false,
|
||||
kwargs: default_bin_args + {
|
||||
'install': false,
|
||||
}
|
||||
)
|
||||
|
||||
update_unicode_dep = []
|
||||
|
||||
if not meson.is_cross_build()
|
||||
update_unicode_dep += custom_target('norm_test.run',
|
||||
output: 'norm_test.run',
|
||||
input: update_unicode_targets,
|
||||
command: [norm_test],
|
||||
build_by_default: false,
|
||||
build_always_stale: true,
|
||||
)
|
||||
endif
|
||||
|
||||
|
||||
# Use a custom target, as run targets serialize the output, making this harder
|
||||
# to debug, and don't deal well with targets with multiple outputs.
|
||||
update_unicode = custom_target('update-unicode',
|
||||
depends: update_unicode_dep,
|
||||
output: ['dont-exist'],
|
||||
input: update_unicode_targets,
|
||||
command: ['cp', '@INPUT@', '@SOURCE_ROOT@/src/include/common/'],
|
||||
build_by_default: false,
|
||||
build_always_stale: true,
|
||||
)
|
||||
|
||||
alias_target('update-unicode', update_unicode)
|
Reference in New Issue
Block a user