Skip to content

Commit 2b0c684

Browse files
authored
GH-134273: Allow setting JIT compiler flags at build time with CFLAGS_JIT (GH134276)
1 parent 7343135 commit 2b0c684

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT``

Tools/jit/_targets.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import tempfile
1212
import typing
13+
import shlex
1314

1415
import _llvm
1516
import _schema
@@ -46,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
4647
stable: bool = False
4748
debug: bool = False
4849
verbose: bool = False
50+
cflags: str = ""
4951
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
5052
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
5153

@@ -62,6 +64,7 @@ def _compute_digest(self) -> str:
6264
hasher = hashlib.sha256()
6365
hasher.update(self.triple.encode())
6466
hasher.update(self.debug.to_bytes())
67+
hasher.update(self.cflags.encode())
6568
# These dependencies are also reflected in _JITSources in regen.targets:
6669
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
6770
hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
@@ -155,6 +158,8 @@ async def _compile(
155158
f"{o}",
156159
f"{c}",
157160
*self.args,
161+
# Allow user-provided CFLAGS to override any defaults
162+
*shlex.split(self.cflags),
158163
]
159164
await _llvm.run("clang", args, echo=self.verbose)
160165
return await self._parse(o)

Tools/jit/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@
3939
parser.add_argument(
4040
"-v", "--verbose", action="store_true", help="echo commands as they are run"
4141
)
42+
parser.add_argument(
43+
"--cflags", help="additional flags to pass to the compiler", default=""
44+
)
4245
args = parser.parse_args()
4346
for target in args.target:
4447
target.debug = args.debug
4548
target.force = args.force
4649
target.verbose = args.verbose
50+
target.cflags = args.cflags
4751
target.pyconfig_dir = args.pyconfig_dir
4852
target.build(
4953
comment=comment,

configure

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
27762776
[],
27772777
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
27782778
AS_VAR_SET([REGEN_JIT_COMMAND],
2779-
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."])
2779+
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\""])
27802780
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
27812781
AS_VAR_IF([Py_DEBUG],
27822782
[true],

0 commit comments

Comments
 (0)