Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix Windows builds
  • Loading branch information
brandtbucher committed May 19, 2025
commit d79184190286d507f0d9bc64fb9f1ac03d2e512a
3 changes: 1 addition & 2 deletions PCbuild/regen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@
<JITArgs Condition="$(Platform) == 'x64'">x86_64-pc-windows-msvc</JITArgs>
<JITArgs Condition="$(Configuration) == 'Debug'">$(JITArgs) --debug</JITArgs>
</PropertyGroup>
<Exec Command='$(PythonForBuild) "$(PySourcePath)Tools\jit\build.py" $(JITArgs)'
WorkingDirectory="$(GeneratedJitStencilsDir)"/>
<Exec Command='$(PythonForBuild) "$(PySourcePath)Tools\jit\build.py" $(JITArgs) --output-dir "$(GeneratedJitStencilsDir)" --pyconfig-dir "$(PySourcePath)PC"'/>
</Target>
<Target Name="_CleanJIT" AfterTargets="Clean">
<Delete Files="@(_JITOutputs)"/>
Expand Down
18 changes: 10 additions & 8 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
debug: bool = False
verbose: bool = False
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
pyconfig: pathlib.Path | None = None

def _get_nop(self) -> bytes:
if re.fullmatch(r"aarch64-.*", self.triple):
Expand All @@ -57,13 +58,14 @@ def _get_nop(self) -> bytes:
raise ValueError(f"NOP not defined for {self.triple}")
return nop

def _compute_digest(self, out: pathlib.Path) -> str:
def _compute_digest(self) -> str:
hasher = hashlib.sha256()
hasher.update(self.triple.encode())
hasher.update(self.debug.to_bytes())
# These dependencies are also reflected in _JITSources in regen.targets:
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
hasher.update((out / "pyconfig.h").read_bytes())
assert self.pyconfig is not None
hasher.update(self.pyconfig.read_bytes())
for dirpath, _, filenames in sorted(os.walk(TOOLS_JIT)):
for filename in filenames:
hasher.update(pathlib.Path(dirpath, filename).read_bytes())
Expand Down Expand Up @@ -118,14 +120,15 @@ async def _compile(
self, opname: str, c: pathlib.Path, tempdir: pathlib.Path
) -> _stencils.StencilGroup:
o = tempdir / f"{opname}.o"
assert self.pyconfig is not None
args = [
f"--target={self.triple}",
"-DPy_BUILD_CORE_MODULE",
"-D_DEBUG" if self.debug else "-DNDEBUG",
f"-D_JIT_OPCODE={opname}",
"-D_PyJIT_ACTIVE",
"-D_Py_JIT",
"-I.",
f"-I{self.pyconfig.parent}",
f"-I{CPYTHON / 'Include'}",
f"-I{CPYTHON / 'Include' / 'internal'}",
f"-I{CPYTHON / 'Include' / 'internal' / 'mimalloc'}",
Expand Down Expand Up @@ -193,28 +196,27 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:

def build(
self,
out: pathlib.Path,
*,
comment: str = "",
force: bool = False,
stencils_h: str = "jit_stencils.h",
jit_stencils: pathlib.Path,
) -> None:
"""Build jit_stencils.h in the given directory."""
jit_stencils.parent.mkdir(parents=True, exist_ok=True)
if not self.stable:
warning = f"JIT support for {self.triple} is still experimental!"
request = "Please report any issues you encounter.".center(len(warning))
outline = "=" * len(warning)
print("\n".join(["", outline, warning, request, outline, ""]))
digest = f"// {self._compute_digest(out)}\n"
jit_stencils = out / stencils_h
digest = f"// {self._compute_digest()}\n"
if (
not force
and jit_stencils.exists()
and jit_stencils.read_text().startswith(digest)
):
return
stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils())
jit_stencils_new = out / "jit_stencils.h.new"
jit_stencils_new = jit_stencils.parent / "jit_stencils.h.new"
try:
with jit_stencils_new.open("w") as file:
file.write(digest)
Expand Down
13 changes: 9 additions & 4 deletions Tools/jit/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import _targets

if __name__ == "__main__":
out = pathlib.Path.cwd().resolve()
comment = f"$ {shlex.join([pathlib.Path(sys.executable).name] + sys.argv)}"
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
Expand All @@ -23,6 +22,12 @@
parser.add_argument(
"-f", "--force", action="store_true", help="force the entire JIT to be rebuilt"
)
parser.add_argument(
"-o", "--output-dir", help="where to output generated files", required=True, type=lambda p: pathlib.Path(p).resolve()
)
parser.add_argument(
"-p", "--pyconfig-dir", help="where to find pyconfig.h", required=True, type=lambda p: pathlib.Path(p).resolve()
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="echo commands as they are run"
)
Expand All @@ -31,13 +36,13 @@
target.debug = args.debug
target.force = args.force
target.verbose = args.verbose
target.pyconfig=args.pyconfig_dir / "pyconfig.h"
target.build(
out,
comment=comment,
stencils_h=f"jit_stencils-{target.triple}.h",
force=args.force,
jit_stencils=args.output_dir / f"jit_stencils-{target.triple}.h",
)
jit_stencils_h = out / "jit_stencils.h"
jit_stencils_h = args.output_dir / "jit_stencils.h"
lines = [f"// {comment}\n"]
guard = "#if"
for target in args.target:
Expand Down