From 7d12a8abdc562c5fca33fdad029102dbfdbc1415 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 19 May 2025 13:48:03 -0400 Subject: [PATCH 1/5] gh-134273: Propagate CFLAGS to the JIT --- Tools/jit/_targets.py | 3 +++ Tools/jit/build.py | 4 ++++ configure | 2 +- configure.ac | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 6ceb4404e74ce7..94b74b5c8b0c7e 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) def _get_nop(self) -> bytes: @@ -119,6 +121,7 @@ async def _compile( ) -> _stencils.StencilGroup: o = tempdir / f"{opname}.o" args = [ + *shlex.split(self.cflags), f"--target={self.triple}", "-DPy_BUILD_CORE_MODULE", "-D_DEBUG" if self.debug else "-DNDEBUG", diff --git a/Tools/jit/build.py b/Tools/jit/build.py index 49b08f477dbed7..49a1b11de474a8 100644 --- a/Tools/jit/build.py +++ b/Tools/jit/build.py @@ -26,11 +26,15 @@ parser.add_argument( "-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="" + ) 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.build( out, comment=comment, diff --git a/configure b/configure index 2649a800f91a48..d12a97879b1ea1 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}" + REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-cflags=\"\$(CONFIGURE_CFLAGS)\"" JIT_STENCILS_H="jit_stencils.h" if test "x$Py_DEBUG" = xtrue then : diff --git a/configure.ac b/configure.ac index 5525a5b0ed5240..745c5dc7390664 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}"]) + ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-cflags=\"\$(CONFIGURE_CFLAGS)\""]) AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"]) AS_VAR_IF([Py_DEBUG], [true], From a6cfd1fb897d0c3a9bc910241ddad28f40d62fbc Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 19 May 2025 18:05:54 -0400 Subject: [PATCH 2/5] Update `_Target._compute_digest` --- Tools/jit/_targets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 94b74b5c8b0c7e..a2a68522735c4d 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -63,6 +63,7 @@ def _compute_digest(self, out: pathlib.Path) -> 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((out / "pyconfig.h").read_bytes()) From 7ed82fe38d402f78177ac21f981f0c369cb2eb41 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 19 May 2025 18:09:31 -0400 Subject: [PATCH 3/5] Add NEWS --- .../next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst 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..c307dd98c6fe8f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst @@ -0,0 +1 @@ +Respect CFLAGS set during configure during JIT builds From 9c7658060a07e275ea70936ce2112b17ae475c66 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 27 May 2025 15:46:52 -0500 Subject: [PATCH 4/5] Use CFLAGS_JIT --- configure | 4 +++- configure.ac | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/configure b/configure index d12a97879b1ea1..ecffb702b44f37 100755 --- a/configure +++ b/configure @@ -906,6 +906,7 @@ DSYMUTIL_PATH DSYMUTIL JIT_STENCILS_H REGEN_JIT_COMMAND +CFLAGS_JIT UNIVERSAL_ARCH_FLAGS WASM_STDLIB WASM_ASSETS_DIR @@ -10832,6 +10833,7 @@ esac fi # Check for --enable-experimental-jit: + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --enable-experimental-jit" >&5 printf %s "checking for --enable-experimental-jit... " >&6; } # Check whether --enable-experimental-jit was given. @@ -10863,7 +10865,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} --with-cflags=\"\$(CONFIGURE_CFLAGS)\"" + REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-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 745c5dc7390664..f8488d0fae8bca 100644 --- a/configure.ac +++ b/configure.ac @@ -2752,6 +2752,7 @@ AS_VAR_IF([ac_cv_gcc_compat], [yes], [ ]) # Check for --enable-experimental-jit: +AC_SUBST([CFLAGS_JIT]) AC_MSG_CHECKING([for --enable-experimental-jit]) AC_ARG_ENABLE([experimental-jit], [AS_HELP_STRING([--enable-experimental-jit@<:@=no|yes|yes-off|interpreter@:>@], @@ -2776,7 +2777,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} --with-cflags=\"\$(CONFIGURE_CFLAGS)\""]) + ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-cflags=\"\$(CFLAGS_JIT)\""]) AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"]) AS_VAR_IF([Py_DEBUG], [true], From 1633f560624041de0464b8943d5954cb422a403f Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 27 May 2025 15:50:21 -0500 Subject: [PATCH 5/5] Update news --- .../next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c307dd98c6fe8f..76ae16b7556091 100644 --- 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 @@ -1 +1 @@ -Respect CFLAGS set during configure during JIT builds +Add support for configuring compiler flags for the JIT with CFLAGS_JIT