Skip to content

Commit 58e1c7a

Browse files
Introduce build-python and build-host subcommands for Tools/wasm/wasi (GH-142266)
It should make it easier when you need to rebuild just the e.g. host Python, but it requires ./configure to run. Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent dcac498 commit 58e1c7a

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

Tools/wasm/wasi/__main__.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,6 @@ def make_wasi_python(context, working_dir):
386386
)
387387

388388

389-
def build_all(context):
390-
"""Build everything."""
391-
steps = [
392-
configure_build_python,
393-
make_build_python,
394-
configure_wasi_python,
395-
make_wasi_python,
396-
]
397-
for step in steps:
398-
step(context)
399-
400-
401389
def clean_contents(context):
402390
"""Delete all files created by this script."""
403391
if CROSS_BUILD_DIR.exists():
@@ -409,6 +397,16 @@ def clean_contents(context):
409397
log("🧹", f"Deleting generated {LOCAL_SETUP} ...")
410398

411399

400+
def build_steps(*steps):
401+
"""Construct a command from other steps."""
402+
403+
def builder(context):
404+
for step in steps:
405+
step(context)
406+
407+
return builder
408+
409+
412410
def main():
413411
default_host_triple = "wasm32-wasip1"
414412
default_wasi_sdk = find_wasi_sdk()
@@ -438,6 +436,9 @@ def main():
438436
make_build = subcommands.add_parser(
439437
"make-build-python", help="Run `make` for the build Python"
440438
)
439+
build_python = subcommands.add_parser(
440+
"build-python", help="Build the build Python"
441+
)
441442
configure_host = subcommands.add_parser(
442443
"configure-host",
443444
help="Run `configure` for the "
@@ -448,15 +449,20 @@ def main():
448449
make_host = subcommands.add_parser(
449450
"make-host", help="Run `make` for the host/WASI"
450451
)
452+
build_host = subcommands.add_parser(
453+
"build-host", help="Build the host/WASI Python"
454+
)
451455
subcommands.add_parser(
452456
"clean", help="Delete files and directories created by this script"
453457
)
454458
for subcommand in (
455459
build,
456460
configure_build,
457461
make_build,
462+
build_python,
458463
configure_host,
459464
make_host,
465+
build_host,
460466
):
461467
subcommand.add_argument(
462468
"--quiet",
@@ -471,19 +477,30 @@ def main():
471477
default=default_logdir,
472478
help=f"Directory to store log files; defaults to {default_logdir}",
473479
)
474-
for subcommand in configure_build, configure_host:
480+
for subcommand in (
481+
configure_build,
482+
configure_host,
483+
build_python,
484+
build_host,
485+
):
475486
subcommand.add_argument(
476487
"--clean",
477488
action="store_true",
478489
default=False,
479490
dest="clean",
480491
help="Delete any relevant directories before building",
481492
)
482-
for subcommand in build, configure_build, configure_host:
493+
for subcommand in (
494+
build,
495+
configure_build,
496+
configure_host,
497+
build_python,
498+
build_host,
499+
):
483500
subcommand.add_argument(
484501
"args", nargs="*", help="Extra arguments to pass to `configure`"
485502
)
486-
for subcommand in build, configure_host:
503+
for subcommand in build, configure_host, build_host:
487504
subcommand.add_argument(
488505
"--wasi-sdk",
489506
type=pathlib.Path,
@@ -499,7 +516,7 @@ def main():
499516
help="Command template for running the WASI host; defaults to "
500517
f"`{default_host_runner}`",
501518
)
502-
for subcommand in build, configure_host, make_host:
519+
for subcommand in build, configure_host, make_host, build_host:
503520
subcommand.add_argument(
504521
"--host-triple",
505522
action="store",
@@ -511,12 +528,17 @@ def main():
511528
context = parser.parse_args()
512529
context.init_dir = pathlib.Path().absolute()
513530

531+
build_build_python = build_steps(configure_build_python, make_build_python)
532+
build_wasi_python = build_steps(configure_wasi_python, make_wasi_python)
533+
514534
dispatch = {
515535
"configure-build-python": configure_build_python,
516536
"make-build-python": make_build_python,
537+
"build-python": build_build_python,
517538
"configure-host": configure_wasi_python,
518539
"make-host": make_wasi_python,
519-
"build": build_all,
540+
"build-host": build_wasi_python,
541+
"build": build_steps(build_build_python, build_wasi_python),
520542
"clean": clean_contents,
521543
}
522544
dispatch[context.subcommand](context)

0 commit comments

Comments
 (0)