diff --git a/Misc/NEWS.d/next/Build/2021-04-29-11-04-02.bpo-43974.Ok5zIs.rst b/Misc/NEWS.d/next/Build/2021-04-29-11-04-02.bpo-43974.Ok5zIs.rst new file mode 100644 index 00000000000000..95533781d998a9 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2021-04-29-11-04-02.bpo-43974.Ok5zIs.rst @@ -0,0 +1,3 @@ +``setup.py`` now defines ``Py_BUILD_CORE_MODULE`` for all core modules +automatically. ``Modules/Setup`` no longer defines ``Py_BUILD_CORE_BUILTIN``. +The macro is automatically defined for builtins by ``Modules/makesetup``. diff --git a/Modules/Setup b/Modules/Setup index 87c6a152f86eac..2246500868badc 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -101,29 +101,29 @@ PYTHONPATH=$(COREPYTHONPATH) # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. -posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls +posix -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls errno errnomodule.c # posix (UNIX) errno values pwd pwdmodule.c # this is needed to find out the user's home dir # if $HOME is not set -_sre -DPy_BUILD_CORE_BUILTIN _sre.c # Fredrik Lundh's new regular expressions +_sre _sre.c # Fredrik Lundh's new regular expressions _codecs _codecsmodule.c # access to the builtin codecs and codec registry _weakref _weakref.c # weak references -_functools -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _functoolsmodule.c # Tools for working with functions and callable objects -_operator -DPy_BUILD_CORE_BUILTIN _operator.c # operator.add() and similar goodies +_functools -I$(srcdir)/Include/internal _functoolsmodule.c # Tools for working with functions and callable objects +_operator _operator.c # operator.add() and similar goodies _collections _collectionsmodule.c # Container types -_abc -DPy_BUILD_CORE_BUILTIN _abc.c # Abstract base classes +_abc _abc.c # Abstract base classes itertools itertoolsmodule.c # Functions creating iterators for efficient looping atexit atexitmodule.c # Register functions to be run at interpreter-shutdown -_signal -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal signalmodule.c +_signal -I$(srcdir)/Include/internal signalmodule.c _stat _stat.c # stat.h interface -time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c # -lm # time operations and variables -_thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c # low-level threading interface +time -I$(srcdir)/Include/internal timemodule.c # -lm # time operations and variables +_thread -I$(srcdir)/Include/internal _threadmodule.c # low-level threading interface # access to ISO C locale support -_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl +_locale _localemodule.c # -lintl # Standard I/O baseline -_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c +_io -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c # faulthandler module faulthandler faulthandler.c @@ -166,26 +166,26 @@ _symtable symtablemodule.c # Modules that should always be present (non UNIX dependent): -#array -DPy_BUILD_CORE_MODULE arraymodule.c # array objects -#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions -#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin() +array arraymodule.c # array objects +#cmath cmathmodule.c _math.c # -lm # complex math library functions +#math mathmodule.c _math.c # -lm # math library functions, e.g. sin() #_contextvars _contextvarsmodule.c # Context Variables -#_struct -DPy_BUILD_CORE_MODULE _struct.c # binary structure packing/unpacking +#_struct _struct.c # binary structure packing/unpacking #_weakref _weakref.c # basic weak reference support #_testcapi _testcapimodule.c # Python C API test module -#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal -DPy_BUILD_CORE_MODULE # Python internal C API test module -#_random _randommodule.c -DPy_BUILD_CORE_MODULE # Random number generator +#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal # Python internal C API test module +#_random _randommodule.c # Random number generator #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator -#_pickle -DPy_BUILD_CORE_MODULE _pickle.c # pickle accelerator +#_pickle _pickle.c # pickle accelerator #_datetime _datetimemodule.c # datetime accelerator -#_zoneinfo _zoneinfo.c -DPy_BUILD_CORE_MODULE # zoneinfo accelerator +#_zoneinfo _zoneinfo.c # zoneinfo accelerator #_bisect _bisectmodule.c # Bisection algorithms -#_heapq _heapqmodule.c -DPy_BUILD_CORE_MODULE # Heap queue algorithm +#_heapq _heapqmodule.c # Heap queue algorithm #_asyncio _asynciomodule.c # Fast asyncio Future -#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups +#_json -I$(srcdir)/Include/internal _json.c # _json speedups #_statistics _statisticsmodule.c # statistics accelerator -#unicodedata unicodedata.c -DPy_BUILD_CORE_BUILTIN # static Unicode character database +#unicodedata unicodedata.c # static Unicode character database # Modules with some UNIX dependencies -- on by default: @@ -238,7 +238,7 @@ _symtable symtablemodule.c #termios termios.c # Steen Lumholt's termios module #resource resource.c # Jeremy Hylton's rlimit interface -#_posixsubprocess -DPy_BUILD_CORE_BUILTIN _posixsubprocess.c # POSIX subprocess module helper +#_posixsubprocess _posixsubprocess.c # POSIX subprocess module helper # Multimedia modules -- off by default. # These don't work for 64-bit platforms!!! @@ -260,8 +260,8 @@ _symtable symtablemodule.c # The _sha module implements the SHA checksum algorithms. # (NIST's Secure Hash Algorithms.) #_sha1 sha1module.c -#_sha256 sha256module.c -DPy_BUILD_CORE_BUILTIN -#_sha512 sha512module.c -DPy_BUILD_CORE_BUILTIN +#_sha256 sha256module.c +#_sha512 sha512module.c #_sha3 _sha3/sha3module.c # _blake module @@ -318,7 +318,7 @@ _symtable symtablemodule.c # provided by the ncurses library. e.g. on Linux, link with -lncurses # instead of -lcurses). -#_curses _cursesmodule.c -lcurses -ltermcap -DPy_BUILD_CORE_MODULE +#_curses _cursesmodule.c -lcurses -ltermcap # Wrapper for the panel library that's part of ncurses and SYSV curses. #_curses_panel _curses_panel.c -lpanel -lncurses diff --git a/setup.py b/setup.py index ca0ed8363ef358..ad3e14ab4eb571 100644 --- a/setup.py +++ b/setup.py @@ -372,6 +372,7 @@ def __init__(self, dist): self.parallel = True def add(self, ext): + ext.define_macros.append(("Py_BUILD_CORE_MODULE", None)) self.extensions.append(ext) def set_srcdir(self): @@ -877,8 +878,7 @@ def detect_simple_extensions(self): # # array objects - self.add(Extension('array', ['arraymodule.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension('array', ['arraymodule.c'])) # Context Variables self.add(Extension('_contextvars', ['_contextvarsmodule.c'])) @@ -887,14 +887,12 @@ def detect_simple_extensions(self): # math library functions, e.g. sin() self.add(Extension('math', ['mathmodule.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], extra_objects=[shared_math], depends=['_math.h', shared_math], libraries=['m'])) # complex math library functions self.add(Extension('cmath', ['cmathmodule.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], extra_objects=[shared_math], depends=['_math.h', shared_math], libraries=['m'])) @@ -911,43 +909,33 @@ def detect_simple_extensions(self): # libm is needed by delta_new() that uses round() and by accum() that # uses modf(). self.add(Extension('_datetime', ['_datetimemodule.c'], - libraries=['m'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + libraries=['m'])) # zoneinfo module - self.add(Extension('_zoneinfo', ['_zoneinfo.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension('_zoneinfo', ['_zoneinfo.c'])) # random number generator implemented in C - self.add(Extension("_random", ["_randommodule.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_random", ["_randommodule.c"])) # bisect self.add(Extension("_bisect", ["_bisectmodule.c"])) # heapq - self.add(Extension("_heapq", ["_heapqmodule.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_heapq", ["_heapqmodule.c"])) # C-optimized pickle replacement - self.add(Extension("_pickle", ["_pickle.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_pickle", ["_pickle.c"])) # _json speedups - self.add(Extension("_json", ["_json.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_json", ["_json.c"])) # profiler (_lsprof is for cProfile.py) self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c'])) # static Unicode character database self.add(Extension('unicodedata', ['unicodedata.c'], - depends=['unicodedata_db.h', 'unicodename_db.h'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + depends=['unicodedata_db.h', 'unicodename_db.h'])) # _opcode module self.add(Extension('_opcode', ['_opcode.c'])) # asyncio speedups - self.add(Extension("_asyncio", ["_asynciomodule.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_asyncio", ["_asynciomodule.c"])) # _abc speedups - self.add(Extension("_abc", ["_abc.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_abc", ["_abc.c"])) # _queue module - self.add(Extension("_queue", ["_queuemodule.c"], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension("_queue", ["_queuemodule.c"])) # _statistics module self.add(Extension("_statistics", ["_statisticsmodule.c"])) @@ -1010,8 +998,7 @@ def detect_simple_extensions(self): self.add(Extension('_csv', ['_csv.c'])) # POSIX subprocess module helper. - self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'])) def detect_test_extensions(self): # Python C API test module @@ -1019,8 +1006,7 @@ def detect_test_extensions(self): depends=['testcapi_long.h'])) # Python Internal C API test module - self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) + self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'])) # Python PEP-3118 (buffer protocol) test module self.add(Extension('_testbuffer', ['_testbuffer.c'])) @@ -1160,7 +1146,6 @@ def detect_readline_curses(self): if curses_library.startswith('ncurses'): curses_libs = [curses_library] self.add(Extension('_curses', ['_cursesmodule.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], include_dirs=curses_includes, define_macros=curses_defines, libraries=curses_libs)) @@ -1175,7 +1160,6 @@ def detect_readline_curses(self): curses_libs = ['curses'] self.add(Extension('_curses', ['_cursesmodule.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], define_macros=curses_defines, libraries=curses_libs)) else: @@ -2199,7 +2183,7 @@ def detect_ctypes(self): self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS") include_dirs = [] - extra_compile_args = ['-DPy_BUILD_CORE_MODULE'] + extra_compile_args = [] extra_link_args = [] sources = ['_ctypes/_ctypes.c', '_ctypes/callbacks.c', @@ -2512,14 +2496,12 @@ def detect_hash_builtins(self): if "sha256" in configured: self.add(Extension( '_sha256', ['sha256module.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], depends=['hashlib.h'] )) if "sha512" in configured: self.add(Extension( '_sha512', ['sha512module.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'], depends=['hashlib.h'] )) @@ -2714,9 +2696,12 @@ class DummyProcess: 'install_lib': PyBuildInstallLib}, # The struct module is defined here, because build_ext won't be # called unless there's at least one extension module defined. - ext_modules=[Extension('_struct', ['_struct.c'], - extra_compile_args=['-DPy_BUILD_CORE_MODULE'])], - + ext_modules=[ + Extension( + '_struct', ['_struct.c'], + define_macros=[('Py_BUILD_CORE_MODULE', None)] + ) + ], # If you change the scripts installed here, you also need to # check the PyBuildScripts command above, and change the links # created by the bininstall target in Makefile.pre.in