Skip to content

Commit

Permalink
feat: concurrent builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Dec 10, 2024
1 parent d37c687 commit 8a9fe2d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ cl_build_binary_cmd: (info: cpp2b_source_binary_info, bin_outpath: fs::path) ->
cmd_str += " \"(transpiled_src.string())$\"";
cmd_str += " -I\"(cppfront_include_dir.string())$\"";
cmd_str += " /Fe\"(bin_outpath.string())$\"";
cmd_str += " /Fd\"(fs::relative(bin_outpath).parent_path().string())$\\\"";
return cmd_str;
}

Expand Down Expand Up @@ -671,7 +672,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())$\"";
cmd_str += " /Fo\"(fs::relative(bin_outpath).parent_path().string())$\"";

Check warning on line 675 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 @@ -932,7 +933,11 @@ do_build: (targets: std::vector<std::string>) -> (stuff: full_build_info, exit_c
bin_targets.reserve(targets.size());
}

bin_loop: for stuff.bins do(bin) {

bin_futures: std::vector<std::pair<std::reference_wrapper<cpp2b_source_binary_info>, std::future<build_binary_result>>> = ();
bin_futures.reserve(stuff.bins.size());

bin_loop: for stuff.bins do(inout bin) {
bin_target_name := fs::path(bin.name()).generic_string();

if !targets.empty() {
Expand All @@ -955,13 +960,22 @@ do_build: (targets: std::vector<std::string>) -> (stuff: full_build_info, exit_c
}
}

build_result := build_binary(bin);
bin_futures.emplace_back(
std::ref(bin),
std::async(std::launch::async, build_binary, bin)
);
}

for bin_futures do(inout p) {
build_result := p.second.get();
bin := p.first.get();

stuff.bin_results.emplace_back(build_result);

if build_result.exit_code != 0 {
log_error("failed to build binary - exit code {}", build_result.exit_code);
print_log_file(build_result.log_path);
continue bin_loop;
continue;
}

log_success("binary built {} ({}ms)", fs::relative(build_result.outpath).generic_string(), build_result.duration.count());
Expand Down

0 comments on commit 8a9fe2d

Please sign in to comment.