Skip to content

Commit 348f2b6

Browse files
Fix event loop binding error for _CORES in FAT builds
1 parent 3bc2820 commit 348f2b6

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Tools/unicode/data/
137137
# hendrikmuhs/ccache-action@v1
138138
/.ccache
139139
/cross-build/
140-
/jit_stencils.h
140+
/jit_stencils*.h
141141
/platform
142142
/profile-clean-stamp
143143
/profile-run-stamp

Tools/jit/_llvm.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ async def wrapper(
3232
return wrapper
3333

3434

35-
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
35+
_CORES: asyncio.BoundedSemaphore | None = None
36+
37+
38+
def _get_cores() -> asyncio.BoundedSemaphore:
39+
global _CORES
40+
if _CORES is None:
41+
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
42+
return _CORES
3643

3744

3845
async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str | None:
3946
command = [tool, *args]
40-
async with _CORES:
47+
async with _get_cores():
4148
if echo:
4249
print(shlex.join(command))
4350
try:

Tools/jit/_targets.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
CPYTHON = TOOLS.parent
2626
PYTHON_EXECUTOR_CASES_C_H = CPYTHON / "Python" / "executor_cases.c.h"
2727
TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
28-
ASYNCIO_RUNNER = asyncio.Runner()
2928

3029
_S = typing.TypeVar("_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection)
3130
_R = typing.TypeVar(
@@ -45,7 +44,6 @@ class _Target(typing.Generic[_S, _R]):
4544
debug: bool = False
4645
verbose: bool = False
4746
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
48-
basename: str = ""
4947

5048
def _compute_digest(self, out: pathlib.Path) -> str:
5149
hasher = hashlib.sha256()
@@ -201,7 +199,7 @@ def build(
201199
and jit_stencils.read_text().startswith(digest)
202200
):
203201
return
204-
stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils())
202+
stencil_groups = asyncio.run(self._build_stencils())
205203
jit_stencils_new = out / "jit_stencils.h.new"
206204
try:
207205
with jit_stencils_new.open("w") as file:
@@ -506,9 +504,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
506504
target: _COFF | _ELF | _MachO
507505
if re.fullmatch(r"aarch64-apple-darwin.*", host):
508506
condition = "defined(__aarch64__) && defined(__APPLE__)"
509-
target = _MachO(
510-
host, condition, alignment=8, prefix="_", basename="aarch64-apple-darwin"
511-
)
507+
target = _MachO(host, condition, alignment=8, prefix="_")
512508
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
513509
args = ["-fms-runtime-lib=dll", "-fplt"]
514510
condition = "defined(_M_ARM64)"
@@ -532,7 +528,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
532528
target = _COFF(host, condition, args=args, prefix="_")
533529
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
534530
condition = "defined(__x86_64__) && defined(__APPLE__)"
535-
target = _MachO(host, condition, prefix="_", basename="x86_64-apple-darwin")
531+
target = _MachO(host, condition, prefix="_")
536532
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
537533
args = ["-fms-runtime-lib=dll"]
538534
condition = "defined(_M_X64)"

Tools/jit/build.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@
2626
"-v", "--verbose", action="store_true", help="echo commands as they are run"
2727
)
2828
args = parser.parse_args()
29-
print(args.target)
3029

3130
if len(args.target) == 1:
32-
# Single triple specified, assume this is a normal build
33-
target = args.target[0]
34-
target.debug = args.debug
35-
target.force = args.force
36-
target.verbose = args.verbose
37-
target.build(pathlib.Path.cwd(), comment=comment)
31+
args.target.debug = args.debug
32+
args.target.verbose = args.verbose
33+
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)
3834

3935
else:
40-
# Multiple triples specified, assume this is a macOS multi-architecture build
41-
# - Generate multiple stencil headers
42-
# - Generate a helper header that includes the stencils for the current
43-
# architecture.
36+
# Build for multiple targets (e.g. universal2)
4437
for target in args.target:
4538
target.debug = args.debug
4639
target.force = args.force
@@ -49,6 +42,7 @@
4942
pathlib.Path.cwd(),
5043
comment=comment,
5144
stencils_h=f"jit_stencils-{target.triple}.h",
45+
force=args.force,
5246
)
5347

5448
with open("jit_stencils.h", "w") as fp:
@@ -57,5 +51,5 @@
5751
fp.write(f'# include "jit_stencils-{target.triple}.h"\n')
5852

5953
fp.write("#else\n")
60-
fp.write('# error "unexpected cpu type"\n')
54+
fp.write('# error "unexpected target"\n')
6155
fp.write("#endif\n")

0 commit comments

Comments
 (0)