[RFC] building postgres with meson
Andres Freund <andres@anarazel.de>
Attachments
Hi, For the last year or so I've on and off tinkered with $subject. I think it's in a state worth sharing now. First, let's look at a little comparison. My workstation: non-cached configure: current: 11.80s meson: 6.67s non-cached build (world-bin): current: 40.46s ninja: 7.31s no-change build: current: 1.17s ninja: 0.06s test world: current: 105s meson: 63s What actually started to motivate me however were the long times windows builds took to come back with testsresults. On CI, with the same machine config: build: current: 202s (doesn't include genbki etc) meson+ninja: 140s meson+msbuild: 206s test: current: 1323s (many commands) meson: 903s (single command) (note that the test comparison isn't quite fair - there's a few tests missing, but it's just small contrib ones afaik) The biggest difference to me however is not the speed, but how readable the output is. Running the tests with meson in a terminal, shows the number of tests that completed out of how many total, how much time has passed, how long the currently running tests already have been running. At the end of a testrun a count of tests is shown: 188/189 postgresql:tap+pg_basebackup / pg_basebackup/t/010_pg_basebackup.pl OK 39.51s 110 subtests passed 189/189 postgresql:isolation+snapshot_too_old / snapshot_too_old/isolation OK 62.93s Ok: 188 Expected Fail: 0 Fail: 1 Unexpected Pass: 0 Skipped: 0 Timeout: 0 Full log written to /tmp/meson/meson-logs/testlog.txt The log has the output of the tests and ends with: Summary of Failures: 120/189 postgresql:tap+recovery / recovery/t/007_sync_rep.pl ERROR 7.16s (exit status 255 or signal 127 SIGinvalid) Quite the difference to make check-world -jnn output. So, now that the teasing is done, let me explain a bit what lead me down this path: Autoconf + make is not being actively developed. Especially autoconf is *barely* in maintenance mode - despite many shortcomings and bugs. It's also technology that very few want to use - autoconf m4 is scary, and it's scarier for people that started more recently than a lot of us committers for example. Recursive make as we use it is hard to get right. One reason the clean make build is so slow compared to meson is that we had to resort to .NOTPARALLEL to handle dependencies in a bunch of places. And despite that, I quite regularly see incremental build failures that can be resolved by retrying the build. While we have incremental build via --enable-depend, they don't work that reliable (i.e. misses necessary rebuilds) and yet is often too aggressive. More modern build system can keep track of the precise command used to build a target and rebuild it when that command changes. We also don't just have the autoconf / make buildsystem, there's also the msvc project generator - something most of us unix-y folks do not like to touch. I think that, combined with there being no easy way to run all tests, and it being just different, really hurt our windows developer appeal (and subsequently the quality of postgres on windows). I'm not saying this to ding the project generator - that was well before there were decent "meta" buildsystems out there (and in some ways it is a small one itself). The last big issue I have with the current situation is that there's no good test integration. make check-world output is essentially unreadable / not automatically parseable. Which led to the buildfarm having a separate list of things it needs to test, so that failures can be pinpointed and paired with appropriate logs. That approach unfortunately doesn't scale well to multi-core CPUs, slowing down the buildfarm by a fair bit. This all led to me to experiment with improvements. I tried a few somewhat crazy but incremental things like converting our buildsystem to non-recursive make (I got it to build the backend, but it's too hard to do manually I think), or to not run tests during the recursive make check-world, but to append commands to a list of tests, that then is run by a helper (can kinda be made to work). In the end I concluded that the amount of time we'd need to invest to maintain our more-and-more custom buildsystem going forward doesn't make sense. Which lead me to look around and analyze which other buildsystems there are that could make some sense for us. The halfway decent list includes, I think: 1) cmake 2) bazel 3) meson cmake would be a decent choice, I think. However, I just can't fully warm up to it. Something about it just doesn't quite sit right with me. That's not a good enough reason to prevent others from suggesting to use it, but it's good enough to justify not investing a lot of time in it myself. Bazel has some nice architectural properties. But it requires a JVM to run - I think that basically makes it insuitable for us. And the build information seems quite arduous to maintain too. Which left me with meson. It is a meta-buildsystem that can do the actual work of building via ninja (the most common one, also targeted by cmake), msbuild (visual studio project files, important for GUI work) and xcode projects (I assume that's for a macos IDE, but I haven't tried to use it). Meson roughly does what autoconf+automake did, in a python-esque DSL, and outputs build-instructions for ninja / msbuild / xcode. One interesting bit is that meson itself is written in python ( and fairly easy to contribute too - I got a few changes in now). I don't think meson is perfect architecturally - e.g. its insistence on not having functions ends up making it a bit harder to not end up duplicating code. There's some user-interface oddities that are now hard to fix fully, due to the faily wide usage. But all-in-all it's pretty nice to use. Its worth calling out that a lot of large open source projects have been / are migrating to meson. qemu/kvm, mesa (core part of graphics stack on linux and also widely used in other platforms), a good chunk of GNOME, and quite a few more. Due to that it seems unlikely to be abandoned soon. As far as I can tell the only OS that postgres currently supports that meson doesn't support is HPUX. It'd likely be fairly easy to add gcc-on-hpux support, a chunk more to add support for the proprietary ones. The attached patch (meson support is 0016, the rest is prerequisites that aren't that interesting at this stage) converts most of postgres to meson. There's a few missing contrib modules, only about half the optional library dependencies are implemented, and I've only built on x64. It builds on freebsd, linux, macos and windows (both ninja and msbuild) and cross builds from linux to windows. Thomas helped make the freebsd / macos pieces a reality, thanks! I took a number of shortcuts (although there used to be a *lot* more). So this shouldn't be reviewed to the normal standard of the community - it's a prototype. But I think it's in a complete enough shape that it allows to do a well-informed evaluation. What doesn't yet work/ build: - plenty optional libraries, contrib, NLS, docs build - PGXS - and I don't yet know what to best do about it. One backward-compatible way would be to continue use makefiles for pgxs, but do the necessary replacement of Makefile.global.in via meson (and not use that for postgres' own build). But that doesn't really provide a nicer path for building postgres extensions on windows, so it'd definitely not be a long-term path. - JIT bitcode generation for anything but src/backend. - anything but modern-ish x86. That's proably a small amount of work, but something that needs to be done. - exporting all symbols for extension modules on windows (the stuff for postgres is implemented). Instead I marked the relevant symbols als declspec(dllexport). I think we should do that regardless of the buildsystem change. Restricting symbol visibility via gcc's -fvisibility=hidden for extensions results in a substantially reduced number of exported symbols, and even reduces object size (and I think improves the code too). I'll send an email about that separately. There's a lot more stuff to talk about, but I'll stop with a small bit of instructions below: Demo / instructions: # Get code git remote add andres git@github.com:anarazel/postgres.git git fetch andres git checkout --track andres/meson # setup build directory meson setup build --buildtype debug cd build # build (uses automatically as many cores as available) ninja # change configuration, build again meson configure -Dssl=openssl ninja # run all tests meson test # run just recovery tests meson test --suite setup --suite recovery # list tests meson test --list Greetings, Andres Freund
Commits
-
meson: Add 'running' test setup, as a replacement for installcheck
- 3f0e786ccbf5 16.0 landed
-
meson: Add support for building with precompiled headers
- e5555657ba86 16.0 landed
-
windows: Adjust FD_SETSIZE via commandline define
- 4289263cf263 16.0 landed
-
meson: docs: Add xml{lint,proc} wrapper to collect dependencies
- 29668e31865a 16.0 landed
-
meson: ecpg: Split definition of static and shared libraries
- a1261cd16f07 16.0 landed
-
windows: Set UMDF_USING_NTSTATUS globally, include ntstatus.h
- b8d8a4593a3a 16.0 landed
-
ci: Add hint about downloadable logs to README
- bed0927aeb0c 16.0 cited
-
meson: Set up absolute rpaths to libdir
- a1860071b3fc 16.0 landed
-
meson: Include CFLAGS/c_args in summary and pg_config output
- 1330dcdec0f2 16.0 landed
-
windows: remove date from version number in win32ver.rc
- 31d2c4716e6b 16.0 landed
-
meson: Add initial version of meson based build system
- e6927270cd18 16.0 landed
-
ci: windows: set error mode to not include SEM_NOGPFAULTERRORBOX
- 0c400445dbe3 15.0 landed
- 661ee7bfc661 16.0 landed
-
Refactor PG_TEST_EXTRA logic in autoconf build
- c3382a3c3ccd 16.0 landed
-
Split TESTDIR into TESTLOGDIR and TESTDATADIR
- c47885bd8b69 16.0 landed
-
Don't hardcode tmp_check/ as test directory for tap tests
- bb54bf22900f 16.0 landed
-
Extend gendef.pl in preparation for meson
- 70df2df1cc89 16.0 landed
-
Include c.h instead of postgres.h in src/port/*p{read,write}*.c
- 5aee41e28de9 12.13 landed
- f69b8f324af5 13.9 landed
- b4b4b817da5a 14.6 landed
- 940c1c7ed3d1 15.0 landed
- 43fcaa345d5a 16.0 landed
-
Remove DLLTOOL, DLLWRAP from configure / Makefile.global.in
- 8d513a6b71b7 16.0 landed
-
Run xmllint validation only once
- ab393528fa4b 16.0 landed
-
Bump minimum Perl version to 5.14
- 4c1532763a00 16.0 landed
-
Move gramparse.h to src/backend/parser
- ecaf7c5df54f 16.0 landed
-
Run perltidy over Catalog.pm
- b2e6e768230b 16.0 landed
-
Parse catalog .dat files as a whole when compiling the backend
- 69eb643b2582 16.0 landed
-
Build all Flex files standalone
- dac048f71ebb 16.0 landed
-
Move private declarations shared between guc.c and guc-file.l to new header
- 80e8450a744b 16.0 landed
-
Preparatory refactoring for compiling guc-file.c standalone
- 1b188ea7921a 16.0 landed
-
Move darwin sysroot determination into separate file
- 05519126a02e 16.0 landed
-
Fix MSVC warning in compat_informix/rnull.pgc
- 483ac6476198 16.0 landed
-
solaris: Use versioning scripts instead of -Bsymbolic
- 3fb0687d328b 16.0 landed
-
Change shared library installation naming on macOS
- 161355ee6d2c 16.0 landed
-
regress: allow to specify directory containing expected files, for ecpg
- c855872074b5 16.0 landed
-
Don't add HAVE_LDAP_H HAVE_WINLDAP_H to pg_config.h
- 4ab53b647abf 16.0 landed
-
Refactor dtrace postprocessing make rules
- eb6569fd0e24 16.0 landed
-
Add output directory option to gen_node_support.pl
- adba4b747106 16.0 landed
-
Add output directory argument to generate-unicode_norm_table.pl
- c8a9246e09cc 16.0 landed
-
Add output file argument to generate-errcodes.pl
- 2bf626b714b5 16.0 landed
-
Add output path arg in generate-lwlocknames.pl
- 4f20506fe040 16.0 landed
-
Move snowball_create.sql creation into perl file
- b3a0d8324cf1 16.0 landed
-
ecpg: Output dir, source dir, stamp file argument for preproc/*.pl
- db0a272d123b 16.0 landed
-
psql: Output dir and dependency generation for sql_help
- 7c3c2cb9aeda 16.0 landed
-
Deal with paths containing \ and spaces in basebackup_to_shell tests
- a91242b1bcb3 16.0 landed
- 1ab071983637 15.0 landed
-
Remove LLVM_CONFIG from Makefile.global.in
- 7775c748db12 16.0 landed
-
Make update-unicode target work in vpath builds
- c64fb698d076 15.0 landed
-
Refactor DLSUFFIX handling
- 23119d51a14c 15.0 landed
-
ldap tests: Add paths for openbsd.
- 45fb0de4dc65 15.0 landed
-
ldap tests: Don't run on unsupported operating systems.
- ee56c3b21629 15.0 landed
-
Remove check for accept() argument types
- ee3a1a5b636b 15.0 landed
-
Move our p{read,write}v replacements into their own files.
- 0d56acfbaa79 14.0 cited
-
Adjust yywrap macro for non-reentrant scanners for MSVC.
- 08a0c2dabc3b 9.1.0 cited
-
Remove any -arch switches given in ExtUtils::Embed's ldopts from our
- d69a419e682c 9.0.0 cited
-
Change PL/Perl and Pg interface build to use configured compiler and
- 7662419f1bc1 7.3.1 cited
-
Apparently, on some systems, ExtUtils::Embed and MakeMaker are slightly
- f5d0c6cad5bb 7.2.1 cited