]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-134273: Allow setting JIT compiler flags at build time with CFLAGS_JIT (GH134276)
authorZanie Blue <contact@zanie.dev>
Thu, 12 Jun 2025 23:11:08 +0000 (18:11 -0500)
committerGitHub <noreply@github.com>
Thu, 12 Jun 2025 23:11:08 +0000 (16:11 -0700)
Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst [new file with mode: 0644]
Tools/jit/_targets.py
Tools/jit/build.py
configure
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 (file)
index 0000000..3eb13ce
--- /dev/null
@@ -0,0 +1 @@
+Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT``
index d0a1c081ffecc2e2b81447807ae2e14ab7d87ee3..b383e39da194562c72c707cf777aa30d4e69f5df 100644 (file)
@@ -10,6 +10,7 @@ import re
 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 @@ class _Target(typing.Generic[_S, _R]):
         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 @@ class _Target(typing.Generic[_S, _R]):
             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)
index 1afd0c76bad1d2d7a1e594c9dbf42953b3ab2a20..a0733005929bf243e724e3fefa30391b927f1e78 100644 (file)
@@ -39,11 +39,15 @@ if __name__ == "__main__":
     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,
index 029bf527da4e3db9e4d5a5d1abc681be2c833b72..fef9f2d7da935c1bed8f2c630cf63bd98eecfc78 100755 (executable)
--- 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 :
index 371b2e8ed735253b7fb32c511145e76e0a0f4f54..cc37a636c522ba824dc48ddd41227cbf7d2880de 100644 (file)
@@ -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],