Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions Tools/wasm/wasi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""Delete all files created by this script."""
if CROSS_BUILD_DIR.exists():
Expand All @@ -409,6 +397,16 @@ def clean_contents(context):
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():
default_host_triple = "wasm32-wasip1"
default_wasi_sdk = find_wasi_sdk()
Expand Down Expand Up @@ -438,6 +436,9 @@ def main():
make_build = subcommands.add_parser(
"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",
help="Run `configure` for the "
Expand All @@ -448,15 +449,20 @@ def main():
make_host = subcommands.add_parser(
"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(
"clean", help="Delete files and directories created by this script"
)
for subcommand in (
build,
configure_build,
make_build,
build_python,
configure_host,
make_host,
build_host,
):
subcommand.add_argument(
"--quiet",
Expand All @@ -471,19 +477,30 @@ def main():
default=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(
"--clean",
action="store_true",
default=False,
dest="clean",
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(
"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(
"--wasi-sdk",
type=pathlib.Path,
Expand All @@ -499,7 +516,7 @@ def main():
help="Command template for running the WASI host; defaults to "
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(
"--host-triple",
action="store",
Expand All @@ -511,12 +528,17 @@ def main():
context = parser.parse_args()
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 = {
"configure-build-python": configure_build_python,
"make-build-python": make_build_python,
"build-python": build_build_python,
"configure-host": configure_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,
}
dispatch[context.subcommand](context)
Expand Down
Loading