diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 820b6a2d..75f330d9 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -653,7 +653,8 @@ fi # We patched configure.ac above. Reflect those changes. autoconf -CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \ +# Ensure `CFLAGS` are propagated to JIT compilation for 3.13+ +CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS JIT_CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \ ./configure ${CONFIGURE_FLAGS} # Supplement produced Makefile with our modifications. diff --git a/cpython-unix/patch-jit-cflags-314.patch b/cpython-unix/patch-jit-cflags-314.patch index 3a16fb5d..a75563b4 100644 --- a/cpython-unix/patch-jit-cflags-314.patch +++ b/cpython-unix/patch-jit-cflags-314.patch @@ -1,5 +1,12 @@ +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 00000000000..3eb13cefbe6 +--- /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 d0a1c081ffe..deb83f275d2 100644 +index d0a1c081ffe..b383e39da19 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -10,6 +10,7 @@ @@ -18,16 +25,25 @@ index d0a1c081ffe..deb83f275d2 100644 known_symbols: dict[str, int] = dataclasses.field(default_factory=dict) pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve() -@@ -120,6 +122,7 @@ async def _compile( - ) -> _stencils.StencilGroup: - o = tempdir / f"{opname}.o" - args = [ +@@ -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), - f"--target={self.triple}", - "-DPy_BUILD_CORE_MODULE", - "-D_DEBUG" if self.debug else "-DNDEBUG", + ] + 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 1afd0c76bad..96c4cb07593 100644 +index 1afd0c76bad..a0733005929 100644 --- a/Tools/jit/build.py +++ b/Tools/jit/build.py @@ -39,11 +39,15 @@ @@ -35,19 +51,19 @@ index 1afd0c76bad..96c4cb07593 100644 "-v", "--verbose", action="store_true", help="echo commands as they are run" ) + parser.add_argument( -+ "--with-cflags", help="additional flags to pass to the compiler", default="" ++ "--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.with_cflags ++ target.cflags = args.cflags target.pyconfig_dir = args.pyconfig_dir target.build( comment=comment, diff --git a/configure b/configure -index 884f8a4b068..2e6740c33d9 100755 +index 029bf527da4..fef9f2d7da9 100755 --- a/configure +++ b/configure @@ -10863,7 +10863,7 @@ then : @@ -55,12 +71,12 @@ index 884f8a4b068..2e6740c33d9 100755 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 . --with-cflags=\"\$(CONFIGURE_CFLAGS)\"" ++ 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 cf25148bad2..f8bfab7bf96 100644 +index 371b2e8ed73..cc37a636c52 100644 --- a/configure.ac +++ b/configure.ac @@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags], @@ -68,7 +84,7 @@ index cf25148bad2..f8bfab7bf96 100644 [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 . --with-cflags=\"\$(CONFIGURE_CFLAGS)\""]) ++ ["\$(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],