From 2b4145f0258f674f966d043b2cb23e0d54b1c7c7 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 21 Dec 2022 15:11:43 +0200 Subject: [PATCH] Turn off debug information in C extension Previously, pydantic used the default Python CFLAGS which include `-g` (debug level 2). This is good for debugging at the C level, but it significantly increases the size of the C extension shared library, and is probably not needed by the vast majority of pydantic users. Thus, it seems a better tradeoff to turn debug info off. This can be overridden when building pydantic from source (not from PyPI wheel) by using `CFLAGS='-O3 -g'`. This change reduces the pydantic binary on cp310-linux-x86_64 from 31MB (12MB wheel) to 8.9MB (3MB wheel). Fixes #2276 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d677cd7765..dc44f33043 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ def extra(self): compiler_directives['linetrace'] = True # Set CFLAG to all optimizations (-O3) # Any additional CFLAGS will be appended. Only the last optimization flag will have effect - os.environ['CFLAGS'] = '-O3 ' + os.environ.get('CFLAGS', '') + os.environ['CFLAGS'] = '-O3 -g0' + os.environ.get('CFLAGS', '') ext_modules = cythonize( 'pydantic/*.py', exclude=['pydantic/generics.py'],