diff --git a/doc/computing/parallelism.rst b/doc/computing/parallelism.rst index 97e3e2866083f..b7add493a88b1 100644 --- a/doc/computing/parallelism.rst +++ b/doc/computing/parallelism.rst @@ -299,6 +299,13 @@ When this environment variable is set to a non zero value, the `Cython` derivative, `boundscheck` is set to `True`. This is useful for finding segfaults. +`SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When this environment variable is set to a non zero value, the debug symbols +will be included in the compiled C extensions. Only debug symbols for POSIX +systems is configured. + `SKLEARN_PAIRWISE_DIST_CHUNK_SIZE` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/setup.py b/setup.py index 13f44982dcfe1..aa1b328e41103 100755 --- a/setup.py +++ b/setup.py @@ -509,6 +509,16 @@ def configure_extension_modules(): default_extra_compile_args = [f"/{optimization_level}"] default_libraries = [] + build_with_debug_symbols = ( + os.environ.get("SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS", "0") != "0" + ) + if os.name == "posix": + if build_with_debug_symbols: + default_extra_compile_args.append("-g") + else: + # Setting -g0 will strip symbols, reducing the binary size of extensions + default_extra_compile_args.append("-g0") + cython_exts = [] for submodule, extensions in extension_config.items(): submodule_parts = submodule.split(".")