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`.

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
```

`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: arch...@mail-archive.com

Reply via email to