Skip to content

Commit de9ab1d

Browse files
jere8184heinezen
authored andcommitted
CI-CD:use debug config for CI
1 parent 7eca2be commit de9ab1d

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

.github/workflows/windows-server-2019.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
mkdir build
5252
cd build
5353
cmake -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release -DCMAKE_CXX_FLAGS='/Zc:__cplusplus /permissive- /EHsc' -DCMAKE_EXE_LINKER_FLAGS='' -DCMAKE_MODULE_LINKER_FLAGS='' -DCMAKE_SHARED_LINKER_FLAGS='' -DDOWNLOAD_NYAN=YES -DCXX_OPTIMIZATION_LEVEL=auto -DCXX_SANITIZE_FATAL=False -DCXX_SANITIZE_MODE=none -DWANT_BACKTRACE=if_available -DWANT_GPERFTOOLS_PROFILER=if_available -DWANT_GPERFTOOLS_TCMALLOC=False -DWANT_INOTIFY=if_available -DWANT_NCURSES=if_available -DWANT_OPENGL=if_available -DWANT_VULKAN=if_available -DFLEX_EXECUTABLE="$FLEX_PATH" -G "Visual Studio 16 2019" -A x64 ../source
54-
cmake --build . --config RelWithDebInfo -- -nologo -maxCpuCount
54+
cmake --build . --config Debug -- -nologo -maxCpuCount
5555
shell: pwsh
5656
- name: Package
5757
run: |

.github/workflows/windows-server-2022.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
mkdir build
5252
cd build
5353
cmake -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TRY_COMPILE_CONFIGURATION=Release -DCMAKE_CXX_FLAGS='/Zc:__cplusplus /permissive- /EHsc' -DCMAKE_EXE_LINKER_FLAGS='' -DCMAKE_MODULE_LINKER_FLAGS='' -DCMAKE_SHARED_LINKER_FLAGS='' -DDOWNLOAD_NYAN=YES -DCXX_OPTIMIZATION_LEVEL=auto -DCXX_SANITIZE_FATAL=False -DCXX_SANITIZE_MODE=none -DWANT_BACKTRACE=if_available -DWANT_GPERFTOOLS_PROFILER=if_available -DWANT_GPERFTOOLS_TCMALLOC=False -DWANT_INOTIFY=if_available -DWANT_NCURSES=if_available -DWANT_OPENGL=if_available -DWANT_VULKAN=if_available -DFLEX_EXECUTABLE="$FLEX_PATH" -G "Visual Studio 17 2022" -A x64 ../source
54-
cmake --build . --config RelWithDebInfo -- -nologo -maxCpuCount
54+
cmake --build . --config Debug -- -nologo -maxCpuCount
5555
shell: pwsh
5656
- name: Package
5757
run: |

buildsystem/HandlePythonOptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
4747
if (${_index} GREATER -1)
4848
MATH(EXPR _index "${_index}+1")
4949
list(GET PYEXT_LIBRARY ${_index} PYEXT_LIBRARY)
50+
set(force_optimized_lib_flag "--force_optimized_lib")
5051
endif()
5152
endif()
5253

buildsystem/cythonize.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,26 @@ def cythonize_wrapper(modules, force_optimized_lib = False, **kwargs):
8989
if src_modules:
9090
cythonize(src_modules, **kwargs)
9191
if sys.platform == 'win32' and force_optimized_lib:
92-
windows_use_optimized_lib_python(src_modules, bin_dir)
92+
win_use_optimized_lib_python(src_modules, bin_dir)
9393

9494
if bin_modules:
9595
os.chdir(bin_dir)
9696
cythonize(bin_modules, **kwargs)
9797
if sys.platform == 'win32' and force_optimized_lib:
98-
windows_use_optimized_lib_python(bin_modules, bin_dir)
98+
win_use_optimized_lib_python(bin_modules, bin_dir)
9999
os.chdir(src_dir)
100100

101101

102-
def windows_use_optimized_lib_python(modules, path):
102+
def win_use_optimized_lib_python(modules, path):
103103
"""
104104
Add an #ifdef statement in cythonized .cpp files to temporarily undefine _DEBUG before
105105
#include "Python.h"
106106
107107
This function modifies the generated C++ files from Cython to prevent linking to
108108
the debug version of the Python library on Windows. The debug version of the
109109
Python library cannot import Python libraries that contain extension modules.
110+
see: https://github.com/python/cpython/issues/127619 (To unserstand the problem)
111+
see: https://stackoverflow.com/a/59566420 (To understand the soloution)
110112
"""
111113

112114
for module in modules:
@@ -117,10 +119,24 @@ def windows_use_optimized_lib_python(modules, path):
117119
module = module + ".cpp"
118120
with open(module, "r", encoding='utf8') as file:
119121
text = file.read()
120-
text = text.replace("#include \"Python.h\"",
121-
"#ifdef _DEBUG\n#define _DEBUG_WAS_DEFINED\n#undef _DEBUG\n#endif\n\
122-
#include \"Python.h\"\n#ifdef _DEBUG_WAS_DEFINED\n#define _DEBUG\n\
123-
#undef _DEBUG_WAS_DEFINED\n#endif", 1)
122+
if not text.count("OPENAGE: UNDEF_DEBUG_INSERTED"):
123+
text = text.replace(
124+
'#include "Python.h"',
125+
(
126+
"\n\n// OPENAGE: UNDEF_DEBUG_INSERTED\n"
127+
"// Avoid linking to the debug version of the Python library on Windows\n\n"
128+
"#ifdef _DEBUG\n"
129+
"#define _DEBUG_WAS_DEFINED\n"
130+
"#undef _DEBUG\n#endif\n"
131+
"#include \"Python.h\"\n"
132+
"#ifdef _DEBUG_WAS_DEFINED\n"
133+
"#define _DEBUG\n"
134+
"#undef _DEBUG_WAS_DEFINED\n"
135+
"#endif\n\n"
136+
"// OPENAGE: UNDEF_DEBUG_INSERTED\n\n"
137+
),
138+
1
139+
)
124140
with open(module, "w", encoding='utf8') as file:
125141
file.write(text)
126142

buildsystem/python.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ function(python_finalize)
375375

376376

377377
# cythonize (.pyx -> .cpp)
378-
if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
379-
set(force_optimized_lib "--force_optimized_lib")
380-
endif()
381378

382379
get_property(cython_modules GLOBAL PROPERTY SFT_CYTHON_MODULES)
383380
write_on_change("${CMAKE_BINARY_DIR}/py/cython_modules" "${cython_modules}")
@@ -396,7 +393,7 @@ function(python_finalize)
396393
"${CMAKE_BINARY_DIR}/py/cython_modules"
397394
"${CMAKE_BINARY_DIR}/py/cython_modules_embed"
398395
"${CMAKE_BINARY_DIR}/py/pxd_list"
399-
${force_optimized_lib}
396+
${force_optimized_lib_flag}
400397
"--build-dir" "${CMAKE_BINARY_DIR}"
401398
COMMAND "${CMAKE_COMMAND}" -E touch "${CYTHONIZE_TIMEFILE}"
402399
DEPENDS

0 commit comments

Comments
 (0)