pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Enable Python Limited API for PL/Python on MSVC
4+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2026-01-16 6831cd9e3b  Fix PL/Python build on MSVC with older Meson
* pgsql: Enable Python Limited API for PL/Python on MSVC
@ 2026-01-14 09:53 Peter Eisentraut <peter@eisentraut.org>
  2026-01-15 09:36 ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Peter Eisentraut @ 2026-01-14 09:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Enable Python Limited API for PL/Python on MSVC

Previously, the Python Limited API was disabled on MSVC due to build
failures caused by Meson not knowing to link against python3.lib
instead of python3XX.lib when using the Limited API.

This commit works around the Meson limitation by explicitly finding
and linking against python3.lib on MSVC, and removes the preprocessor
guard that was disabling the Limited API on MSVC in plpython.h.

This requires python3.lib to be present in the Python installation,
which is included when Python is installed.

Author: Bryan Green <dbryan.green@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/ee410de1-1e0b-4770-b125-eeefd4726a24%40eisentraut.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2bc60f86219b00a9ba23efab8f4bb8de21e64e2a

Modified Files
--------------
meson.build                | 16 +++++++++++++++-
src/pl/plpython/plpython.h |  4 ----
2 files changed, 15 insertions(+), 5 deletions(-)



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

* Re: pgsql: Enable Python Limited API for PL/Python on MSVC
  2026-01-14 09:53 pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-15 09:36 ` Peter Eisentraut <peter@eisentraut.org>
  2026-01-15 16:21   ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Bryan Green <dbryan.green@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Peter Eisentraut @ 2026-01-15 09:36 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org, Andrew Dunstan <andrew@dunslane.net>; Bryan Green <dbryan.green@gmail.com>

This is failing on buildfarm member drongo: 
<https://buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=drongo&br=master;. 
  AFAICT, this is the only buildfarm member that tests Python on 
Windows, so we have no additional results to compare with.  It did pass 
on Cirrus CI.  Andrew/Bryan, could you figure out how the Python 
installation on drongo is different?


On 14.01.26 10:53, Peter Eisentraut wrote:
> Enable Python Limited API for PL/Python on MSVC
> 
> Previously, the Python Limited API was disabled on MSVC due to build
> failures caused by Meson not knowing to link against python3.lib
> instead of python3XX.lib when using the Limited API.
> 
> This commit works around the Meson limitation by explicitly finding
> and linking against python3.lib on MSVC, and removes the preprocessor
> guard that was disabling the Limited API on MSVC in plpython.h.
> 
> This requires python3.lib to be present in the Python installation,
> which is included when Python is installed.
> 
> Author: Bryan Green <dbryan.green@gmail.com>
> Discussion: https://www.postgresql.org/message-id/flat/ee410de1-1e0b-4770-b125-eeefd4726a24%40eisentraut.org
> 
> Branch
> ------
> master
> 
> Details
> -------
> https://git.postgresql.org/pg/commitdiff/2bc60f86219b00a9ba23efab8f4bb8de21e64e2a
> 
> Modified Files
> --------------
> meson.build                | 16 +++++++++++++++-
> src/pl/plpython/plpython.h |  4 ----
> 2 files changed, 15 insertions(+), 5 deletions(-)
> 






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

* Re: pgsql: Enable Python Limited API for PL/Python on MSVC
  2026-01-14 09:53 pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
  2026-01-15 09:36 ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-15 16:21   ` Bryan Green <dbryan.green@gmail.com>
  2026-01-17 05:26     ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Bryan Green @ 2026-01-15 16:21 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; pgsql-committers@lists.postgresql.org, Andrew Dunstan <andrew@dunslane.net>

On 1/15/2026 3:36 AM, Peter Eisentraut wrote:
> This is failing on buildfarm member drongo: <https://
> buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=drongo&br=master>.
>  AFAICT, this is the only buildfarm member that tests Python on Windows,
> so we have no additional results to compare with.  It did pass on Cirrus
> CI.  Andrew/Bryan, could you figure out how the Python installation on
> drongo is different?
> 

Peter, Andrew,

The failure on drongo is due to my writing this patch to support meson
versions >= 1.1.0.  I setup my local environment to match CI and was
using meson 1.10.0.  Before 1.1.0 you needed to pass the include
directory to check_headers with arg:.  I have made the changes and
tested python 3.11 w/meson 0.57.2 and 1.0.1.  I have also retested with
python 3.14 and meson 1.10.0.  Everything passed.

Additional items to note:

1. meson 1.0.1 expects distutils which was retired in python 3.12.  If
you want to use a later python with that version of meson (or earlier)
you will need to install setuptools which has a distutils shim I am led
to believe.
2. when building with meson 0.57.2 I had to provide -Dreadline=disabled
for the build to succeed.



The v2 patch is attached.


-- 
Bryan Green
EDB: https://www.enterprisedb.com

Attachments:

