Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsmSD-0026Ax-1W for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Feb 2026 18:39:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsmSB-00HLT9-1F for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Feb 2026 18:39:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsmSB-00HLSr-08 for pgsql-hackers@lists.postgresql.org; Wed, 18 Feb 2026 18:39:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsmS5-000000000HN-2f6l for pgsql-hackers@postgresql.org; Wed, 18 Feb 2026 18:39:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 61IId5pc2064895; Wed, 18 Feb 2026 13:39:06 -0500 From: Tom Lane To: Peter Eisentraut cc: Andres Freund , pgsql-hackers , Tristan Partin Subject: Re: meson: Allow disabling static libraries In-reply-to: References: Comments: In-reply-to Peter Eisentraut message dated "Tue, 27 Jan 2026 15:03:03 +0100" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2064818.1771439895.0@sss.pgh.pa.us> Date: Wed, 18 Feb 2026 13:39:05 -0500 Message-ID: <2064894.1771439945@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2064818.1771439895.1@sss.pgh.pa.us> Peter Eisentraut writes: > On 20.01.26 18:03, Andres Freund wrote: >> Separately, perhaps it'd be mildly nicer to have a boolean for static libs >> instead of using .found() everywhere. > Yeah, after playing with this a bit more, I'm not sure sure this > disabler trick is really that good. The idea would have been that you > just need to add the disabler to the dependencies and everything else > will magically work. But the reason that you need stuff like > +if dep_static_lib.found() > + installed_targets += [libpq_st] > +endif > is that the disabler sneaks up into other variables and dependencies and > has weird effects. For example, if you remove "if" around this and > similar lines, then "meson test" breaks in highly confusing ways > (probably because tmp_install depends on installed_targets). That seems like an excellent reason to stay away from disabler() and use your "variant 2". I reviewed/tested this and noted a couple of other problems: 1. This doesn't work for AIX, because there we'll need to force build_static_lib to false and yet we'll still want (by default anyway) to install libpgcommon.a and friends. In the attached I dealt with that by breaking build_static_lib into two variables, build_static_lib and install_internal_static_lib. 2. As written, this resulted in installing libpgcommon_srv.a and libpgport_srv.a, whereas historically we've only installed the frontend and shlib variants of those libraries. I do not see a reason to change that behavior. I fixed it in the attached with + 'install': install_internal_static_lib and name != '_srv', but perhaps there's a nicer way? I think the attached v3 is about ready to go, with perhaps two loose ends for you to deal with: * Do we need to document this in the SGML docs? * Given that -Ddefault_library=static doesn't actually work and I doubt we have any interest in ever making it work, perhaps it would be nicer to throw an explicit 'not supported' error. As this stands, if you try it you get src/interfaces/libpq/meson.build:89:0: ERROR: Unknown variable "libpq_so". which looks more like a bug than an intentionally-unsupported option. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name*0="v3-0001-meson-allow-disabling-building-installation-of-st.p"; name*1="atch"; charset="us-ascii" Content-ID: <2064818.1771439895.2@sss.pgh.pa.us> Content-Description: v3-0001-meson-allow-disabling-building-installation-of-st.patch Content-Transfer-Encoding: quoted-printable =46rom ab973a6061b3c6b6b42905f5bac9da905123bd2d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 18 Feb 2026 13:22:37 -0500 Subject: [PATCH v3] meson: allow disabling building/installation of static libraries. We now support the common meson option -Ddefault_library, with values 'both' (the default), 'shared' (install only shared libraries), and 'static' (install only static libraries). The 'static' choice doesn't actually work, since psql and other programs insist on linking to the shared version of libpq, but it's there pro-forma. It could be built out if we really wanted, but since we have never supported the equivalent in the autoconf build system, I think we don't want it. With an eye to re-supporting AIX, the internal implementation distinguishes whether to install libpgport.a and other static-only libraries from whether to build/install the static variant of libraries that we can build both ways. This detail isn't exposed as a meson option, though it could be if there's demand. Author: Peter Eisentraut Reviewed-by: Andres Freund Reviewed-by: Tom Lane Discussion: https://postgr.es/m/e8aa97db-872b-4087-b073-f296baae948d@eisen= traut.org --- .cirrus.tasks.yml | 1 + meson.build | 38 +++++++++++++++++----- src/common/meson.build | 1 + src/fe_utils/meson.build | 4 ++- src/interfaces/ecpg/compatlib/meson.build | 4 +++ src/interfaces/ecpg/ecpglib/meson.build | 4 +++ src/interfaces/ecpg/pgtypeslib/meson.build | 8 +++-- src/interfaces/libpq-oauth/meson.build | 6 ++++ src/interfaces/libpq/meson.build | 6 ++++ src/port/meson.build | 1 + 10 files changed, 61 insertions(+), 12 deletions(-) diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml index 2a821593ce5..4841a204248 100644 --- a/.cirrus.tasks.yml +++ b/.cirrus.tasks.yml @@ -133,6 +133,7 @@ task: meson setup \ --buildtype=3Ddebug \ --auto-features=3Ddisabled \ + -Ddefault_library=3Dshared \ -Dtap_tests=3Denabled \ build EOF diff --git a/meson.build b/meson.build index f6d5842d852..9ce34e3ce37 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,7 @@ project('postgresql', 'warning_level=3D1', #-Wall equivalent 'b_pch=3Dfalse', 'buildtype=3Ddebugoptimized', # -O2 + debug + 'default_library=3Dboth', # For compatibility with the autoconf build, set a default prefix. Th= is # works even on windows, where it's a drive-relative path (i.e. when = on # d:/somepath it'll install to d:/usr/local/pgsql) @@ -50,6 +51,31 @@ not_found_dep =3D dependency('', required: false) thread_dep =3D dependency('threads') auto_features =3D get_option('auto_features') = +# Declare variables to disable static or shared libraries. This +# makes the 'default_library' option work even though we don't use the +# library() function but instead shared_library() and static_library() +# separately. +# +# build_shared_lib/build_static_lib control building/installing the two +# versions of libraries that we can build both versions of (e.g., libpq). +# There are also libraries that we only build a static version of (e.g., +# libpgport). These are always built, since we need them while building, +# but they are installed only if install_internal_static_lib is true. +# +# Note: at present, -Ddefault_library=3Dstatic doesn't actually work, bec= ause +# psql and other programs insist on linking to the shared version of libp= q. +# This could be fixed if there was interest, but so far there is not. +default_library_opt =3D get_option('default_library') +build_shared_lib =3D true +build_static_lib =3D true +install_internal_static_lib =3D true +if default_library_opt =3D=3D 'shared' + build_static_lib =3D false + install_internal_static_lib =3D false +elif default_library_opt =3D=3D 'static' + build_shared_lib =3D false +endif + = = ############################################################### @@ -3104,6 +3130,7 @@ add_project_link_arguments(ldflags, language: ['c', = 'cpp']) # list of targets for various alias targets backend_targets =3D [] bin_targets =3D [] +libpq_targets =3D [] pl_targets =3D [] contrib_targets =3D [] testprep_targets =3D [] @@ -3530,20 +3557,13 @@ endif installed_targets =3D [ backend_targets, bin_targets, - libpq_st, + libpq_targets, pl_targets, contrib_targets, nls_mo_targets, ecpg_targets, ] = -if oauth_flow_supported - installed_targets +=3D [ - libpq_oauth_so, - libpq_oauth_st, - ] -endif - # all targets that require building code all_built =3D [ installed_targets, @@ -3880,7 +3900,7 @@ add_test_setup('running', ############################################################### = alias_target('backend', backend_targets) -alias_target('bin', bin_targets + [libpq_st]) +alias_target('bin', bin_targets + libpq_targets) alias_target('pl', pl_targets) alias_target('contrib', contrib_targets) alias_target('testprep', testprep_targets) diff --git a/src/common/meson.build b/src/common/meson.build index b757618a9c9..4f9b8b8263d 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -192,6 +192,7 @@ foreach name, opts : pgcommon_variants opts.get('include_directories', []), ], 'dependencies': opts['dependencies'] + [ssl], + 'install': install_internal_static_lib and name !=3D '_srv', } ) pgcommon +=3D {name: lib} diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index a2420ea2d5c..86befca192e 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -35,5 +35,7 @@ fe_utils =3D static_library('libpgfeutils', include_directories: [postgres_inc, libpq_inc], c_args: host_system =3D=3D 'windows' ? ['-DFD_SETSIZE=3D1024'] : [], dependencies: frontend_common_code, - kwargs: default_lib_args, + kwargs: default_lib_args + { + 'install': install_internal_static_lib, + }, ) diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ec= pg/compatlib/meson.build index 6cb1be73407..d578faefe1c 100644 --- a/src/interfaces/ecpg/compatlib/meson.build +++ b/src/interfaces/ecpg/compatlib/meson.build @@ -16,6 +16,7 @@ if host_system =3D=3D 'windows' endif = # see src/interfaces/libpq/meson.build +if build_static_lib ecpg_compat_st =3D static_library('libecpg_compat', ecpg_compat_sources, include_directories: ecpg_compat_inc, @@ -25,7 +26,9 @@ ecpg_compat_st =3D static_library('libecpg_compat', kwargs: default_lib_args, ) ecpg_targets +=3D ecpg_compat_st +endif = +if build_shared_lib ecpg_compat_so =3D shared_library('libecpg_compat', ecpg_compat_sources + ecpg_compat_so_sources, include_directories: ecpg_compat_inc, @@ -40,6 +43,7 @@ ecpg_compat_so =3D shared_library('libecpg_compat', kwargs: default_lib_args, ) ecpg_targets +=3D ecpg_compat_so +endif = pkgconfig.generate( name: 'libecpg_compat', diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg= /ecpglib/meson.build index 889bd9efd65..81e92151945 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -25,6 +25,7 @@ if host_system =3D=3D 'windows' endif = # see src/interfaces/libpq/meson.build +if build_static_lib ecpglib_st =3D static_library('libecpg', ecpglib_sources, include_directories: ecpglib_inc, @@ -35,7 +36,9 @@ ecpglib_st =3D static_library('libecpg', kwargs: default_lib_args, ) ecpg_targets +=3D ecpglib_st +endif = +if build_shared_lib ecpglib_so =3D shared_library('libecpg', ecpglib_sources + ecpglib_so_sources, include_directories: ecpglib_inc, @@ -51,6 +54,7 @@ ecpglib_so =3D shared_library('libecpg', kwargs: default_lib_args, ) ecpg_targets +=3D ecpglib_so +endif = pkgconfig.generate( name: 'libecpg', diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/e= cpg/pgtypeslib/meson.build index 6b78f529e53..241fa95e559 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -21,22 +21,25 @@ if host_system =3D=3D 'windows' endif = # see src/interfaces/libpq/meson.build +if build_static_lib ecpg_pgtypes_st =3D 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, + dependencies: [frontend_stlib_code], kwargs: default_lib_args, ) ecpg_targets +=3D ecpg_pgtypes_st +endif = +if build_shared_lib ecpg_pgtypes_so =3D 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, + dependencies: [frontend_shlib_code], version: '3.' + pg_version_major.to_string(), soversion: host_system !=3D 'windows' ? '3' : '', darwin_versions: ['3', '3.' + pg_version_major.to_string()], @@ -45,6 +48,7 @@ ecpg_pgtypes_so =3D shared_library('libpgtypes', kwargs: default_lib_args, ) ecpg_targets +=3D ecpg_pgtypes_so +endif = pkgconfig.generate( name: 'libpgtypes', diff --git a/src/interfaces/libpq-oauth/meson.build b/src/interfaces/libpq= -oauth/meson.build index d8a0c04095a..27aca2bc324 100644 --- a/src/interfaces/libpq-oauth/meson.build +++ b/src/interfaces/libpq-oauth/meson.build @@ -21,6 +21,7 @@ export_file =3D custom_target('libpq-oauth.exports', # port needs to be in include path due to pthread-win32.h libpq_oauth_inc =3D include_directories('.', '../libpq', '../../port') = +if build_static_lib libpq_oauth_st =3D static_library('libpq-oauth', libpq_oauth_sources, include_directories: [libpq_oauth_inc, postgres_inc], @@ -32,11 +33,14 @@ libpq_oauth_st =3D static_library('libpq-oauth', ], kwargs: default_lib_args, ) +libpq_targets +=3D libpq_oauth_st +endif = # This is an internal module; we don't want an SONAME and therefore do no= t set # SO_MAJOR_VERSION. libpq_oauth_name =3D 'libpq-oauth-@0@'.format(pg_version_major) = +if build_shared_lib libpq_oauth_so =3D shared_module(libpq_oauth_name, libpq_oauth_sources + libpq_oauth_so_sources, include_directories: [libpq_oauth_inc, postgres_inc], @@ -47,6 +51,8 @@ libpq_oauth_so =3D shared_module(libpq_oauth_name, link_args: export_fmt.format(export_file.full_path()), kwargs: default_lib_args, ) +libpq_targets +=3D libpq_oauth_so +endif = libpq_oauth_test_deps =3D [] = diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson= .build index c5ecd9c3a87..2b95098187e 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -57,6 +57,7 @@ libpq_so_c_args =3D ['-DUSE_DYNAMIC_OAUTH'] # We could try to avoid building the source files twice, but it probably = adds # more complexity than its worth (reusing object files requires also link= ing # to the library on windows or breaks precompiled headers). +if build_static_lib libpq_st =3D static_library('libpq', libpq_sources, include_directories: [libpq_inc], @@ -65,7 +66,10 @@ libpq_st =3D static_library('libpq', dependencies: [frontend_stlib_code, libpq_deps], kwargs: default_lib_args, ) +libpq_targets +=3D libpq_st +endif = +if build_shared_lib libpq_so =3D shared_library('libpq', libpq_sources + libpq_so_sources, include_directories: [libpq_inc, postgres_inc], @@ -79,6 +83,8 @@ libpq_so =3D shared_library('libpq', link_args: export_fmt.format(export_file.full_path()), kwargs: default_lib_args, ) +libpq_targets +=3D libpq_so +endif = libpq =3D declare_dependency( link_with: [libpq_so], diff --git a/src/port/meson.build b/src/port/meson.build index d7d4e705b89..52f9b3da631 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -192,6 +192,7 @@ foreach name, opts : pgport_variants c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], + 'install': install_internal_static_lib and name !=3D '_srv', } ) pgport +=3D {name: lib} -- = 2.43.7 ------- =_aaaaaaaaaa0--