meson-python icon indicating copy to clipboard operation
meson-python copied to clipboard

Document that Meson and thus meson-python require MSVC compilers to be found in `$PATH`

Open dnicolodi opened this issue 2 years ago • 5 comments

setuptools has its magic to find the compilers but Meson does not thus this may come as a surprise especially to people like me that compiles on Windows only on CI jobs. Because many CI environments have images where the GCC compilers are available via MSYS2 or similar, Meson picks up those by default and things break in unexpected ways because the right command line arguments should be passed to these compilers to correctly build Python extensions.

One more related issue is that cibuildweels (I don't know how popular but definitely convenient way to build distributable wheels) most prominently way to build wheels in GitHub Actions is using a reusable action that does not play nicely with adding the MSVC compilers in $PATH. The solution is to use pipx run cibuildwheel directly. @henryiii can probably fill in the details.

All this should be documented somewhere.

dnicolodi avatar Nov 22 '22 11:11 dnicolodi

meson setup --vsenv will force Meson to run the vcvars*.bat script and acquire its information on finding MSVC before any other compiler. Without that option, Meson does indeed pick an msys2 compiler from $PATH.

eli-schwartz avatar Nov 22 '22 12:11 eli-schwartz

I've looked into updating the action to run the native pwsh backend on Windows. Unfortunately, it seems powershell doesn't like empty args, that is, --flag "" complains about flag not getting an argument. We use this for a couple of arguments, so that's where I'm stuck at the moment.

henryiii avatar Nov 22 '22 13:11 henryiii

Here's the run if you are curious: https://github.com/pybind/scikit_build_example/actions/runs/3519251284/jobs/5899006227

Run henryiii/cibuildwheel@henryiii/fix/action
with:
  package-dir: .
  output-dir: wheelhouse
env:
  CIBW_ARCHS_MACOS: auto universal2
Run actions/setup-python@v4
with:
  python-version: 3.7 - 3.11
  update-environment: false
  check-latest: false
  token: ***
env:
  CIBW_ARCHS_MACOS: auto universal2
Successfully set up CPython (3.11.0)
Run pipx run --python "C:\hostedtoolcache\windows\Python\3.11.0\x64\python.exe" --spec "D:\a\_actions\henryiii\cibuildwheel\henryiii/fix/action" cibuildwheel "." --output-dir "wheelhouse" --config-file "" --only ""
pipx run --python "C:\hostedtoolcache\windows\Python\3.11.0\x64\python.exe" --spec "D:\a\_actions\henryiii\cibuildwheel\henryiii/fix/action" cibuildwheel "." --output-dir "wheelhouse" --config-file "" --only ""
shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
env:
  CIBW_ARCHS_MACOS: auto universal2
creating virtual environment...
creating virtual environment...
determining package name from 'D:\\a\\_actions\\henryiii\\cibuildwheel\\henryiii\\fix\\action'...
installing cibuildwheel from spec 'D:\\a\\_actions\\henryiii\\cibuildwheel\\henryiii\\fix\\action'...
usage: cibuildwheel [-h] [--platform {auto,linux,macos,windows}]
                    [--archs ARCHS] [--only ONLY] [--output-dir OUTPUT_DIR]
                    [--config-file CONFIG_FILE] [--print-build-identifiers]
                    [--allow-empty] [--prerelease-pythons]
                    [PACKAGE]
cibuildwheel: error: argument --config-file: expected one argument

The run line looks correct:

pipx run --python "C:\hostedtoolcache\windows\Python\3.11.0\x64\python.exe" --spec "D:\a\_actions\henryiii\cibuildwheel\henryiii/fix/action" cibuildwheel "." --output-dir "wheelhouse" --config-file "" --only ""

But powershell seems to be muddling it somehow since argparse reports is has no argument for --config-file. We could technically fix that one (the default can be written in text, so could be put into the action), but --only really does need to be empty.

If there's some powershell trickery to avoid printing the option if the variable is empty, I'd be happy to hear it. :) Edit: Doubling quotes. Hmm, okay.

henryiii avatar Nov 22 '22 13:11 henryiii

Got it working, made https://github.com/pypa/cibuildwheel/pull/1346.

henryiii avatar Nov 22 '22 14:11 henryiii

meson setup --vsenv will force Meson to run the vcvars*.bat script and acquire its information on finding MSVC before any other compiler. Without that option, Meson does indeed pick an msys2 compiler from $PATH.

Isn't that bugging behavior, though? Here, https://github.com/mesonbuild/meson/blob/master/mesonbuild/compilers/detect.py#L56, it says that meson should prefer cl.exe before other compilers. It would be inconsistent for meson, to only prefer cl.exe if it was in the path?

Interestingly enough, if nothing is in the PATH, meson is somehow able to find MSVC.

lithomas1 avatar Nov 22 '22 20:11 lithomas1

This was documented in gh-371, so we should be good here.

rgommers avatar Apr 14 '23 16:04 rgommers