2525CPYTHON = TOOLS .parent
2626PYTHON_EXECUTOR_CASES_C_H = CPYTHON / "Python" / "executor_cases.c.h"
2727TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
28+ ASYNCIO_RUNNER = asyncio .Runner ()
2829
2930_S = typing .TypeVar ("_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection )
3031_R = typing .TypeVar (
3536@dataclasses .dataclass
3637class _Target (typing .Generic [_S , _R ]):
3738 triple : str
39+ condition : str
3840 _ : dataclasses .KW_ONLY
3941 alignment : int = 1
4042 args : typing .Sequence [str ] = ()
@@ -188,7 +190,12 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
188190 return stencil_groups
189191
190192 def build (
191- self , out : pathlib .Path , * , comment : str = "" , force : bool = False
193+ self ,
194+ out : pathlib .Path ,
195+ * ,
196+ comment : str = "" ,
197+ force : bool = False ,
198+ stencils_h : str = "jit_stencils.h" ,
192199 ) -> None :
193200 """Build jit_stencils.h in the given directory."""
194201 if not self .stable :
@@ -197,14 +204,14 @@ def build(
197204 outline = "=" * len (warning )
198205 print ("\n " .join (["" , outline , warning , request , outline , "" ]))
199206 digest = f"// { self ._compute_digest (out )} \n "
200- jit_stencils = out / "jit_stencils.h"
207+ jit_stencils = out / stencils_h
201208 if (
202209 not force
203210 and jit_stencils .exists ()
204211 and jit_stencils .read_text ().startswith (digest )
205212 ):
206213 return
207- stencil_groups = asyncio .run (self ._build_stencils ())
214+ stencil_groups = ASYNCIO_RUNNER .run (self ._build_stencils ())
208215 jit_stencils_new = out / "jit_stencils.h.new"
209216 try :
210217 with jit_stencils_new .open ("w" ) as file :
@@ -512,33 +519,40 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
512519 """Build a _Target for the given host "triple" and options."""
513520 target : _COFF | _ELF | _MachO
514521 if re .fullmatch (r"aarch64-apple-darwin.*" , host ):
515- target = _MachO (host , alignment = 8 , prefix = "_" )
522+ condition = "defined(__aarch64__) && defined(__APPLE__)"
523+ target = _MachO (host , condition , alignment = 8 , prefix = "_" )
516524 elif re .fullmatch (r"aarch64-pc-windows-msvc" , host ):
517525 args = ["-fms-runtime-lib=dll" , "-fplt" ]
518- target = _COFF (host , alignment = 8 , args = args )
526+ condition = "defined(_M_ARM64)"
527+ target = _COFF (host , condition , alignment = 8 , args = args )
519528 elif re .fullmatch (r"aarch64-.*-linux-gnu" , host ):
520529 args = [
521530 "-fpic" ,
522531 # On aarch64 Linux, intrinsics were being emitted and this flag
523532 # was required to disable them.
524533 "-mno-outline-atomics" ,
525534 ]
526- target = _ELF (host , alignment = 8 , args = args )
535+ condition = "defined(__aarch64__) && defined(__linux__)"
536+ target = _ELF (host , condition , alignment = 8 , args = args )
527537 elif re .fullmatch (r"i686-pc-windows-msvc" , host ):
528538 args = [
529539 "-DPy_NO_ENABLE_SHARED" ,
530540 # __attribute__((preserve_none)) is not supported
531541 "-Wno-ignored-attributes" ,
532542 ]
533- target = _COFF (host , args = args , prefix = "_" )
543+ condition = "defined(_M_IX86)"
544+ target = _COFF (host , condition , args = args , prefix = "_" )
534545 elif re .fullmatch (r"x86_64-apple-darwin.*" , host ):
535- target = _MachO (host , prefix = "_" )
546+ condition = "defined(__x86_64__) && defined(__APPLE__)"
547+ target = _MachO (host , condition , prefix = "_" )
536548 elif re .fullmatch (r"x86_64-pc-windows-msvc" , host ):
537549 args = ["-fms-runtime-lib=dll" ]
538- target = _COFF (host , args = args )
550+ condition = "defined(_M_X64)"
551+ target = _COFF (host , condition , args = args )
539552 elif re .fullmatch (r"x86_64-.*-linux-gnu" , host ):
540553 args = ["-fno-pic" , "-mcmodel=medium" , "-mlarge-data-threshold=0" ]
541- target = _ELF (host , args = args )
554+ condition = "defined(__x86_64__) && defined(__linux__)"
555+ target = _ELF (host , condition , args = args )
542556 else :
543557 raise ValueError (host )
544558 return target
0 commit comments