Skip to content

Passing through project-specific config options #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rgommers opened this issue May 16, 2022 · 11 comments · Fixed by #167
Closed

Passing through project-specific config options #54

rgommers opened this issue May 16, 2022 · 11 comments · Fixed by #167
Labels
enhancement New feature or request

Comments

@rgommers
Copy link
Contributor

The docs currently mention one option: https://meson-python.readthedocs.io/en/latest/usage/build-options.html. This is a meson-python build option. I am trying to figure out if/how it is possible to pass project-specific options through. For example, in SciPy we have a meson_options.txt file containing:

option('blas', type: 'string', value: 'openblas',
        description: 'option for BLAS library switching')
option('lapack', type: 'string', value: 'openblas',
        description: 'option for LAPACK library switching')

I don't think it is currently possible to use those with either build or pip? Something like:

$ python -m build "-C--Dblas=mkl --Dlapack=lapack"

Note that the build docs are a bit fuzzy on -C-- for config settings, or how to pass on multiple settings.

Is this possible at all, or is it planned for the future?

@FFY00
Copy link
Member

FFY00 commented May 16, 2022

Yes, I am working on it, but that will play with the default Meson options in the config file and I am struggling to decide on the design.

Passing multiple backend config options in pypa/build works just like in Meson with -D, it ends up looking a bit weird but there isn´t much we can do about that.

$ python -m build -C-Dblas=mkl -C-Dlapack=lapack

@rgommers
Copy link
Contributor Author

Cool, good to know. This one is not urgent, it's more a nice-to-have for SciPy 1.9.0 I'd say.

@andyfaff
Copy link

andyfaff commented Aug 2, 2022

I'm currently trying to setup cibuildwheel infrastructure for scipy.
The scipy pyproject.toml specifies the use of mesonpy as the build backend (ultimately using meson/ninja underneath). cibuildwheel just asks pip or build to make the wheel.

However, in order to target cp3*-macosx_arm64 cross compilation has to be used, because there is an arm64 host on an x86_64 build machine (Github Actions). This requires the use of a cross-compile file. I can find documentation on how to supply this file directly to a meson build (I think it gets placed in the build directory). However, there doesn't seem to be a way of supplying the cross-compile file as options to a pip/build.

e.g. I can't do:

python -m build . <my_cross_compile_build_flags_to_be_supplied_to_meson>

Will this PR enable this?

@rgommers
Copy link
Contributor Author

rgommers commented Aug 2, 2022

@andyfaff I believe it should, with python -m build . -C--cross-file=/absolute/path/to/cross-file.ini. That should pass it to meson setup just fine. There may be one hiccup to work out though (I'm very much not sure without testing): since meson-python itself uses a native-file.ini, that may conflict. If so, meson-python should probably detect if a cross-file option is present, and leave out its own native-file.

@eli-schwartz
Copy link
Member

Meson can use both native and cross files at the same time, although it's not especially useful unless the project in question actually has some components tagged as native-only. It's sometimes useful, though, to have e.g. code generator programs that are built for the build machine, not the cross-compile target. Meson therefore allows you to look up native dependencies/programs too, use the native file to configure it, etc.

@andyfaff
Copy link

One thing I forgot to ask, is it possible to provide flags to the build process via an environment variable? Taking the above example is it possible to do something along the lines of:

export MESON_OPTIONS="--cross-file=/absolute/path/to/cross-file.ini"
python -m build .

@rgommers
Copy link
Contributor Author

No, that is not possible, it's a conscious design choice: https://mesonbuild.com/Contributing.html#environment-variables. There are exceptions, like CC, CFLAGS, LDFLAGS, etc. - but not many.

@eli-schwartz
Copy link
Member

If this PEP 517 backend wanted to, it could read the environment variable and pass it to Meson.

Although that would mean it diverges from Meson's conscious design choice...

@rgommers
Copy link
Contributor Author

I'd much prefer to stay with the Meson philosophy. gh-122 should already solve this problem.

@doronbehar
Copy link
Contributor

@andyfaff I believe it should, with python -m build . -C--cross-file=/absolute/path/to/cross-file.ini. That should pass it to meson setup just fine.

I too need to add a --cross-file flag to meson for cross compiling scipy but there is no build module there.. What am I missing? I'm using NixOS and our build scripts use by default:

python -m pip wheel --verbose --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist .

Alternatively, how to add --cross-file if I want to use pip build?

@andyfaff
Copy link

Try and follow https://github.com/scipy/scipy/blob/acd1a4ad9e8d41d4956baf5fac38a8c779debcda/.github/workflows/wheels.yml#L159, that'll give the clearest example of how to do a cross compilr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
5 participants