Skip to content

Commit fe33e63

Browse files
authored
Use the latest patch for the CFLAGS JIT configuration (#659)
1 parent bd92d95 commit fe33e63

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

cpython-unix/build-cpython.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ fi
653653
# We patched configure.ac above. Reflect those changes.
654654
autoconf
655655

656-
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \
656+
# Ensure `CFLAGS` are propagated to JIT compilation for 3.13+
657+
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS JIT_CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \
657658
./configure ${CONFIGURE_FLAGS}
658659

659660
# Supplement produced Makefile with our modifications.
Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
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
2+
new file mode 100644
3+
index 00000000000..3eb13cefbe6
4+
--- /dev/null
5+
+++ b/Misc/NEWS.d/next/Build/2025-05-19-18-09-20.gh-issue-134273.ZAliyy.rst
6+
@@ -0,0 +1 @@
7+
+Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT``
18
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
2-
index d0a1c081ffe..deb83f275d2 100644
9+
index d0a1c081ffe..b383e39da19 100644
310
--- a/Tools/jit/_targets.py
411
+++ b/Tools/jit/_targets.py
512
@@ -10,6 +10,7 @@
@@ -18,57 +25,66 @@ index d0a1c081ffe..deb83f275d2 100644
1825
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
1926
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
2027

21-
@@ -120,6 +122,7 @@ async def _compile(
22-
) -> _stencils.StencilGroup:
23-
o = tempdir / f"{opname}.o"
24-
args = [
28+
@@ -62,6 +64,7 @@ def _compute_digest(self) -> str:
29+
hasher = hashlib.sha256()
30+
hasher.update(self.triple.encode())
31+
hasher.update(self.debug.to_bytes())
32+
+ hasher.update(self.cflags.encode())
33+
# These dependencies are also reflected in _JITSources in regen.targets:
34+
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
35+
hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
36+
@@ -155,6 +158,8 @@ async def _compile(
37+
f"{o}",
38+
f"{c}",
39+
*self.args,
40+
+ # Allow user-provided CFLAGS to override any defaults
2541
+ *shlex.split(self.cflags),
26-
f"--target={self.triple}",
27-
"-DPy_BUILD_CORE_MODULE",
28-
"-D_DEBUG" if self.debug else "-DNDEBUG",
42+
]
43+
await _llvm.run("clang", args, echo=self.verbose)
44+
return await self._parse(o)
2945
diff --git a/Tools/jit/build.py b/Tools/jit/build.py
30-
index 1afd0c76bad..96c4cb07593 100644
46+
index 1afd0c76bad..a0733005929 100644
3147
--- a/Tools/jit/build.py
3248
+++ b/Tools/jit/build.py
3349
@@ -39,11 +39,15 @@
3450
parser.add_argument(
3551
"-v", "--verbose", action="store_true", help="echo commands as they are run"
3652
)
3753
+ parser.add_argument(
38-
+ "--with-cflags", help="additional flags to pass to the compiler", default=""
54+
+ "--cflags", help="additional flags to pass to the compiler", default=""
3955
+ )
4056
args = parser.parse_args()
4157
for target in args.target:
4258
target.debug = args.debug
4359
target.force = args.force
4460
target.verbose = args.verbose
45-
+ target.cflags = args.with_cflags
61+
+ target.cflags = args.cflags
4662
target.pyconfig_dir = args.pyconfig_dir
4763
target.build(
4864
comment=comment,
4965
diff --git a/configure b/configure
50-
index 884f8a4b068..2e6740c33d9 100755
66+
index 029bf527da4..fef9f2d7da9 100755
5167
--- a/configure
5268
+++ b/configure
5369
@@ -10863,7 +10863,7 @@ then :
5470

5571
else case e in #(
5672
e) as_fn_append CFLAGS_NODIST " $jit_flags"
5773
- REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."
58-
+ REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --with-cflags=\"\$(CONFIGURE_CFLAGS)\""
74+
+ REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\""
5975
JIT_STENCILS_H="jit_stencils.h"
6076
if test "x$Py_DEBUG" = xtrue
6177
then :
6278
diff --git a/configure.ac b/configure.ac
63-
index cf25148bad2..f8bfab7bf96 100644
79+
index 371b2e8ed73..cc37a636c52 100644
6480
--- a/configure.ac
6581
+++ b/configure.ac
6682
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
6783
[],
6884
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
6985
AS_VAR_SET([REGEN_JIT_COMMAND],
7086
- ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."])
71-
+ ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --with-cflags=\"\$(CONFIGURE_CFLAGS)\""])
87+
+ ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\""])
7288
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
7389
AS_VAR_IF([Py_DEBUG],
7490
[true],

0 commit comments

Comments
 (0)