Skip to content

Commit 4c459a4

Browse files
committed
pythongh-131842: Allow to pass custom CFLAGS and LDFLAGS to the compilation of builtin extension modules
Signed-off-by: Pablo Galindo <[email protected]>
1 parent 56d0f9a commit 4c459a4

File tree

8 files changed

+40
-4
lines changed

8 files changed

+40
-4
lines changed

Diff for: Doc/using/configure.rst

+19-1
Original file line numberDiff line numberDiff line change
@@ -1396,12 +1396,21 @@ Compiler flags
13961396

13971397
.. versionadded:: 3.2
13981398

1399+
.. envvar:: PY_EXTRA_STDMODULE_CFLAGS
1400+
1401+
Equivalent flag to :envvar:`CFLAGS_NODIST` but it only applies to **all** builtin extension
1402+
modules built as part of the standard library.
1403+
1404+
Default: (empty).
1405+
1406+
.. versionadded:: next
1407+
13991408
.. envvar:: PY_BUILTIN_MODULE_CFLAGS
14001409

14011410
Compiler flags to build a standard library extension module as a built-in
14021411
module, like the :mod:`posix` module.
14031412

1404-
Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN``.
1413+
Default: ``$(BUILTIN_MODULE_CFLAGS) $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN``.
14051414

14061415
.. versionadded:: 3.8
14071416

@@ -1495,6 +1504,15 @@ Linker flags
14951504

14961505
.. versionadded:: 3.8
14971506

1507+
.. envvar:: PY_EXTRA_STDMODULE_LDFLAGS
1508+
1509+
Equivalent flag to :envvar:`LDLAGS_NODIST` but it only applies to **all** builtin extension
1510+
modules built as part of the standard library.
1511+
1512+
Default: (empty).
1513+
1514+
.. versionadded:: next
1515+
14981516

14991517
.. rubric:: Footnotes
15001518

Diff for: Doc/whatsnew/3.13.rst

-1
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,6 @@ Build Changes
25912591
C extensions are now built with the :ref:`limited C API <limited-c-api>`.
25922592
(Contributed by Victor Stinner in :gh:`85283`.)
25932593

2594-
25952594
Porting to Python 3.13
25962595
======================
25972596

Diff for: Doc/whatsnew/3.14.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,13 @@ Build changes
14951495
with :c:expr:`Py_NO_LINK_LIB`. (Contributed by Jean-Christophe
14961496
Fillion-Robin in :gh:`82909`.)
14971497

1498+
* Two new configure flags are added: :envvar:`CFLAGS_BUILTIN_MODULE` and
1499+
:envvar:`LDFLAGS_BUILTIN_MODULE`. These flags allows refistributors to
1500+
provide compile and linker flags that only apply to standard library extension
1501+
modules. This is particulary useful to provide options such as ``RUNPATH`` and
1502+
``RPATH`` that need to be applied specifically to standard library modules due to
1503+
its different relative location. (Contributed by Pablo Galindo in :gh:`131842`.)
1504+
14981505
.. _whatsnew314-pep761:
14991506

15001507
PEP 761: Discontinuation of PGP signatures

Diff for: Makefile.pre.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ ARFLAGS= @ARFLAGS@
119119
# Extra C flags added for building the interpreter object files.
120120
CFLAGSFORSHARED=@CFLAGSFORSHARED@
121121
# C flags used for building the interpreter object files
122+
PY_EXTRA_STDMODULE_CFLAGS= @PY_EXTRA_STDMODULE_CFLAGS@
123+
PY_EXTRA_STDMODULE_LDFLAGS= @PY_EXTRA_STDMODULE_LDFLAGS@
122124
PY_STDMODULE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED)
123-
PY_BUILTIN_MODULE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN
125+
PY_BUILTIN_MODULE_CFLAGS= $(PY_EXTRA_STDMODULE_CFLAGS) $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN
126+
PY_BUILTIN_MODULE_LDFLAGS= $(PY_EXTRA_STDMODULE_LDFLAGS)
124127
PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
125128
# Linker flags used for building the interpreter object files
126129
PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow to pass custom ``CFLAGS`` and ``LDFLAGS`` to the compilation of
2+
builtin extension modules. Patch by Pablo Galindo

Diff for: Modules/makesetup

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
274274
;;
275275
esac
276276
rule="$file: $objs"
277-
rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file"
277+
ldd="\$(BLDSHARED) \$(PY_BUILTIN_MODULE_LDFLAGS)"
278+
rule="$rule; $ldd $objs $libs \$(LIBPYTHON) -o $file"
278279
echo "$rule" >>$rulesf
279280
done
280281
done

Diff for: configure

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,9 @@ AS_CASE([$enable_wasm_dynamic_linking],
24322432

24332433
AC_SUBST([BASECFLAGS])
24342434
AC_SUBST([CFLAGS_NODIST])
2435+
AC_SUBST([PY_EXTRA_STDMODULE_CFLAGS])
24352436
AC_SUBST([LDFLAGS_NODIST])
2437+
AC_SUBST([PY_EXTRA_STDMODULE_LDFLAGS])
24362438
AC_SUBST([LDFLAGS_NOLTO])
24372439
AC_SUBST([WASM_ASSETS_DIR])
24382440
AC_SUBST([WASM_STDLIB])

0 commit comments

Comments
 (0)