v2-0001-Enable-Python-Limited-API-for-PL-Python-on-MSVC.patch (text/plain, 3.0K) download From a3d39e86c640ef441ac919aefaec6a670beacb0b Mon Sep 17 00:00:00 2001 From: Bryan Green <dbryan.green@gmail.com> Date: Fri, 2 Jan 2026 10:48:54 -0600 Subject: [PATCH v2] Enable Python Limited API for PL/Python on MSVC Previously, the Python Limited API was disabled on MSVC due to build failures caused by Meson not knowing to link against python3.lib instead of python3XX.lib when using the Limited API. This commit works around the Meson limitation by explicitly finding and linking against python3.lib on MSVC, and removes the preprocessor guard that was disabling the Limited API on MSVC in plpython.h. This requires python3.lib to be present in the Python installation, which is included when Python is installed. Discussion: https://www.postgresql.org/message-id/flat/ee410de1-1e0b-4770-b125-eeefd4726a24%40eisentraut.org --- meson.build | 21 +++++++++++++++++++-- src/pl/plpython/plpython.h | 4 ---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index d7c5193d4c..4b45732d53 100644 --- a/meson.build +++ b/meson.build @@ -1329,9 +1329,26 @@ if not pyopt.disabled() pm = import('python') python3_inst = pm.find_installation(python.full_path(), required: pyopt) if python3_inst.found() - python3_dep = python3_inst.dependency(embed: true, required: pyopt) + # For Limited API on MSVC, link against python3.lib instead of python3XX.lib. + # Meson doesn't handle this automatically: + # <https://github.com/mesonbuild/meson/issues/13824> + if host_system == 'windows' and cc.get_id() == 'msvc' + python3_prefix = python3_inst.get_variable('prefix') + python3_libdir = python3_prefix / 'libs' + python3_incdir = python3_prefix / 'include' + python3_lib = cc.find_library('python3', dirs: python3_libdir, required: pyopt) + python3_dep = declare_dependency( + include_directories: include_directories(python3_incdir), + dependencies: python3_lib, + ) + # Explicit args needed for older Meson compatibility + python3_header_check_args = ['/I' + python3_incdir] + else + python3_dep = python3_inst.dependency(embed: true, required: pyopt) + python3_header_check_args = [] + endif # Remove this check after we depend on Meson >= 1.1.0 - if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt, include_directories: postgres_inc) + if not cc.check_header('Python.h', args: python3_header_check_args, dependencies: python3_dep, required: pyopt, include_directories: postgres_inc) python3_dep = not_found_dep endif endif diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h index 118b310084..445f7bc31a 100644 --- a/src/pl/plpython/plpython.h +++ b/src/pl/plpython/plpython.h @@ -25,12 +25,8 @@ /* * Enable Python Limited API - * - * XXX currently not enabled on MSVC because of build failures */ -#if !defined(_MSC_VER) #define Py_LIMITED_API 0x03020000 -#endif /* * Pull in Python headers via a wrapper header, to control the scope of -- 2.52.0.windows.1
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: pgsql: Enable Python Limited API for PL/Python on MSVC
  2026-01-14 09:53 pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
  2026-01-15 09:36 ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
  2026-01-15 16:21   ` Re: pgsql: Enable Python Limited API for PL/Python on MSVC Bryan Green <dbryan.green@gmail.com>
@ 2026-01-17 05:26     ` Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Eisentraut @ 2026-01-17 05:26 UTC (permalink / raw)
  To: Bryan Green <dbryan.green@gmail.com>; pgsql-committers@lists.postgresql.org, Andrew Dunstan <andrew@dunslane.net>

On 15.01.26 17:21, Bryan Green wrote:
> On 1/15/2026 3:36 AM, Peter Eisentraut wrote:
>> This is failing on buildfarm member drongo: <https://
>> buildfarm.postgresql.org/cgi-bin/show_history.pl?nm=drongo&br=master>.
>>   AFAICT, this is the only buildfarm member that tests Python on Windows,
>> so we have no additional results to compare with.  It did pass on Cirrus
>> CI.  Andrew/Bryan, could you figure out how the Python installation on
>> drongo is different?
>>
> 
> Peter, Andrew,
> 
> The failure on drongo is due to my writing this patch to support meson
> versions >= 1.1.0.  I setup my local environment to match CI and was
> using meson 1.10.0.  Before 1.1.0 you needed to pass the include
> directory to check_headers with arg:.  I have made the changes and
> tested python 3.11 w/meson 0.57.2 and 1.0.1.  I have also retested with
> python 3.14 and meson 1.10.0.  Everything passed.

Thanks, this has been committed and seems to have fixed the drongo failure.






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


end of thread, other threads:[~2026-01-17 05:26 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-01-14 09:53 pgsql: Enable Python Limited API for PL/Python on MSVC Peter Eisentraut <peter@eisentraut.org>
2026-01-15 09:36 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-15 16:21   ` Bryan Green <dbryan.green@gmail.com>
2026-01-17 05:26     ` Peter Eisentraut <peter@eisentraut.org>

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