mirror of
https://github.com/python/cpython.git
synced 2025-11-03 15:11:34 +00:00
GH-134273: Allow setting JIT compiler flags at build time with CFLAGS_JIT (GH134276)
This commit is contained in:
parent
73431356d3
commit
2b0c684e07
5 changed files with 12 additions and 2 deletions
|
|
@ -0,0 +1 @@
|
||||||
|
Add support for configuring compiler flags for the JIT with ``CFLAGS_JIT``
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import typing
|
import typing
|
||||||
|
import shlex
|
||||||
|
|
||||||
import _llvm
|
import _llvm
|
||||||
import _schema
|
import _schema
|
||||||
|
|
@ -46,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
|
||||||
stable: bool = False
|
stable: bool = False
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
verbose: bool = False
|
verbose: bool = False
|
||||||
|
cflags: str = ""
|
||||||
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
|
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
|
||||||
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
|
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
|
||||||
|
|
||||||
|
|
@ -62,6 +64,7 @@ def _compute_digest(self) -> str:
|
||||||
hasher = hashlib.sha256()
|
hasher = hashlib.sha256()
|
||||||
hasher.update(self.triple.encode())
|
hasher.update(self.triple.encode())
|
||||||
hasher.update(self.debug.to_bytes())
|
hasher.update(self.debug.to_bytes())
|
||||||
|
hasher.update(self.cflags.encode())
|
||||||
# These dependencies are also reflected in _JITSources in regen.targets:
|
# These dependencies are also reflected in _JITSources in regen.targets:
|
||||||
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
|
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
|
||||||
hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
|
hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
|
||||||
|
|
@ -155,6 +158,8 @@ async def _compile(
|
||||||
f"{o}",
|
f"{o}",
|
||||||
f"{c}",
|
f"{c}",
|
||||||
*self.args,
|
*self.args,
|
||||||
|
# Allow user-provided CFLAGS to override any defaults
|
||||||
|
*shlex.split(self.cflags),
|
||||||
]
|
]
|
||||||
await _llvm.run("clang", args, echo=self.verbose)
|
await _llvm.run("clang", args, echo=self.verbose)
|
||||||
return await self._parse(o)
|
return await self._parse(o)
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,15 @@
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--verbose", action="store_true", help="echo commands as they are run"
|
"-v", "--verbose", action="store_true", help="echo commands as they are run"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--cflags", help="additional flags to pass to the compiler", default=""
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
for target in args.target:
|
for target in args.target:
|
||||||
target.debug = args.debug
|
target.debug = args.debug
|
||||||
target.force = args.force
|
target.force = args.force
|
||||||
target.verbose = args.verbose
|
target.verbose = args.verbose
|
||||||
|
target.cflags = args.cflags
|
||||||
target.pyconfig_dir = args.pyconfig_dir
|
target.pyconfig_dir = args.pyconfig_dir
|
||||||
target.build(
|
target.build(
|
||||||
comment=comment,
|
comment=comment,
|
||||||
|
|
|
||||||
2
configure
generated
vendored
2
configure
generated
vendored
|
|
@ -10863,7 +10863,7 @@ then :
|
||||||
|
|
||||||
else case e in #(
|
else case e in #(
|
||||||
e) as_fn_append CFLAGS_NODIST " $jit_flags"
|
e) as_fn_append CFLAGS_NODIST " $jit_flags"
|
||||||
REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."
|
REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\""
|
||||||
JIT_STENCILS_H="jit_stencils.h"
|
JIT_STENCILS_H="jit_stencils.h"
|
||||||
if test "x$Py_DEBUG" = xtrue
|
if test "x$Py_DEBUG" = xtrue
|
||||||
then :
|
then :
|
||||||
|
|
|
||||||
|
|
@ -2776,7 +2776,7 @@ AS_VAR_IF([jit_flags],
|
||||||
[],
|
[],
|
||||||
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
|
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
|
||||||
AS_VAR_SET([REGEN_JIT_COMMAND],
|
AS_VAR_SET([REGEN_JIT_COMMAND],
|
||||||
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir ."])
|
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\""])
|
||||||
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
|
AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
|
||||||
AS_VAR_IF([Py_DEBUG],
|
AS_VAR_IF([Py_DEBUG],
|
||||||
[true],
|
[true],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue