Skip to content

Commit d791841

Browse files
committed
Fix Windows builds
1 parent de70614 commit d791841

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

PCbuild/regen.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@
125125
<JITArgs Condition="$(Platform) == 'x64'">x86_64-pc-windows-msvc</JITArgs>
126126
<JITArgs Condition="$(Configuration) == 'Debug'">$(JITArgs) --debug</JITArgs>
127127
</PropertyGroup>
128-
<Exec Command='$(PythonForBuild) "$(PySourcePath)Tools\jit\build.py" $(JITArgs)'
129-
WorkingDirectory="$(GeneratedJitStencilsDir)"/>
128+
<Exec Command='$(PythonForBuild) "$(PySourcePath)Tools\jit\build.py" $(JITArgs) --output-dir "$(GeneratedJitStencilsDir)" --pyconfig-dir "$(PySourcePath)PC"'/>
130129
</Target>
131130
<Target Name="_CleanJIT" AfterTargets="Clean">
132131
<Delete Files="@(_JITOutputs)"/>

Tools/jit/_targets.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class _Target(typing.Generic[_S, _R]):
4747
debug: bool = False
4848
verbose: bool = False
4949
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
50+
pyconfig: pathlib.Path | None = None
5051

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

60-
def _compute_digest(self, out: pathlib.Path) -> str:
61+
def _compute_digest(self) -> str:
6162
hasher = hashlib.sha256()
6263
hasher.update(self.triple.encode())
6364
hasher.update(self.debug.to_bytes())
6465
# These dependencies are also reflected in _JITSources in regen.targets:
6566
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
66-
hasher.update((out / "pyconfig.h").read_bytes())
67+
assert self.pyconfig is not None
68+
hasher.update(self.pyconfig.read_bytes())
6769
for dirpath, _, filenames in sorted(os.walk(TOOLS_JIT)):
6870
for filename in filenames:
6971
hasher.update(pathlib.Path(dirpath, filename).read_bytes())
@@ -118,14 +120,15 @@ async def _compile(
118120
self, opname: str, c: pathlib.Path, tempdir: pathlib.Path
119121
) -> _stencils.StencilGroup:
120122
o = tempdir / f"{opname}.o"
123+
assert self.pyconfig is not None
121124
args = [
122125
f"--target={self.triple}",
123126
"-DPy_BUILD_CORE_MODULE",
124127
"-D_DEBUG" if self.debug else "-DNDEBUG",
125128
f"-D_JIT_OPCODE={opname}",
126129
"-D_PyJIT_ACTIVE",
127130
"-D_Py_JIT",
128-
"-I.",
131+
f"-I{self.pyconfig.parent}",
129132
f"-I{CPYTHON / 'Include'}",
130133
f"-I{CPYTHON / 'Include' / 'internal'}",
131134
f"-I{CPYTHON / 'Include' / 'internal' / 'mimalloc'}",
@@ -193,28 +196,27 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
193196

194197
def build(
195198
self,
196-
out: pathlib.Path,
197199
*,
198200
comment: str = "",
199201
force: bool = False,
200-
stencils_h: str = "jit_stencils.h",
202+
jit_stencils: pathlib.Path,
201203
) -> None:
202204
"""Build jit_stencils.h in the given directory."""
205+
jit_stencils.parent.mkdir(parents=True, exist_ok=True)
203206
if not self.stable:
204207
warning = f"JIT support for {self.triple} is still experimental!"
205208
request = "Please report any issues you encounter.".center(len(warning))
206209
outline = "=" * len(warning)
207210
print("\n".join(["", outline, warning, request, outline, ""]))
208-
digest = f"// {self._compute_digest(out)}\n"
209-
jit_stencils = out / stencils_h
211+
digest = f"// {self._compute_digest()}\n"
210212
if (
211213
not force
212214
and jit_stencils.exists()
213215
and jit_stencils.read_text().startswith(digest)
214216
):
215217
return
216218
stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils())
217-
jit_stencils_new = out / "jit_stencils.h.new"
219+
jit_stencils_new = jit_stencils.parent / "jit_stencils.h.new"
218220
try:
219221
with jit_stencils_new.open("w") as file:
220222
file.write(digest)

Tools/jit/build.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import _targets
99

1010
if __name__ == "__main__":
11-
out = pathlib.Path.cwd().resolve()
1211
comment = f"$ {shlex.join([pathlib.Path(sys.executable).name] + sys.argv)}"
1312
parser = argparse.ArgumentParser(description=__doc__)
1413
parser.add_argument(
@@ -23,6 +22,12 @@
2322
parser.add_argument(
2423
"-f", "--force", action="store_true", help="force the entire JIT to be rebuilt"
2524
)
25+
parser.add_argument(
26+
"-o", "--output-dir", help="where to output generated files", required=True, type=lambda p: pathlib.Path(p).resolve()
27+
)
28+
parser.add_argument(
29+
"-p", "--pyconfig-dir", help="where to find pyconfig.h", required=True, type=lambda p: pathlib.Path(p).resolve()
30+
)
2631
parser.add_argument(
2732
"-v", "--verbose", action="store_true", help="echo commands as they are run"
2833
)
@@ -31,13 +36,13 @@
3136
target.debug = args.debug
3237
target.force = args.force
3338
target.verbose = args.verbose
39+
target.pyconfig=args.pyconfig_dir / "pyconfig.h"
3440
target.build(
35-
out,
3641
comment=comment,
37-
stencils_h=f"jit_stencils-{target.triple}.h",
3842
force=args.force,
43+
jit_stencils=args.output_dir / f"jit_stencils-{target.triple}.h",
3944
)
40-
jit_stencils_h = out / "jit_stencils.h"
45+
jit_stencils_h = args.output_dir / "jit_stencils.h"
4146
lines = [f"// {comment}\n"]
4247
guard = "#if"
4348
for target in args.target:

0 commit comments

Comments
 (0)