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>
This commit is contained in:
Brett Cannon 2025-12-05 13:35:50 -08:00 committed by GitHub
parent dcac498e50
commit 58e1c7a16f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -386,18 +386,6 @@ def make_wasi_python(context, working_dir):
) )
def build_all(context):
"""Build everything."""
steps = [
configure_build_python,
make_build_python,
configure_wasi_python,
make_wasi_python,
]
for step in steps:
step(context)
def clean_contents(context): def clean_contents(context):
"""Delete all files created by this script.""" """Delete all files created by this script."""
if CROSS_BUILD_DIR.exists(): if CROSS_BUILD_DIR.exists():
@ -409,6 +397,16 @@ def clean_contents(context):
log("🧹", f"Deleting generated {LOCAL_SETUP} ...") log("🧹", f"Deleting generated {LOCAL_SETUP} ...")
def build_steps(*steps):
"""Construct a command from other steps."""
def builder(context):
for step in steps:
step(context)
return builder
def main(): def main():
default_host_triple = "wasm32-wasip1" default_host_triple = "wasm32-wasip1"
default_wasi_sdk = find_wasi_sdk() default_wasi_sdk = find_wasi_sdk()
@ -438,6 +436,9 @@ def main():
make_build = subcommands.add_parser( make_build = subcommands.add_parser(
"make-build-python", help="Run `make` for the build Python" "make-build-python", help="Run `make` for the build Python"
) )
build_python = subcommands.add_parser(
"build-python", help="Build the build Python"
)
configure_host = subcommands.add_parser( configure_host = subcommands.add_parser(
"configure-host", "configure-host",
help="Run `configure` for the " help="Run `configure` for the "
@ -448,6 +449,9 @@ def main():
make_host = subcommands.add_parser( make_host = subcommands.add_parser(
"make-host", help="Run `make` for the host/WASI" "make-host", help="Run `make` for the host/WASI"
) )
build_host = subcommands.add_parser(
"build-host", help="Build the host/WASI Python"
)
subcommands.add_parser( subcommands.add_parser(
"clean", help="Delete files and directories created by this script" "clean", help="Delete files and directories created by this script"
) )
@ -455,8 +459,10 @@ def main():
build, build,
configure_build, configure_build,
make_build, make_build,
build_python,
configure_host, configure_host,
make_host, make_host,
build_host,
): ):
subcommand.add_argument( subcommand.add_argument(
"--quiet", "--quiet",
@ -471,7 +477,12 @@ def main():
default=default_logdir, default=default_logdir,
help=f"Directory to store log files; defaults to {default_logdir}", help=f"Directory to store log files; defaults to {default_logdir}",
) )
for subcommand in configure_build, configure_host: for subcommand in (
configure_build,
configure_host,
build_python,
build_host,
):
subcommand.add_argument( subcommand.add_argument(
"--clean", "--clean",
action="store_true", action="store_true",
@ -479,11 +490,17 @@ def main():
dest="clean", dest="clean",
help="Delete any relevant directories before building", help="Delete any relevant directories before building",
) )
for subcommand in build, configure_build, configure_host: for subcommand in (
build,
configure_build,
configure_host,
build_python,
build_host,
):
subcommand.add_argument( subcommand.add_argument(
"args", nargs="*", help="Extra arguments to pass to `configure`" "args", nargs="*", help="Extra arguments to pass to `configure`"
) )
for subcommand in build, configure_host: for subcommand in build, configure_host, build_host:
subcommand.add_argument( subcommand.add_argument(
"--wasi-sdk", "--wasi-sdk",
type=pathlib.Path, type=pathlib.Path,
@ -499,7 +516,7 @@ def main():
help="Command template for running the WASI host; defaults to " help="Command template for running the WASI host; defaults to "
f"`{default_host_runner}`", f"`{default_host_runner}`",
) )
for subcommand in build, configure_host, make_host: for subcommand in build, configure_host, make_host, build_host:
subcommand.add_argument( subcommand.add_argument(
"--host-triple", "--host-triple",
action="store", action="store",
@ -511,12 +528,17 @@ def main():
context = parser.parse_args() context = parser.parse_args()
context.init_dir = pathlib.Path().absolute() context.init_dir = pathlib.Path().absolute()
build_build_python = build_steps(configure_build_python, make_build_python)
build_wasi_python = build_steps(configure_wasi_python, make_wasi_python)
dispatch = { dispatch = {
"configure-build-python": configure_build_python, "configure-build-python": configure_build_python,
"make-build-python": make_build_python, "make-build-python": make_build_python,
"build-python": build_build_python,
"configure-host": configure_wasi_python, "configure-host": configure_wasi_python,
"make-host": make_wasi_python, "make-host": make_wasi_python,
"build": build_all, "build-host": build_wasi_python,
"build": build_steps(build_build_python, build_wasi_python),
"clean": clean_contents, "clean": clean_contents,
} }
dispatch[context.subcommand](context) dispatch[context.subcommand](context)