Skip to content

Commit b606b48

Browse files
Fix up to make generic
1 parent bce7980 commit b606b48

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Tools/jit/_targets.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,24 +518,31 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
518518
# ghccc currently crashes Clang when combined with musttail on aarch64. :(
519519
target: _COFF | _ELF | _MachO
520520
if re.fullmatch(r"aarch64-apple-darwin.*", host):
521-
target = _MachO(host, alignment=8, prefix="_")
521+
condition = "defined(__aarch64__)" and "defined(__APPLE__)"
522+
target = _MachO(host, condition, alignment=8, prefix="_")
522523
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
523524
args = ["-fms-runtime-lib=dll"]
524-
target = _COFF(host, alignment=8, args=args)
525+
condition = "defined(_M_ARM64)"
526+
target = _COFF(host, condition, alignment=8, args=args)
525527
elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
526528
args = ["-fpic"]
527-
target = _ELF(host, alignment=8, args=args)
529+
condition = "defined(__aarch64__)" and "defined(__linux__)"
530+
target = _ELF(host, condition, alignment=8, args=args)
528531
elif re.fullmatch(r"i686-pc-windows-msvc", host):
529532
args = ["-DPy_NO_ENABLE_SHARED"]
530-
target = _COFF(host, args=args, ghccc=True, prefix="_")
533+
condition = "defined(_M_IX86)"
534+
target = _COFF(host, condition, args=args, ghccc=True, prefix="_")
531535
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
532-
target = _MachO(host, ghccc=True, prefix="_")
536+
condition = "defined(__x86_64__)" and "defined(__APPLE__)"
537+
target = _MachO(host, condition, ghccc=True, prefix="_")
533538
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
534539
args = ["-fms-runtime-lib=dll"]
535-
target = _COFF(host, args=args, ghccc=True)
540+
condition = "defined(_M_X64)"
541+
target = _COFF(host, condition, args=args, ghccc=True)
536542
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
537543
args = ["-fpic"]
538-
target = _ELF(host, args=args, ghccc=True)
544+
condition = "defined(__x86_64__)" and "defined(__linux__)"
545+
target = _ELF(host, condition, args=args, ghccc=True)
539546
else:
540547
raise ValueError(host)
541548
return target

Tools/jit/build.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
args.target.build(pathlib.Path.cwd(), comment=comment)
3232

3333
else:
34-
# Multiple triples specified, assume this is a macOS multiarchitecture build
34+
# Multiple triples specified, assume this is a macOS multi-architecture build
3535
# - Generate multiple stencil headers
36-
# - Generate a helper header that include sthe stencils for the current
36+
# - Generate a helper header that includes the stencils for the current
3737
# architecture.
3838
for target in args.target:
3939
target.debug = args.debug
@@ -43,8 +43,7 @@
4343

4444
with open("jit_stencils.h", "w") as fp:
4545
for idx, target in enumerate(args.target):
46-
cpu, _, _ = target.triple.partition("-")
47-
fp.write(f"#{'if' if idx == 0 else 'elif'} defined(__{cpu}__)\n")
46+
fp.write(f"#{'if' if idx == 0 else 'elif'} defined(__{target.condition}__)\n")
4847
fp.write(f'# include "jit_stencils-{target.triple}.h"\n')
4948

5049
fp.write("#else\n")

0 commit comments

Comments
 (0)