Skip to content

Commit a8091a7

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

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
2+
index b3b065652e0..d361f57382e 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+
@@ -42,6 +43,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+
@@ -115,6 +117,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 a8cb0f67c36..663874ad439 100644
31+
--- a/Tools/jit/build.py
32+
+++ b/Tools/jit/build.py
33+
@@ -22,7 +22,11 @@
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+
args.target.debug = args.debug
42+
args.target.verbose = args.verbose
43+
+ args.target.cflags = args.with_cflags
44+
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)
45+
diff --git a/configure b/configure
46+
index 1b75ddfa26d..3c9e550b5d3 100755
47+
--- a/configure
48+
+++ b/configure
49+
@@ -8399,7 +8399,7 @@ then :
50+
51+
else case e in #(
52+
e) as_fn_append CFLAGS_NODIST " $jit_flags"
53+
- REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py $host"
54+
+ REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py $host --with-cflags=\"\$(CONFIGURE_CFLAGS)\""
55+
JIT_STENCILS_H="jit_stencils.h"
56+
if test "x$Py_DEBUG" = xtrue
57+
then :
58+
diff --git a/configure.ac b/configure.ac
59+
index c449bb5ebb3..5f9d08a4ee7 100644
60+
--- a/configure.ac
61+
+++ b/configure.ac
62+
@@ -1827,7 +1827,7 @@ AS_VAR_IF([jit_flags],
63+
[],
64+
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
65+
AS_VAR_SET([REGEN_JIT_COMMAND],
66+
- ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py $host"])
67+
+ ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py $host --with-cflags=\"\$(CONFIGURE_CFLAGS)\""])
68+
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
69+
AS_VAR_IF([Py_DEBUG],
70+
[true],

0 commit comments

Comments
 (0)