Python build shared library

3.1.9. Security Options

New in version 3.11: siphash13 is added and it is the new default.

  • md5 ;
  • sha1 ;
  • sha256 ;
  • sha512 ;
  • sha3 (with shake);
  • blake2 .

Override the OpenSSL default cipher suites string:

  • python (default): use Python’s preferred selection;
  • openssl : leave OpenSSL’s defaults untouched;
  • STRING: use a custom string

Changed in version 3.10: The settings python and STRING also set TLS 1.2 as minimum protocol version.

3.1.10. macOS Options

Create a universal binary build. SDKDIR specifies which macOS SDK should be used to perform the build (default is no).

Create a Python.framework rather than a traditional Unix install. Optional INSTALLDIR specifies the installation path (default is no).

Specify the kind of universal binary that should be created. This option is only valid when —enable-universalsdk is set.

  • universal2 ;
  • 32-bit ;
  • 64-bit ;
  • 3-way ;
  • intel ;
  • intel-32 ;
  • intel-64 ;
  • all .

Specify the name for the python framework on macOS only valid when —enable-framework is set (default: Python ).

3.1.11. Cross Compiling Options

Cross compiling, also known as cross building, can be used to build Python for another CPU architecture or platform. Cross compiling requires a Python interpreter for the build platform. The version of the build Python must match the version of the cross compiled host Python.

configure for building on BUILD, usually guessed by config.guess.

cross-compile to build programs to run on HOST (target platform)

path to build python binary for cross compiling

An environment variable that points to a file with configure overrides.

# config.site-aarch64 ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no 
CONFIG_SITE=config.site-aarch64 ../configure \ --build=x86_64-pc-linux-gnu \ --host=aarch64-unknown-linux-gnu \ --with-build-python=../x86_64/python

3.2. Python Build System

3.2.1. Main files of the build system

  • configure.ac => configure ;
  • Makefile.pre.in => Makefile (created by configure );
  • pyconfig.h (created by configure );
  • Modules/Setup : C extensions built by the Makefile using Module/makesetup shell script;
  • setup.py : C extensions built using the distutils module.

3.2.2. Main build steps

  • C files ( .c ) are built as object files ( .o ).
  • A static libpython library ( .a ) is created from objects files.
  • python.o and the static libpython library are linked into the final python program.
  • C extensions are built by the Makefile (see Modules/Setup ) and python setup.py build .

3.2.3. Main Makefile targets

  • make : Build Python with the standard library.
  • make platform: : build the python program, but don’t build the standard library extension modules.
  • make profile-opt : build Python using Profile Guided Optimization (PGO). You can use the configure —enable-optimizations option to make this the default target of the make command ( make all or just make ).
  • make buildbottest : Build Python and run the Python test suite, the same way than buildbots test Python. Set TESTTIMEOUT variable (in seconds) to change the test timeout (1200 by default: 20 minutes).
  • make install : Build and install Python.
  • make regen-all : Regenerate (almost) all generated files; make regen-stdlib-module-names and autoconf must be run separately for the remaining generated files.
  • make clean : Remove built files.
  • make distclean : Same than make clean , but remove also files created by the configure script.

3.2.4. C extensions

Some C extensions are built as built-in modules, like the sys module. They are built with the Py_BUILD_CORE_BUILTIN macro defined. Built-in modules have no __file__ attribute:

>>> import sys >>> sys module 'sys' (built-in)> >>> sys.__file__ Traceback (most recent call last): File "", line 1, in module> AttributeError: module 'sys' has no attribute '__file__' 

Other C extensions are built as dynamic libraries, like the _asyncio module. They are built with the Py_BUILD_CORE_MODULE macro defined. Example on Linux x86-64:

>>> import _asyncio >>> _asyncio '_asyncio' from '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so'> >>> _asyncio.__file__ '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so' 

Modules/Setup is used to generate Makefile targets to build C extensions. At the beginning of the files, C extensions are built as built-in modules. Extensions defined after the *shared* marker are built as dynamic libraries.

