diff --git a/meson.build b/meson.build index 66583095a6e77..ab3196fc44a7f 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,24 @@ endif cy = meson.get_compiler('cython') if cy.version().version_compare('>=3.1.0') add_project_arguments('-Xfreethreading_compatible=true', language: 'cython') + + # Use shared utility code to reduce wheel sizes + # copied from https://github.com/scikit-learn/scikit-learn/pull/31151/files + cy = find_program(cy.cmd_array()[0]) + cython_shared_src = custom_target( + install: false, + output: '_cyutility.c', + command: [ + cy, '-3', '--fast-fail', + '--generate-shared=' + meson.current_build_dir()/'_cyutility.c' + ], + ) + + py.extension_module('_cyutility', + cython_shared_src, + subdir: 'pandas/_libs', + install: true, + ) endif # Needed by pandas.test() when it looks for the pytest ini options diff --git a/pandas/_libs/meson.build b/pandas/_libs/meson.build index a50976767928a..33fc65e5034d0 100644 --- a/pandas/_libs/meson.build +++ b/pandas/_libs/meson.build @@ -148,6 +148,12 @@ if get_option('buildtype') == 'debug' cython_args += ['--gdb'] endif +# Use shared utility code to reduce wheel sizes +# copied from https://github.com/scikit-learn/scikit-learn/pull/31151/files +if cy.version().version_compare('>=3.1.0') + cython_args += ['--shared=pandas._libs._cyutility'] +endif + foreach ext_name, ext_dict : libs_sources py.extension_module( ext_name, diff --git a/pandas/_libs/tslibs/meson.build b/pandas/_libs/tslibs/meson.build index 052a8568b76af..ac43dc7db5fb7 100644 --- a/pandas/_libs/tslibs/meson.build +++ b/pandas/_libs/tslibs/meson.build @@ -28,6 +28,12 @@ if get_option('buildtype') == 'debug' cython_args += ['--gdb'] endif +# Use shared utility code to reduce wheel sizes +# copied from https://github.com/scikit-learn/scikit-learn/pull/31151/files +if cy.version().version_compare('>=3.1.0') + cython_args += ['--shared=pandas._libs._cyutility'] +endif + foreach ext_name, ext_dict : tslibs_sources py.extension_module( ext_name, diff --git a/pandas/_libs/window/meson.build b/pandas/_libs/window/meson.build index 1d49bba47e139..78169e781bc47 100644 --- a/pandas/_libs/window/meson.build +++ b/pandas/_libs/window/meson.build @@ -1,7 +1,7 @@ py.extension_module( 'aggregations', ['aggregations.pyx'], - cython_args: ['-X always_allow_keywords=true'], + cython_args: ['-X always_allow_keywords=true', '--shared=pandas._libs._cyutility'], include_directories: [inc_np, inc_pd], subdir: 'pandas/_libs/window', override_options: ['cython_language=cpp'], @@ -11,7 +11,7 @@ py.extension_module( py.extension_module( 'indexers', ['indexers.pyx'], - cython_args: ['-X always_allow_keywords=true'], + cython_args: ['-X always_allow_keywords=true', '--shared=pandas._libs._cyutility'], include_directories: [inc_np, inc_pd], subdir: 'pandas/_libs/window', install: true, diff --git a/pyproject.toml b/pyproject.toml index 3f7b6a672e1b0..a2b51aca0178b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = [ "meson-python>=0.13.1", "meson>=1.2.1,<2", "wheel", - "Cython~=3.0.5", # Note: sync with setup.py, environment.yml and asv.conf.json + "Cython==3.1.0rc1", # Note: sync with setup.py, environment.yml and asv.conf.json # Force numpy higher than 2.0rc1, so that built wheels are compatible # with both numpy 1 and 2 "numpy>=2.0.0rc1",