nanobind: [BUG]: Internal compiler error with MSVC 2022 when building `nb_func.h`
Problem description
We have recently started building our library Basix on Windows using MSVC 2022 using GitHub Actions. We are using scikit-build-core to orchestrate the CMake build and we build nanobind statically. We use vcpkg to bring in LAPACK and BLAS.
After switching to nanobind 2.0.0 we are consistently triggering an internal compiler error when building nanobind statically. The error points to L42 in nb_func.cpp, but that line looks relatively innocent.
https://github.com/FEniCS/basix/actions/runs/9404421938/job/25903298628#step:5:763 https://github.com/wjakob/nanobind/blob/master/src/nb_func.cpp#L42
We don’t have Windows machines locally so we haven’t tried reproducing this locally. Your CI seems to be running green on MSVC 2022. Any ideas?
Reproducible example code
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 35 (15 by maintainers)
Commits related to this issue
- pin nanobind to 1.9.2 MSVC has some issues that need to be resolved for 2: https://github.com/wjakob/nanobind/issues/613 — committed to mnets/bliss_bind by arashbm 2 years ago
- Fix from https://github.com/wjakob/nanobind/issues/613#issuecomment-2239868209 — committed to jhale/nanobind by jhale 2 years ago
- temporary workaround for an internal compiler error in MSVC (fixes issue #613) — committed to wjakob/nanobind by wjakob 2 years ago
- nanobind: temporary workaround for an internal compiler error in MSVC. See https://github.com/wjakob/nanobind/issues/613. — committed to agarny/libopencor by agarny 2 years ago
- temporary workaround for an internal compiler error in MSVC (fixes issue #613) — committed to sideeffects/nanobind by wjakob 2 years ago
A fork of nanobind with the above patch applied to
v2.0.0is available at: https://github.com/jhale/nanobind/tree/jhale/msvc2022-workaroundI have applied the following patch, which resolves the Internal compiler error. I believe this patch will become unnecessary once the MSVC version is updated and applied to GitHub Actions in the future.
Hi. I also noticed this issue on my own project. I notice that if I add the
/permissive-to nanobind’s CMake I am also able to reproduce the issue locally on nanobind’s repo itself:Which result in the following error:
This with the latest version of Visual Studio 17.10.4 / MSVC 19.40.33812.0.
The good news is I’ve tried to update to the preview release of the next Visual Studio version (17.11.2+c078802d4), and the error goes away.
Config settings lets you do this,
pip install -Ccmake.define.CMAKE_GENERATOR_TOOLSET=ClangCL .Or if you are using cibuildwheel, that can set config-settings too. You can also use environment variables, such as:Now you can set
CMAKE_GENERATOR_TOOLSETas an environment variable, and it will get passed in as a define.(If you check the link above, apparently it has been fixed internally, but isn’t in a released version yet, as of 17.10.2)
I’ve merged a temporary fix for this issue but plan to remove it once GHA is functional again.
@melpon @jhale I’m wondering if it makes sense to temporarily merge this patch into the master branch. Does GHA still serve the broken version of MSVC?
@jhale I found out that
windows-2019image can be used instead ofwindows-latestas a temporary solution to compile nanobind.https://developercommunity.visualstudio.com/t/Internal-compiler-error-w-nanobind-v19/10662883?sort=newest
@jhale The issue has been reported and fixed, but they haven’t released the patch.
The bug is introduced in MSVC 19.40.xxxxx