Required prerequisites
What version (or hash if on master) of pybind11 are you using?
3.0.4
Problem description
I'm working on a project using pybind11 and CMake for pyodide/webassembly. With newer versions of CMake (>=4.1.0) and pybind11 (>=3.0.2) the cross-compilation gives an error. Using either older CMake (<4.1.0) and newer pybind (>=3.0.2) or new CMake and old pybind gives successful compilation.
I think this is caused by PR #5829 which only sets the internal variable _PYBIND11_CROSSCOMPILING if the CMAKE_CROSSCOMPILING_EMULATOR is not defined (code) - however, policy CMP0190 introduced by CMake 4.1 actually requires this to be defined and set to the program used to execute the cross-compiler. As such when running CMake with the emscripten cross-compiler, CMAKE_CROSSCOMPILING_EMULATOR is always defined which means the check fails and _PYBIND11_CROSSCOMPILING is always set to OFF and the compile then fails when the pointer size does not match (webassembly is 32-bit, the host system is 64-bit.
This can be reproduced with the cmake_example project with some modifications in a fork:
git clone --recurse-submodule https://github.com/mducle/cmake_example
cd cmake_example/pybind11
git checkout v3.0.4
cd ..
python -m pip install cibuildwheel cmake
CIBW_BUILD="cp312*" python -m cibuildwheel --platform pyodide
This will give an error Cannot run the interpreter but this is spurious - it's because the cross-compiling flag is not set correctly.
Now, I can get the compilation to work by:
- Changing cmake version to
4.0.0 or earlier in the pip install
- Changing pybind version to
3.0.1 or earlier in the checkout
- Keep both versions up-to-date and editing
tools/pybind11Common.cmake to remove the NOT in line 55
Reproducible example code
Is this a regression? Put the last known working version here if it is.
3.0.1
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
3.0.4
Problem description
I'm working on a project using pybind11 and CMake for pyodide/webassembly. With newer versions of CMake (
>=4.1.0) and pybind11 (>=3.0.2) the cross-compilation gives an error. Using either older CMake (<4.1.0) and newer pybind (>=3.0.2) or new CMake and old pybind gives successful compilation.I think this is caused by PR #5829 which only sets the internal variable
_PYBIND11_CROSSCOMPILINGif theCMAKE_CROSSCOMPILING_EMULATORis not defined (code) - however, policy CMP0190 introduced by CMake4.1actually requires this to be defined and set to the program used to execute the cross-compiler. As such when running CMake with the emscripten cross-compiler,CMAKE_CROSSCOMPILING_EMULATORis always defined which means the check fails and_PYBIND11_CROSSCOMPILINGis always set toOFFand the compile then fails when the pointer size does not match (webassembly is 32-bit, the host system is 64-bit.This can be reproduced with the cmake_example project with some modifications in a fork:
This will give an error
Cannot run the interpreterbut this is spurious - it's because the cross-compiling flag is not set correctly.Now, I can get the compilation to work by:
4.0.0or earlier in the pip install3.0.1or earlier in the checkouttools/pybind11Common.cmaketo remove theNOTin line 55Reproducible example code
Is this a regression? Put the last known working version here if it is.
3.0.1