Skip to content

Commit a51d89f

Browse files
authored
[ESI][Runtime] Add Debug DLLs to wheels for Windows (#9687)
Windows applications in Debug mode crash when linking against the ESI Runtime wheel due to runtime library mismatches. Only Release DLLs were being packaged. Solution is to build and package both Release and Debug configurations of all C++ libraries and tools on Windows in a single wheel.
1 parent be8c245 commit a51d89f

File tree

5 files changed

+233
-95
lines changed

5 files changed

+233
-95
lines changed

lib/Dialect/ESI/runtime/CMakeLists.txt

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ else()
171171
endif()
172172
add_library(esiaccel::ESICppRuntime ALIAS ESICppRuntime)
173173

174+
# Set debug postfix for Windows libraries
175+
if(WIN32)
176+
set_target_properties(ESICppRuntime PROPERTIES DEBUG_POSTFIX "_d")
177+
endif()
178+
174179
target_include_directories(ESICppRuntime PUBLIC
175180
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include
176181
)
@@ -210,6 +215,15 @@ install(TARGETS ESICppRuntime
210215
COMPONENT ESIRuntime
211216
)
212217

218+
# Install PDB files for Windows Debug builds
219+
if(WIN32 AND MSVC)
220+
install(FILES $<TARGET_PDB_FILE:ESICppRuntime>
221+
DESTINATION ${ESIRT_INSTALL_LIBDIR}
222+
COMPONENT ESIRuntime
223+
OPTIONAL
224+
)
225+
endif()
226+
213227
install(FILES ${ESICppRuntimeHeaders}
214228
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/esi
215229
COMPONENT ESIRuntime
@@ -241,6 +255,10 @@ set(ESIRuntimePath "${CMAKE_CURRENT_BINARY_DIR}"
241255
add_executable(esiquery
242256
${CMAKE_CURRENT_SOURCE_DIR}/cpp/tools/esiquery.cpp
243257
)
258+
# Set debug postfix for Windows executables
259+
if(WIN32)
260+
set_target_properties(esiquery PROPERTIES DEBUG_POSTFIX "_d")
261+
endif()
244262
target_link_libraries(esiquery PRIVATE
245263
ESICppRuntime
246264
CLI11::CLI11
@@ -251,20 +269,40 @@ install(TARGETS esiquery
251269
DESTINATION ${ESIRT_INSTALL_BINDIR}
252270
COMPONENT ESIRuntime
253271
)
272+
# Install PDB files for Windows Debug builds
273+
if(WIN32 AND MSVC)
274+
install(FILES $<TARGET_PDB_FILE:esiquery>
275+
DESTINATION ${ESIRT_INSTALL_BINDIR}
276+
COMPONENT ESIRuntime
277+
OPTIONAL
278+
)
279+
endif()
254280

255281
##===----------------------------------------------------------------------===//
256282
## The esitester tool is both an example and test driver. As it is not intended
257-
## for production use, it is not installed.
283+
## for production use, it is not installed or included in wheels.
258284
##===----------------------------------------------------------------------===//
259285

260286
add_executable(esitester
261287
${CMAKE_CURRENT_SOURCE_DIR}/cpp/tools/esitester.cpp
262288
)
289+
# Set debug postfix for Windows executables
290+
if(WIN32)
291+
set_target_properties(esitester PROPERTIES DEBUG_POSTFIX "_d")
292+
endif()
263293
target_link_libraries(esitester PRIVATE
264294
ESICppRuntime
265295
CLI11::CLI11
266296
)
267-
add_dependencies(ESIRuntime esitester)
297+
# Install PDB files for Windows Debug builds
298+
if(WIN32 AND MSVC)
299+
install(FILES $<TARGET_PDB_FILE:esitester>
300+
DESTINATION ${ESIRT_INSTALL_BINDIR}
301+
COMPONENT ESIRuntime
302+
OPTIONAL
303+
)
304+
endif()
305+
268306

269307
# Add the Python bindings.
270308
add_subdirectory(python)
@@ -301,6 +339,11 @@ if(ESI_COSIM)
301339
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/RpcServer.h
302340
)
303341

342+
# Set debug postfix for Windows libraries
343+
if(WIN32)
344+
set_target_properties(CosimRpc PROPERTIES DEBUG_POSTFIX "_d")
345+
endif()
346+
304347
target_link_libraries(CosimRpc PUBLIC
305348
ESICppRuntime
306349
protobuf::libprotobuf
@@ -327,6 +370,11 @@ if(ESI_COSIM)
327370
${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/esi/backends/Cosim.h
328371
)
329372

373+
# Set debug postfix for Windows libraries
374+
if(WIN32)
375+
set_target_properties(CosimBackend PROPERTIES DEBUG_POSTFIX "_d")
376+
endif()
377+
330378
target_link_libraries(CosimBackend PUBLIC
331379
ESICppRuntime
332380
CosimRpc
@@ -345,6 +393,19 @@ if(ESI_COSIM)
345393
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
346394
COMPONENT ESIRuntime
347395
)
396+
# Install PDB files for Windows Debug builds
397+
if(MSVC)
398+
install(FILES $<TARGET_PDB_FILE:CosimRpc>
399+
DESTINATION ${ESIRT_INSTALL_LIBDIR}
400+
COMPONENT ESIRuntime
401+
OPTIONAL
402+
)
403+
install(FILES $<TARGET_PDB_FILE:CosimBackend>
404+
DESTINATION ${ESIRT_INSTALL_LIBDIR}
405+
COMPONENT ESIRuntime
406+
OPTIONAL
407+
)
408+
endif()
348409
else()
349410
install(TARGETS CosimRpc CosimBackend
350411
DESTINATION ${ESIRT_INSTALL_LIBDIR}

lib/Dialect/ESI/runtime/cpp/cmake/esiaccelConfig.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ set_target_properties(esiaccel::ESICppRuntime PROPERTIES
44
)
55

66
if(WIN32)
7+
# Default to Release variant for single-config generators and as fallback.
8+
# Multi-config generators (Visual Studio, Xcode) use the per-config
9+
# IMPORTED_LOCATION_<CONFIG> properties set below.
710
set_target_properties(esiaccel::ESICppRuntime PROPERTIES
811
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime.dll"
912
IMPORTED_IMPLIB "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime.lib"
1013
)
14+
set_target_properties(esiaccel::ESICppRuntime PROPERTIES
15+
IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime.dll"
16+
IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime.lib"
17+
IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime_d.dll"
18+
IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../ESICppRuntime_d.lib"
19+
)
1120
else()
1221
set_target_properties(esiaccel::ESICppRuntime PROPERTIES
1322
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../@ESIRT_INSTALL_LIBDIR@/libESICppRuntime.so"
@@ -25,6 +34,12 @@ if(WIN32)
2534
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc.dll"
2635
IMPORTED_IMPLIB "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc.lib"
2736
)
37+
set_target_properties(esiaccel::CosimRpc PROPERTIES
38+
IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc.dll"
39+
IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc.lib"
40+
IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc_d.dll"
41+
IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../CosimRpc_d.lib"
42+
)
2843
else()
2944
set_target_properties(esiaccel::CosimRpc PROPERTIES
3045
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../@ESIRT_INSTALL_LIBDIR@/libCosimRpc.so"
@@ -42,6 +57,12 @@ if(WIN32)
4257
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend.dll"
4358
IMPORTED_IMPLIB "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend.lib"
4459
)
60+
set_target_properties(esiaccel::CosimBackend PROPERTIES
61+
IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend.dll"
62+
IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend.lib"
63+
IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend_d.dll"
64+
IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../CosimBackend_d.lib"
65+
)
4566
else()
4667
set_target_properties(esiaccel::CosimBackend PROPERTIES
4768
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/../@ESIRT_INSTALL_LIBDIR@/libCosimBackend.so"

lib/Dialect/ESI/runtime/cpp/lib/Accelerator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,15 @@ static void loadBackend(Context &ctxt, std::string backend) {
194194
#ifdef __linux__
195195
std::string backendFileName = "lib" + backend + "Backend.so";
196196
#elif _WIN32
197+
// In MSVC debug builds, load the debug variant of the plugin DLL (e.g.
198+
// CosimBackend_d.dll) to ensure compatibility.
199+
#if defined(_MSC_VER) && defined(_DEBUG)
200+
std::string backendFileName = backend + "Backend_d.dll";
201+
#else
197202
std::string backendFileName = backend + "Backend.dll";
203+
#endif
198204
#else
199-
#eror "Unsupported platform"
205+
#error "Unsupported platform"
200206
#endif
201207

202208
// First, try the current directory.

lib/Dialect/ESI/runtime/python/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(Python3_FOUND)
4848
if (WHEEL_BUILD)
4949
message (FATAL_ERROR "nanobind is required for a wheel build.")
5050
endif()
51+
elseif(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
52+
# On MSVC in Debug mode, nanobind's CRT mismatch causes linking issues
53+
# with the Python import library. Disable the Python module entirely.
54+
message(WARNING "Disabling ESI Python API in MSVC Debug mode due to nanobind CRT incompatibility.")
5155
else()
5256
# Compile nanobind module and copy to the correct python directory.
5357
nanobind_add_module(esiCppAccel

0 commit comments

Comments
 (0)