@@ -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 )
0 commit comments