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``
1
8
diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py
2
- index d0a1c081ffe..deb83f275d2 100644
9
+ index d0a1c081ffe..b383e39da19 100644
3
10
--- a/Tools/jit/_targets.py
4
11
+++ b/Tools/jit/_targets.py
5
12
@@ -10,6 +10,7 @@
@@ -18,57 +25,66 @@ index d0a1c081ffe..deb83f275d2 100644
18
25
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
19
26
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
20
27
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
25
41
+ *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)
29
45
diff --git a/Tools/jit/build.py b/Tools/jit/build.py
30
- index 1afd0c76bad..96c4cb07593 100644
46
+ index 1afd0c76bad..a0733005929 100644
31
47
--- a/Tools/jit/build.py
32
48
+++ b/Tools/jit/build.py
33
49
@@ -39,11 +39,15 @@
34
50
parser.add_argument(
35
51
"-v", "--verbose", action="store_true", help="echo commands as they are run"
36
52
)
37
53
+ 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=""
39
55
+ )
40
56
args = parser.parse_args()
41
57
for target in args.target:
42
58
target.debug = args.debug
43
59
target.force = args.force
44
60
target.verbose = args.verbose
45
- + target.cflags = args.with_cflags
61
+ + target.cflags = args.cflags
46
62
target.pyconfig_dir = args.pyconfig_dir
47
63
target.build(
48
64
comment=comment,
49
65
diff --git a/configure b/configure
50
- index 884f8a4b068..2e6740c33d9 100755
66
+ index 029bf527da4..fef9f2d7da9 100755
51
67
--- a/configure
52
68
+++ b/configure
53
69
@@ -10863,7 +10863,7 @@ then :
54
70
55
71
else case e in #(
56
72
e) as_fn_append CFLAGS_NODIST " $jit_flags"
57
73
- 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 \""
59
75
JIT_STENCILS_H="jit_stencils.h"
60
76
if test "x$Py_DEBUG" = xtrue
61
77
then :
62
78
diff --git a/configure.ac b/configure.ac
63
- index cf25148bad2..f8bfab7bf96 100644
79
+ index 371b2e8ed73..cc37a636c52 100644
64
80
--- a/configure.ac
65
81
+++ b/configure.ac
66
82
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
67
83
[],
68
84
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
69
85
AS_VAR_SET([REGEN_JIT_COMMAND],
70
86
- ["\$(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 \""])
72
88
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
73
89
AS_VAR_IF([Py_DEBUG],
74
90
[true],
0 commit comments