From 7d12a8abdc562c5fca33fdad029102dbfdbc1415 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 19 May 2025 13:48:03 -0400 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 From b24af27605c2d34a51791442e8ff662325f1ea43 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 6 Jun 2025 08:27:21 -0500 Subject: [PATCH 06/10] Rename `--with-cflags` to `--cflags` Co-authored-by: Brandt Bucher --- Tools/jit/build.py | 4 ++-- configure | 2 +- configure.ac | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tools/jit/build.py b/Tools/jit/build.py index 96c4cb075932d2..a0733005929bf2 100644 --- a/Tools/jit/build.py +++ b/Tools/jit/build.py @@ -40,14 +40,14 @@ "-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 ff40a8adeeff49..68213817679534 100755 --- a/configure +++ b/configure @@ -10865,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} --output-dir . --pyconfig-dir . --with-cflags=\"\$(CFLAGS_JIT)\"" + 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 d4b05c9282206b..9ab4b370f1c050 100644 --- a/configure.ac +++ b/configure.ac @@ -2777,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} --output-dir . --pyconfig-dir . --with-cflags=\"\$(CFLAGS_JIT)\""]) + ["\$(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], From 6c4eb49296f169d039ca069fcae95af277fd4208 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 6 Jun 2025 08:27:41 -0500 Subject: [PATCH 07/10] Fix formatting in NEWS entry Co-authored-by: Brandt Bucher --- .../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 76ae16b7556091..3eb13cefbe6dfc 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 @@ -Add support for configuring compiler flags for the JIT with CFLAGS_JIT +Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT`` From 397c52e721eb661ad72cfa9362622da01ef0b69d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 6 Jun 2025 08:29:43 -0500 Subject: [PATCH 08/10] Move to end --- Tools/jit/_targets.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index a7279d5fd9487a..b7cd230b08fba2 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -123,7 +123,6 @@ 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", @@ -158,6 +157,8 @@ async def _compile( "-o", f"{o}", f"{c}", + # Allow user-provided CFLAGS to override any defaults + *shlex.split(self.cflags), *self.args, ] await _llvm.run("clang", args, echo=self.verbose) From a66407152ace9030cb6a4835f846aa267b2a2d5e Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 6 Jun 2025 13:02:48 -0700 Subject: [PATCH 09/10] Move self.cflags to the very end, to override any of our own logic --- Tools/jit/_targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index b7cd230b08fba2..b383e39da19456 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -157,9 +157,9 @@ async def _compile( "-o", f"{o}", f"{c}", + *self.args, # Allow user-provided CFLAGS to override any defaults *shlex.split(self.cflags), - *self.args, ] await _llvm.run("clang", args, echo=self.verbose) return await self._parse(o) From 5e752e0efd34c8af0402de434df44881e8188030 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 9 Jun 2025 09:03:24 -0500 Subject: [PATCH 10/10] Resolve `CFLAGS_JIT` at `configure`-time --- configure | 4 +--- configure.ac | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 68213817679534..6170e67e6e297a 100755 --- a/configure +++ b/configure @@ -906,7 +906,6 @@ DSYMUTIL_PATH DSYMUTIL JIT_STENCILS_H REGEN_JIT_COMMAND -CFLAGS_JIT UNIVERSAL_ARCH_FLAGS WASM_STDLIB WASM_ASSETS_DIR @@ -10833,7 +10832,6 @@ 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. @@ -10865,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 . --cflags=\"\$(CFLAGS_JIT)\"" + 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 9ab4b370f1c050..f6091c21b2a686 100644 --- a/configure.ac +++ b/configure.ac @@ -2752,7 +2752,6 @@ 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@:>@], @@ -2777,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 . --cflags=\"\$(CFLAGS_JIT)\""]) + ["\$(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], pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy