https://github.com/python/cpython/commit/3bc42942af865a036282f7c9e0011fe8528b03c1
commit: 3bc42942af865a036282f7c9e0011fe8528b03c1
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: brandtbucher <brandtbuc...@gmail.com>
date: 2025-07-01T14:34:59-07:00
summary:

[3.14] GH-134273: Allow setting JIT compiler flags at build time with 
CFLAGS_JIT (GH-135792)

(cherry picked from commit 2b0c684e0759dc3fec0e9dd0fc8383e6c75b7b5c)
Co-authored-by: Zanie Blue <cont...@zanie.dev>

files:
A Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst
M Tools/jit/_targets.py
M Tools/jit/build.py
M configure
M configure.ac

diff --git 
a/Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst 
b/Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst
new file mode 100644
index 00000000000000..3eb13cefbe6dfc
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst
@@ -0,0 +1 @@
+Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT``
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
index d0a1c081ffecc2..b383e39da19456 100644
--- a/Tools/jit/_targets.py
+++ b/Tools/jit/_targets.py
@@ -10,6 +10,7 @@
 import sys
 import tempfile
 import typing
+import shlex
 
 import _llvm
 import _schema
@@ -46,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
     stable: bool = False
     debug: bool = False
     verbose: bool = False
+    cflags: str = ""
     known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
     pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
 
@@ -62,6 +64,7 @@ def _compute_digest(self) -> str:
         hasher = hashlib.sha256()
         hasher.update(self.triple.encode())
         hasher.update(self.debug.to_bytes())
+        hasher.update(self.cflags.encode())
         # These dependencies are also reflected in _JITSources in 
regen.targets:
         hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
         hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
@@ -155,6 +158,8 @@ async def _compile(
             f"{o}",
             f"{c}",
             *self.args,
+            # Allow user-provided CFLAGS to override any defaults
+            *shlex.split(self.cflags),
         ]
         await _llvm.run("clang", args, echo=self.verbose)
         return await self._parse(o)
diff --git a/Tools/jit/build.py b/Tools/jit/build.py
index 1afd0c76bad1d2..a0733005929bf2 100644
--- a/Tools/jit/build.py
+++ b/Tools/jit/build.py
@@ -39,11 +39,15 @@
     parser.add_argument(
         "-v", "--verbose", action="store_true", help="echo commands as they 
are run"
     )
+    parser.add_argument(
+        "--cflags", help="additional flags to pass to the compiler", default=""
+    )
     args = parser.parse_args()
     for target in args.target:
         target.debug = args.debug
         target.force = args.force
         target.verbose = args.verbose
+        target.cflags = args.cflags
         target.pyconfig_dir = args.pyconfig_dir
         target.build(
             comment=comment,
diff --git a/configure b/configure
index cc2636348ad4cc..e5639740e2cc02 100755
--- a/configure
+++ b/configure
@@ -10863,7 +10863,7 @@ then :
 
 else case e in #(
   e) as_fn_append CFLAGS_NODIST " $jit_flags"
-           REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) 
\$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . 
--pyconfig-dir ."
+           REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) 
\$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . 
--pyconfig-dir . --cflags=\"$CFLAGS_JIT\""
            JIT_STENCILS_H="jit_stencils.h"
            if test "x$Py_DEBUG" = xtrue
 then :
diff --git a/configure.ac b/configure.ac
index 912f77b9ae2cc5..8cba00aa888cb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
           [],
           [AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
            AS_VAR_SET([REGEN_JIT_COMMAND],
-                      ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py 
${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."])
+                      ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py 
${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . 
--cflags=\"$CFLAGS_JIT\""])
            AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
            AS_VAR_IF([Py_DEBUG],
                      [true],

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to