On Wed, May 15, 2024 at 10:56 PM Robert McLeod <robbmcl...@gmail.com> wrote:
> Hi everyone, > > Is there a gist or similar guide anywhere on the steps required to build > NumPy with debugging symbols on the Windows platform using the new Meson > build system? It seems a bit difficult because NumPy seems to expect a > `conda`-like file structure whereas if you are cloning `cpython` directly > it is different. In particular `cpython` puts all the Windows files under > the `PC` and `PCBuild` subdirectories. Also meson doesn't seem to have a > means to call `python_d.exe` directly which may be causing problems. I've > ended up building both `python.exe` and `python_d.exe` but run into some > problem finding Python in `meson.build`. > I can think of two ways to point Meson at a custom `python_d.exe` Python executable: using pkg-config, and using a machine file ( https://mesonbuild.com/Machine-files.html#cross-and-native-file-reference). meson-python uses the latter approach; you create a file `native-file.ini` with contents: ``` [binaries] python = 'C:/path/to/python_d.exe' # (not sure about \ vs. / here) ``` You can install pkg-config with Chocolatey for example. The Windows build should produce a .pc file that you can point pkg-config to by setting PKG_CONFIG_PATH. See how we use it in CI here: https://github.com/numpy/numpy/blob/main/.github/workflows/windows.yml#L44 I'd try the machine file approach first, I'd expect it to be enough. Not sure though, I don't think I've seen anyone try with a Windows debug build. > This describes my efforts to date: > > # Build CPython with Debugging Symbols on Windows > > ```shell > git clone https://github.com/python/cpython.git > cd cpython > git switch 3.11 > PCbuild\get_externals.bat > # Build the debug version `python_d.exe` > PCbuild\build.bat -e -d > # Meson calls `python.exe` and doesn't seem to have an argument to change > this. > # We could either build it, or create a symlink > PCbuild\build.bat > # ln -s PCbuild/amd64/python_d.exe PCbuild/amd64/python.exe > ``` > > The built Python will then be located in > `<prefix>/cpython/PCBuild/amd64/python_d.exe`. > > ```batch > set PREFIX=C:/Users/Robert/dev/cpython > set PATH=%PREFIX%;%PREFIX%/PCBuild/amd64;%PREFIX%/Scripts;%PATH% > ``` > > Next we have to install pip: > https://docs.python.org/3/library/ensurepip.html, > meson, and cython. > > ```shell > python_d -m ensurepip > python_d -mpip install meson meson-python ninja cython > ``` > > NOTE: produces `pip3.exe`, not `pip`. > > # Build NumPy with debug Python > > ```shell > git clone https://github.com/numpy/numpy.git > cd numpy > git switch maintenance/1.26.x > git submodule update --init > ``` > > https://mesonbuild.com/meson-python/how-to-guides/debug-builds.html > > Next try and build with meson/ninja: > > ```shell > mkdir build-dbg > cd build-dbg > meson .. setup --buildtype=debug > --includedir=C:/Users/Robert/dev/cpython/PC > --libdir=C:/Users/Robert/dev/cpython/PCbuild/amd64 > ninja > ninja install > ``` > Note that once you get past the "find python_d.exe" hurdle, you will need to change the `meson` invocation from plain `meson xxx` to `python.exe ./vendored-meson/meson/meson.py xxx`, because our custom extensions in https://github.com/numpy/numpy/tree/main/vendored-meson are needed for BLAS and SIMD code. Cheers, Ralf > `meson .. setup <...>` fails and complains that, > > ''' > Run-time dependency python found: NO (tried sysconfig) > > ..\meson.build:41:12: ERROR: Python dependency not found > ''' > > which corresponds to: > > ```meson.build > py = import('python').find_installation(pure: false) > py_dep = py.dependency() > ``` > > I tried also editing `pyproject.toml` to add the section: > > ```toml > [tool.meson-python.args] > setup = ['-Dbuildtype=debug', > '-Dincludedir=C:/Users/Robert/dev/cpython/PC', > '-Dlibdir=C:/Users/Robert/dev/cpython/PCbuild/amd64'] > ``` > > and then build NumPy with pip using the debug python build: > > ```shell > python_d -mpip install . --no-build-isolation -Cbuild-dir=build-dbg > ``` > > But it fails in the same fashion. Searching for issues I find this one but > it's likely in this case something related to the debug Python build is the > problem. > > https://github.com/mesonbuild/meson/issues/12547 > > Meson installed version is 1.4.0. Any advice would be appreciated. I'm > happy to write a gist if I can get it working. > > -- > Robert McLeod > robbmcl...@gmail.com > robert.mcl...@hitachi-hightech.com > > _______________________________________________ > NumPy-Discussion mailing list -- numpy-discussion@python.org > To unsubscribe send an email to numpy-discussion-le...@python.org > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ > Member address: ralf.gomm...@googlemail.com >
_______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com