25
25
CPYTHON = TOOLS .parent
26
26
PYTHON_EXECUTOR_CASES_C_H = CPYTHON / "Python" / "executor_cases.c.h"
27
27
TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
28
+ ASYNCIO_RUNNER = asyncio .Runner ()
28
29
29
30
_S = typing .TypeVar ("_S" , _schema .COFFSection , _schema .ELFSection , _schema .MachOSection )
30
31
_R = typing .TypeVar (
35
36
@dataclasses .dataclass
36
37
class _Target (typing .Generic [_S , _R ]):
37
38
triple : str
39
+ condition : str
38
40
_ : dataclasses .KW_ONLY
39
41
alignment : int = 1
40
42
args : typing .Sequence [str ] = ()
@@ -188,7 +190,12 @@ async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]:
188
190
return stencil_groups
189
191
190
192
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" ,
192
199
) -> None :
193
200
"""Build jit_stencils.h in the given directory."""
194
201
if not self .stable :
@@ -197,14 +204,14 @@ def build(
197
204
outline = "=" * len (warning )
198
205
print ("\n " .join (["" , outline , warning , request , outline , "" ]))
199
206
digest = f"// { self ._compute_digest (out )} \n "
200
- jit_stencils = out / "jit_stencils.h"
207
+ jit_stencils = out / stencils_h
201
208
if (
202
209
not force
203
210
and jit_stencils .exists ()
204
211
and jit_stencils .read_text ().startswith (digest )
205
212
):
206
213
return
207
- stencil_groups = asyncio .run (self ._build_stencils ())
214
+ stencil_groups = ASYNCIO_RUNNER .run (self ._build_stencils ())
208
215
jit_stencils_new = out / "jit_stencils.h.new"
209
216
try :
210
217
with jit_stencils_new .open ("w" ) as file :
@@ -512,33 +519,40 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
512
519
"""Build a _Target for the given host "triple" and options."""
513
520
target : _COFF | _ELF | _MachO
514
521
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 = "_" )
516
524
elif re .fullmatch (r"aarch64-pc-windows-msvc" , host ):
517
525
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 )
519
528
elif re .fullmatch (r"aarch64-.*-linux-gnu" , host ):
520
529
args = [
521
530
"-fpic" ,
522
531
# On aarch64 Linux, intrinsics were being emitted and this flag
523
532
# was required to disable them.
524
533
"-mno-outline-atomics" ,
525
534
]
526
- target = _ELF (host , alignment = 8 , args = args )
535
+ condition = "defined(__aarch64__) && defined(__linux__)"
536
+ target = _ELF (host , condition , alignment = 8 , args = args )
527
537
elif re .fullmatch (r"i686-pc-windows-msvc" , host ):
528
538
args = [
529
539
"-DPy_NO_ENABLE_SHARED" ,
530
540
# __attribute__((preserve_none)) is not supported
531
541
"-Wno-ignored-attributes" ,
532
542
]
533
- target = _COFF (host , args = args , prefix = "_" )
543
+ condition = "defined(_M_IX86)"
544
+ target = _COFF (host , condition , args = args , prefix = "_" )
534
545
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 = "_" )
536
548
elif re .fullmatch (r"x86_64-pc-windows-msvc" , host ):
537
549
args = ["-fms-runtime-lib=dll" ]
538
- target = _COFF (host , args = args )
550
+ condition = "defined(_M_X64)"
551
+ target = _COFF (host , condition , args = args )
539
552
elif re .fullmatch (r"x86_64-.*-linux-gnu" , host ):
540
553
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 )
542
556
else :
543
557
raise ValueError (host )
544
558
return target
0 commit comments