The setup.py script only builds C extensions as shared libraries using the distutils module.

The PyAPI_FUNC() , PyAPI_API() and PyMODINIT_FUNC() macros of Include/pyport.h are defined differently depending if the Py_BUILD_CORE_MODULE macro is defined:

  • Use Py_EXPORTED_SYMBOL if the Py_BUILD_CORE_MODULE is defined
  • Use Py_IMPORTED_SYMBOL otherwise.

If the Py_BUILD_CORE_BUILTIN macro is used by mistake on a C extension built as a shared library, its PyInit_xxx() function is not exported, causing an ImportError on import.

3.3. Compiler and linker flags

Options set by the ./configure script and environment variables and used by Makefile .

3.3.1. Preprocessor flags

Value of CPPFLAGS variable passed to the ./configure script.

(Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory .

Both CPPFLAGS and LDFLAGS need to contain the shell’s value for setup.py to be able to build extension modules using the directories specified in the environment variables.

Extra preprocessor flags added for building the interpreter object files.

Default: $(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) .

3.3.2. Compiler flags

C compiler command used to build the main() function of programs like python .

Variable set by the —with-cxx-main option of the configure script.

Used if the —with-cxx-main option is used.

CFLAGS_NODIST is used for building the interpreter and stdlib C extensions. Use it when a compiler flag should not be part of the distutils CFLAGS once Python is installed (bpo-21121).

In particular, CFLAGS should not contain:

  • the compiler flag -I (for setting the search path for include files). The -I flags are processed from left to right, and any flags in CFLAGS would take precedence over user- and package-supplied -I flags.
  • hardening flags such as -Werror because distributions cannot control whether packages installed by users conform to such heightened standards.

Value of CFLAGS variable passed to the ./configure script.

Value of CFLAGS_NODIST variable passed to the ./configure script.

Strict or non-strict aliasing flags used to compile Python/dtoa.c .

Compiler flags used to build a shared library.

For example, -fPIC is used on Linux and on BSD.

Extra C flags added for building the interpreter object files.

Default: $(CCSHARED) when —enable-shared is used, or an empty string otherwise.

Default: $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) .

Default: $(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include/internal .

C flags used for building the interpreter object files.

Default: $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) .

Default: $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE .

Compiler flags to build a standard library extension module as a built-in module, like the posix module.

Default: $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN .

Purify command. Purify is a memory debugger program.

Default: empty string (not used).

3.3.3. Linker flags

Linker command used to build programs like python and _testembed .

Value of LDFLAGS variable passed to the ./configure script.

Avoid assigning CFLAGS , LDFLAGS , etc. so users can use them on the command line to append to these values without stomping the pre-set values.

LDFLAGS_NODIST is used in the same manner as CFLAGS_NODIST . Use it when a linker flag should not be part of the distutils LDFLAGS once Python is installed (bpo-35257).

In particular, LDFLAGS should not contain:

  • the compiler flag -L (for setting the search path for libraries). The -L flags are processed from left to right, and any flags in LDFLAGS would take precedence over user- and package-supplied -L flags.

Value of LDFLAGS_NODIST variable passed to the ./configure script.

Linker flags, e.g. -L if you have libraries in a nonstandard directory .

Both CPPFLAGS and LDFLAGS need to contain the shell’s value for setup.py to be able to build extension modules using the directories specified in the environment variables.

Linker flags to pass libraries to the linker when linking the Python executable.

Command to build a shared library.

Default: @LDSHARED@ $(PY_LDFLAGS) .

Command to build libpython shared library.

Default: @BLDSHARED@ $(PY_CORE_LDFLAGS) .

Default: $(CONFIGURE_LDFLAGS) $(LDFLAGS) .

Default: $(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST) .

Linker flags used for building the interpreter object files.

Python 3.11

List all ./configure script options using: See also the Misc/SpecialBuilds.txt in Python source distribution.

This part of the documentation devoted general information setup Python environment different platforms, invocation interpreter and things that make working

Источник

Читайте также:  Get list methods php
Оцените статью