Patch-Source: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12610 -- From eea465641340ad6d493093f68ffaebb22e000ded Mon Sep 17 00:00:00 2001 From: PHO Date: Sat, 11 May 2024 23:43:52 +0900 Subject: [PATCH] hadrian/bootstrap/bootstrap.py: Add an option --jobs=N for parallel compilation This makes bootstrapping hadrian a lot faster. --- hadrian/bootstrap/bootstrap.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) --- a/hadrian/bootstrap/bootstrap.py +++ b/hadrian/bootstrap/bootstrap.py @@ -186,24 +186,24 @@ def resolve_dep(dep : BootstrapDep) -> Path: return sdist_dir -def install_dep(dep: BootstrapDep, ghc: Compiler) -> None: +def install_dep(dep: BootstrapDep, ghc: Compiler, jobs: int|None) -> None: dist_dir = (DISTDIR / f'{dep.package}-{dep.version}').resolve() sdist_dir = resolve_dep(dep) - install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component) + install_sdist(dist_dir, sdist_dir, ghc, dep.flags, dep.component, jobs) -def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component): +def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[str], component, jobs: int|None): prefix = PSEUDOSTORE.resolve() flags_option = ' '.join(flags) setup_dist_dir = dist_dir / 'setup' setup = setup_dist_dir / 'Setup' - build_args = [ + common_args = [ f'--builddir={dist_dir}', ] - configure_args = build_args + [ + configure_args = common_args + [ f'--package-db={PKG_DB.resolve()}', f'--prefix={prefix}', f'--bindir={BINDIR.resolve()}', @@ -215,6 +215,12 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st f'{component or ""}' ] + build_args = common_args.copy() + if jobs is not None: + build_args.append(f'--jobs={jobs}') + + install_args = common_args.copy() + def check_call(args: List[str]) -> None: subprocess_run(args, cwd=sdist_dir, check=True) @@ -231,7 +237,7 @@ def install_sdist(dist_dir: Path, sdist_dir: Path, ghc: Compiler, flags: List[st check_call([str(ghc.ghc_path), '--make', '-package-env=-', '-i', f'-odir={setup_dist_dir}', f'-hidir={setup_dist_dir}', '-o', setup, 'Setup']) check_call([setup, 'configure'] + configure_args) check_call([setup, 'build'] + build_args) - check_call([setup, 'install'] + build_args) + check_call([setup, 'install'] + install_args) def hash_file(h, f: BinaryIO) -> SHA256Hash: while True: @@ -246,7 +252,7 @@ def hash_file(h, f: BinaryIO) -> SHA256Hash: UnitId = NewType('UnitId', str) PlanUnit = NewType('PlanUnit', dict) -def bootstrap(info: BootstrapInfo, ghc: Compiler) -> None: +def bootstrap(info: BootstrapInfo, ghc: Compiler, jobs: int|None) -> None: if not PKG_DB.exists(): print(f'Creating package database {PKG_DB}') PKG_DB.parent.mkdir(parents=True, exist_ok=True) @@ -256,7 +262,7 @@ def bootstrap(info: BootstrapInfo, ghc: Compiler) -> None: check_builtin(dep, ghc) for dep in info.dependencies: - install_dep(dep, ghc) + install_dep(dep, ghc, jobs) # Steps ####################################################################### @@ -382,6 +388,8 @@ def main() -> None: help='produce a Hadrian distribution archive (default)') parser.add_argument('--no-archive', dest='want_archive', action='store_false', help='do not produce a Hadrian distribution archive') + parser.add_argument('-j', '--jobs', type=int, + help='the number of jobs to run simultaneously') parser.set_defaults(want_archive=True) subparsers = parser.add_subparsers(dest="command") @@ -488,7 +496,7 @@ Alternatively, you could use `bootstrap.py -w {ghc.ghc_path} -d {args.deps} fetc plan = gen_fetch_plan(info) fetch_from_plan(plan, TARBALLS) - bootstrap(info, ghc) + bootstrap(info, ghc, args.jobs) hadrian_path = (BINDIR / 'hadrian').resolve() print(dedent(f'''