Skip to content

gh-133312: configure: add --enable-static-libpython-for-interpreter #133313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,21 @@ Linker options

.. versionadded:: 3.10

.. option:: --enable-static-libpython-for-interpreter

Do not link the Python interpreter binary (``python3``) against the
shared Python library; instead, statically link the interpreter
against ``libpython`` as if ``--enable-shared`` had not been used,
but continue to build the shared ``libpython`` (for use by other
programs).

This option does nothing if ``--enable-shared`` is not used.

The default (when ``-enable-shared`` is used) is to link the Python
interpreter against the built shared library.

.. versionadded:: 3.14


Libraries options
-----------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Add a new ``./configure`` option
:option:`--enable-static-libpython-for-interpreter` which, when used
with :option:`--enable-shared`, continues to build the shared library
but does not use it for the interpreter. Instead, libpython is
statically linked into the interpreter, as if :option:`--enable-shared`
had not been used. This allows you to do a single build and get a Python
interpreter binary that does not use a shared library but also get a
shared library for use by other programs.
24 changes: 21 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,17 @@ fi],
[AC_MSG_RESULT([yes])])
AC_SUBST([STATIC_LIBPYTHON])

AC_MSG_CHECKING([for --enable-static-libpython-for-interpreter])
AC_ARG_ENABLE([static-libpython-for-interpreter],
AS_HELP_STRING([--enable-static-libpython-for-interpreter],
[even with --enable-shared, statically link libpython into the interpreter (default is to use the shared library)]))

if test -z "$enable_static_libpython_for_interpreter"
then
enable_static_libpython_for_interpreter="no"
fi
AC_MSG_RESULT([$enable_static_libpython_for_interpreter])

AC_MSG_CHECKING([for --enable-profiling])
AC_ARG_ENABLE([profiling],
AS_HELP_STRING([--enable-profiling], [enable C-level code profiling with gprof (default is no)]))
Expand Down Expand Up @@ -1660,7 +1671,11 @@ if test "$PY_ENABLE_SHARED" = 1 || test "$enable_framework" ; then
LIBRARY_DEPS="\$(LIBRARY) $LIBRARY_DEPS"
fi
# Link Python program to the shared library
LINK_PYTHON_OBJS='$(BLDLIBRARY)'
if test "$enable_static_libpython_for_interpreter" = "yes"; then
LINK_PYTHON_OBJS='$(LIBRARY_OBJS)'
else
LINK_PYTHON_OBJS='$(BLDLIBRARY)'
fi
else
if test "$STATIC_LIBPYTHON" = 0; then
# Build Python needs object files but don't need to build
Expand Down Expand Up @@ -2166,11 +2181,14 @@ if test "$Py_BOLT" = 'true' ; then
fi
fi

dnl Enable BOLT of libpython if built.
dnl Enable BOLT of libpython if built and used by the python3 binary.
dnl (If it is built but not used, we cannot profile it.)
AC_SUBST([BOLT_BINARIES])
BOLT_BINARIES='$(BUILDPYTHON)'
AS_VAR_IF([enable_shared], [yes], [
BOLT_BINARIES="${BOLT_BINARIES} \$(INSTSONAME)"
AS_VAR_IF([enable_static_libpython_for_interpreter], [no], [
BOLT_BINARIES="${BOLT_BINARIES} \$(INSTSONAME)"
])
])

AC_ARG_VAR(
Expand Down
Loading