Skip to content

Commit

Permalink
feat: compile build scripts in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Dec 10, 2024
1 parent 7e7ff6c commit d37c687
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ cl_build_build_script_cmd: (info: cpp2b_source_build_info, bin_outpath: fs::path
cmd_str += " \"(transpiled_src .string())$\"";
cmd_str += " -I\"(cppfront_include_dir.string())$\"";
cmd_str += " /Fe\"(fs::relative(bin_outpath).string())$\"";
cmd_str += " /Fo\"(fs::relative(bin_outpath).parent_path())$\"";

Check warning on line 674 in src/main.cpp2

View workflow job for this annotation

GitHub Actions / Typos Check

"Fo" should be "Of" or "For" or "Do" or "Go" or "To".
cmd_str += " /link";
return cmd_str;
}
Expand Down Expand Up @@ -881,15 +882,26 @@ do_build: (targets: std::vector<std::string>) -> (stuff: full_build_info, exit_c
built_modules[result.module_name] = true;
}

build_script_loop: for stuff.build_scripts do(build_script) {
build_script_futures: std::vector<std::pair<std::reference_wrapper<cpp2b_source_build_info>, std::future<build_binary_result>>> = ();
build_script_futures.reserve(stuff.build_scripts.size());

build_script_loop: for stuff.build_scripts do(inout build_script) {
for build_script.imports do(imp) {
if !built_modules.contains(imp) {
log_error("cannot build build script {} - missing import {}", build_script.src.generic_string(), imp);
continue build_script_loop;
}
}

build_result := build_build_script(build_script);
build_script_futures.emplace_back(
std::ref(build_script),
std::async(std::launch::async, build_build_script, build_script)
);
}

for build_script_futures do(inout p) {
build_result := p.second.get();
build_script := p.first.get();

if build_result.exit_code != 0 {
log_error("failed to build {} - exit code {}", build_script.src.generic_string(), build_result.exit_code);
Expand Down

0 comments on commit d37c687

Please sign in to comment.