import argparse import dataclasses import os from pathlib import Path import subprocess @dataclasses.dataclass(frozen=True) class Target: name: str requires_sizeof_jmp_buf: bool targets = [ Target( name="amd64", requires_sizeof_jmp_buf=True, ), Target( name="i686", requires_sizeof_jmp_buf=True, ), Target( name="wasm32", requires_sizeof_jmp_buf=False, ), Target( name="wasm64", requires_sizeof_jmp_buf=False, ), ] def _find_target_by_name(name: str): for target in targets: if target.name == name: return target raise ValueError(f"Unrecognised target: {name}") gcs = ["bump", "mark-and-sweep"] def main(): args = _parse_args() args.func(args) def _main_standard(args): for target in targets: target_dir = Path(__file__).parent / "target" / target.name for gc in gcs: output_dir = target_dir / gc _build_runtime( target=target, gc=gc, options=[], output_dir=output_dir, ) if target.requires_sizeof_jmp_buf: sizeof_jmp_buf = subprocess.check_output([target_dir / gcs[0] / "sizeof_jmp_buf"]) with open(target_dir / "sizeof_jmp_buf.txt", "wb") as fileobj: fileobj.write(sizeof_jmp_buf) def _main_custom(args): target = _find_target_by_name(args.target) _build_runtime( target=target, gc=args.gc, options=args.options, output_dir=Path(args.output_dir), ) def _build_runtime(*, target: Target, gc: str, options: list[str], output_dir: Path): setup_command = ["meson", "setup", output_dir.absolute(), "--werror", f"-Dgc={gc}", "--wipe"] + [ f"-D{option}" for option in options ] if target.name != "amd64": setup_command += ["--cross-file", f"{target.name}.meson"] subprocess.check_call(setup_command, cwd=Path(__file__).parent) subprocess.check_call(["meson", "compile", "--verbose"], cwd=output_dir) def _parse_args(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() standard = subparsers.add_parser("standard", help="Build the standard set of runtimes") standard.set_defaults(func=_main_standard) custom = subparsers.add_parser("custom", help="Build a custom runtime") custom.add_argument("--gc", required=True, choices=gcs) custom.add_argument("--target", required=True, choices=[target.name for target in targets]) custom.add_argument("-D", dest="options", nargs="*") custom.add_argument("--output-dir", required=True) custom.set_defaults(func=_main_custom) return parser.parse_args() if __name__ == "__main__": main()