From 4f62f3a6837a59422d4976e1d9e947b5c0588f0c Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 15:13:39 -0500 Subject: [PATCH 1/7] BLD Strip symbols --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13f44982dcfe1..1929c3e4db673 100755 --- a/setup.py +++ b/setup.py @@ -503,7 +503,7 @@ def configure_extension_modules(): optimization_level = "O2" if os.name == "posix": - default_extra_compile_args = [f"-{optimization_level}"] + default_extra_compile_args = [f"-{optimization_level}", "-g0"] default_libraries = ["m"] else: default_extra_compile_args = [f"/{optimization_level}"] From 173af77d0b6e94c0031df419ebce2521c7bcc22d Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 15:15:39 -0500 Subject: [PATCH 2/7] CI [cd build] From 4aaa016642b2510344717b8fc6a869376960d81f Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 18:04:34 -0500 Subject: [PATCH 3/7] ENH Allow --debug to enable symbols [cd build gh] --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1929c3e4db673..a6d78ddcad948 100755 --- a/setup.py +++ b/setup.py @@ -195,6 +195,12 @@ def build_extensions(self): e.extra_compile_args += openmp_flag e.extra_link_args += openmp_flag + # To build with debug symbols + # python setup.py build_ext -i --debug + if not self.debug and os.name == "posix": + for e in self.extensions: + e.extra_compile_args += ["-g0"] + build_ext.build_extensions(self) def run(self): @@ -503,7 +509,7 @@ def configure_extension_modules(): optimization_level = "O2" if os.name == "posix": - default_extra_compile_args = [f"-{optimization_level}", "-g0"] + default_extra_compile_args = [f"-{optimization_level}"] default_libraries = ["m"] else: default_extra_compile_args = [f"/{optimization_level}"] From 66b5507860671f620893ba111956e2e7df81ca61 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 18:04:54 -0500 Subject: [PATCH 4/7] DOC Minor rewording [cd build gh] --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a6d78ddcad948..0713ea3f49e31 100755 --- a/setup.py +++ b/setup.py @@ -195,7 +195,7 @@ def build_extensions(self): e.extra_compile_args += openmp_flag e.extra_link_args += openmp_flag - # To build with debug symbols + # To build with debug symbols run: # python setup.py build_ext -i --debug if not self.debug and os.name == "posix": for e in self.extensions: From 0b9a92a5389a97455cde61ed3d88931f3187b6a1 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 18:39:26 -0500 Subject: [PATCH 5/7] DOC Add more details [cd build gh] --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 0713ea3f49e31..aef59a873c18c 100755 --- a/setup.py +++ b/setup.py @@ -198,6 +198,7 @@ def build_extensions(self): # To build with debug symbols run: # python setup.py build_ext -i --debug if not self.debug and os.name == "posix": + # Setting -g0 will strip symbols, reducing the binary size of extensions for e in self.extensions: e.extra_compile_args += ["-g0"] From 49b94657fc71b85cff0551b8494e59f3ac03fe23 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Tue, 6 Dec 2022 19:29:53 -0500 Subject: [PATCH 6/7] ENH Adds SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS [cd build gh] --- doc/computing/parallelism.rst | 7 +++++++ setup.py | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) 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 aef59a873c18c..5fbd6ebf8827e 100755 --- a/setup.py +++ b/setup.py @@ -195,12 +195,18 @@ def build_extensions(self): e.extra_compile_args += openmp_flag e.extra_link_args += openmp_flag - # To build with debug symbols run: - # python setup.py build_ext -i --debug - if not self.debug and os.name == "posix": - # Setting -g0 will strip symbols, reducing the binary size of extensions + build_with_debug_symbols = ( + os.environ.get("SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS", "0") != "0" + ) + if os.name == "posix": + if build_with_debug_symbols: + debug_compile_arg = ["-g"] + else: + # Setting -g0 will strip symbols, reducing the binary size of extensions + debug_compile_arg = ["-g0"] + for e in self.extensions: - e.extra_compile_args += ["-g0"] + e.extra_compile_args += debug_compile_arg build_ext.build_extensions(self) From ff2dc705b03109c7ae36326d0b519c41b316bf00 Mon Sep 17 00:00:00 2001 From: "Thomas J. Fan" Date: Wed, 7 Dec 2022 06:52:49 -0500 Subject: [PATCH 7/7] CLN Move closer to other flags [cd build gh] --- setup.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 5fbd6ebf8827e..aa1b328e41103 100755 --- a/setup.py +++ b/setup.py @@ -195,19 +195,6 @@ def build_extensions(self): e.extra_compile_args += openmp_flag e.extra_link_args += openmp_flag - build_with_debug_symbols = ( - os.environ.get("SKLEARN_BUILD_ENABLE_DEBUG_SYMBOLS", "0") != "0" - ) - if os.name == "posix": - if build_with_debug_symbols: - debug_compile_arg = ["-g"] - else: - # Setting -g0 will strip symbols, reducing the binary size of extensions - debug_compile_arg = ["-g0"] - - for e in self.extensions: - e.extra_compile_args += debug_compile_arg - build_ext.build_extensions(self) def run(self): @@ -522,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(".")