-
Notifications
You must be signed in to change notification settings - Fork 198
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
[BUG]: Internal compiler error with MSVC 2022 when building nb_func.h
#613
Comments
We have been getting the same internal compiler error pointing to L42 in |
That's quite mysterious since it doesn't seem to happen in the nanobind CI. Two requests:
|
Regarding your second point @wjakob We are using the 2.0.0 tag point release from wjacob/nanobind. We started noticing this error roughly from yesterday. I think it's safe to say that something upstream, either in the MSVC compiler or in the GitHub Windows Server runner image, has changed. Possibly related issue: actions/runner-images#10004 |
@wjakob, is it possible for you to trigger a |
To throw another datapoint into the mix: I maintain nanobind-bazel, a Bazel ruleset for Python bindings builds with nanobind, and my CI (which consists of building @wjakob 's nanobind_example across multiple Python versions with the respective installed C++ toolchain on every OS) is still entirely green on 20240603.1.0: https://github.com/nicholasjng/nanobind-bazel/actions/runs/9416682418/job/25940329652#step:1:9 EDIT: I should also say that this is built with nanobind v2.0.0. |
Tried on a fork https://github.com/jhale/nanobind, doesn't trigger the issue on either a slightly tweaked v2.0.0 or a current main. |
Could you tell us more about your project @miklhh ? |
@jhale The issue has been reported and fixed, but they haven't released the patch. The bug is introduced in MSVC 19.40.xxxxx |
@jhale I found out that |
Also see pypa/cibuildwheel#1875 for another. |
It's quite a strange bug. Since I could build my lib successfully on my win10 laptop with vs2022. But on github action, it just failed. I don't quite understand what's the difference. |
Do you have version 17.10 locally? That’s the buggy one that came to GHA a week or two ago. It’s breaking other things too, I’ve seen three unrelated packages broken so far. Older versions are fine. (edit: sorry, got the first number wrong, fixed it) |
I got Do you mean the newest |
Yes, got the first number wrong. The buggy one is 17.10. 17.9 is fine. |
(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) |
Download here old versions of msvc : |
I found a solution to make nanobind compile on the Although the bug is still not fixed in cmake_minimum_required(VERSION 3.20)
set(CMAKE_GENERATOR_TOOLSET "ClangCl") # newly added
project(symusic)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) And in the github actions' workflow, I add the following step to specify which CMakeLists to use: - name: Force ClangCL on Windows
if: ${{ matrix.buildplat[0] == 'windows-2022' }}
# remove the default CMakeLists.txt and replace it with CMakeLists-VS.txt
run: |
rm CMakeLists.txt
mv CMakeLists-VS.txt CMakeLists.txt I know this is not an elegant and general way, but this does make my github actions work. Now I can precompile the new version of my lib and upload them to pypi. |
If you wrap the # https://github.com/wjakob/nanobind/issues/613
#
# Visual Studio 17.10.4's MSVC compiler gives an ICE in nanobind's nb_func.h,
# but clang-cl does not.
if(WIN32)
set(CMAKE_GENERATOR_TOOLSET "ClangCl")
endif() clang-cl is compatible with MSVC's commandline, so flags in |
I got it. However, because CMakeLists are packaged with the source code and uploaded to pypi, this can cause the installation to fail when installing from source for users on Win who do not have an additional LLVM installation for Visual Studio. And I found that when using ninja, So if we write these settings to the same file, more |
I'd do things like this from the command line, |
I take it this is still not fixed? It was supposed to be in the latest images... |
Well, I'm using scikit build, and the only way I find (maybe there are other ways) to pass cmake arguments (out of CMakeLists.txt) is to put them in the [tool.scikit-build.cmake.define]
CMAKE_GENERATOR_TOOLSET="ClangCL" I also don't like hard code things like this, but I only find this work. So I choose to create a temporary file, and it will be removed once Microsoft fix that bug.
Yes, in the latest 17.10.4, the bug is still there, waiting to be fixed. |
Config settings lets you do this, [tool.scikit-build.cmake.define]
CMAKE_GENERATOR_TOOLSET = { env="CMAKE_GENERATOR_TOOLSET" } Now you can set |
Thanks for the tips on Unfortunately the main purpose of our Windows CI testing is to make sure that our packages are buildable within conga-forge, which uses |
Hi. I also noticed this issue on my own project. I notice that if I add the diff --git i/CMakeLists.txt w/CMakeLists.txt
index 82f9b28..7d9a03e 100644
--- i/CMakeLists.txt
+++ w/CMakeLists.txt
@@ -22,6 +22,8 @@ if (NOT MSVC)
option(NB_TEST_SANITZE "Build tests with address and undefined behavior sanitizers?" OFF)
endif()
+add_compile_options("/permissive-")
+
# ---------------------------------------------------------------------------
# Do a release build if nothing was specified
# --------------------------------------------------------------------------- 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. |
MSVC has some issues that need to be resolved for 2: wjakob/nanobind#613
I just tried to compile with VS 2022 and C++ 20, it gives internal compiler error in nb_func.h due to some template stuff around 'func_create' However, compiling with C++17 works without error |
I 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. diff --git a/include/nanobind/nb_func.h b/include/nanobind/nb_func.h
index e53e1a4..428ca81 100644
--- a/include/nanobind/nb_func.h
+++ b/include/nanobind/nb_func.h
@@ -199,14 +199,24 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),
PyObject *result;
if constexpr (std::is_void_v<Return>) {
+#if defined(_WIN32)
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...);
+#else
cap->func(in.template get<Is>().operator cast_t<Args>()...);
+#endif
result = Py_None;
Py_INCREF(result);
} else {
+#if defined(_WIN32)
+ result = cast_out::from_cpp(
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...),
+ policy, cleanup).ptr();
+#else
result = cast_out::from_cpp(
cap->func((in.template get<Is>())
.operator cast_t<Args>()...),
policy, cleanup).ptr();
+#endif
}
if constexpr (Info::keep_alive) |
A fork of nanobind with the above patch applied to |
Yea, MSVC from the current windows-2022 image still gives an ICE: https://github.com/calcmogul/Sleipnir/actions/runs/10070019011/job/27837879240
|
It's still broken in GHA. It's up to you on |
I've merged a temporary fix for this issue but plan to remove it once GHA is functional again. |
Currently the workaround causes compile errors for me (described in this discussion post), but when removing it and building nanobind myself, everything works. |
Could you clarify which version of nanobind you are working with? It's 'fixed' on |
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
The text was updated successfully, but these errors were encountered: