Skip to content

Commit 9374cff

Browse files
committed
Pass CFLAGS to the JIT
1 parent 7202f02 commit 9374cff

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ else
8383
patch -p1 -i ${ROOT}/patch-xopen-source-ios-legacy.patch
8484
fi
8585

86+
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
87+
patch -p1 -i ${ROOT}/patch-jit-cflags.patch
88+
fi
89+
8690
# LIBTOOL_CRUFT is unused and breaks cross-compiling on macOS. Nuke it.
8791
# Submitted upstream at https://github.com/python/cpython/pull/101048.
8892
if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then

cpython-unix/patch-jit-cflags.patch

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
2+
index 6ceb4404e74..94b74b5c8b0 100644
3+
--- a/Tools/jit/_targets.py
4+
+++ b/Tools/jit/_targets.py
5+
@@ -10,6 +10,7 @@
6+
import sys
7+
import tempfile
8+
import typing
9+
+import shlex
10+
11+
import _llvm
12+
import _schema
13+
@@ -46,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
14+
stable: bool = False
15+
debug: bool = False
16+
verbose: bool = False
17+
+ cflags: str = ""
18+
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
19+
20+
def _get_nop(self) -> bytes:
21+
@@ -119,6 +121,7 @@ async def _compile(
22+
) -> _stencils.StencilGroup:
23+
o = tempdir / f"{opname}.o"
24+
args = [
25+
+ *shlex.split(self.cflags),
26+
f"--target={self.triple}",
27+
"-DPy_BUILD_CORE_MODULE",
28+
"-D_DEBUG" if self.debug else "-DNDEBUG",
29+
diff --git a/Tools/jit/build.py b/Tools/jit/build.py
30+
index 49b08f477db..49a1b11de47 100644
31+
--- a/Tools/jit/build.py
32+
+++ b/Tools/jit/build.py
33+
@@ -26,11 +26,15 @@
34+
parser.add_argument(
35+
"-v", "--verbose", action="store_true", help="echo commands as they are run"
36+
)
37+
+ parser.add_argument(
38+
+ "--with-cflags", help="additional flags to pass to the compiler", default=""
39+
+ )
40+
args = parser.parse_args()
41+
for target in args.target:
42+
target.debug = args.debug
43+
target.force = args.force
44+
target.verbose = args.verbose
45+
+ target.cflags = args.with_cflags
46+
target.build(
47+
out,
48+
comment=comment,
49+
diff --git a/configure b/configure
50+
index c51192f12c8..0dcef7c2617 100755
51+
--- a/configure
52+
+++ b/configure
53+
@@ -10863,7 +10863,7 @@ then :
54+
55+
else case e in #(
56+
e) as_fn_append CFLAGS_NODIST " $jit_flags"
57+
- REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host}"
58+
+ REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-cflags=\"\$(CONFIGURE_CFLAGS)\""
59+
JIT_STENCILS_H="jit_stencils.h"
60+
if test "x$Py_DEBUG" = xtrue
61+
then :
62+
diff --git a/configure.ac b/configure.ac
63+
index a7b2f62579b..5998f896a4e 100644
64+
--- a/configure.ac
65+
+++ b/configure.ac
66+
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
67+
[],
68+
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
69+
AS_VAR_SET([REGEN_JIT_COMMAND],
70+
- ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host}"])
71+
+ ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --with-cflags=\"\$(CONFIGURE_CFLAGS)\""])
72+
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
73+
AS_VAR_IF([Py_DEBUG],
74+
[true],

0 commit comments

Comments
 (0)