From 799921f0b1f5dcaf8dd2aa2f40adaf8c8490affc Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 11 Jun 2021 19:20:06 +0200 Subject: Naiive async compilation --- Makefile | 2 +- libcppbuild.cc | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7cad9bd..d5beb15 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ libcppbuild.a: libcppbuild.cc ar rcs libcppbuild.a libcppbuild.o cppbuild: cppbuild.cc libcppbuild.a - g++ -g -std=c++17 cppbuild.cc libcppbuild.a -o cppbuild + g++ -g -std=c++17 cppbuild.cc libcppbuild.a -pthread -o cppbuild clean: rm -f cppbuild libcppbuild.o libcppbuild.a diff --git a/libcppbuild.cc b/libcppbuild.cc index ff208b3..ddc0b66 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -5,6 +5,8 @@ #include #include #include +//#include +#include #include "libcppbuild.h" @@ -102,6 +104,8 @@ int main(int argc, const char* argv[]) const auto& files = project.sources; std::vector objects; + std::vector> tasks; + std::cout << "Building\n"; for(const auto& file : files) { @@ -154,12 +158,28 @@ int main(int argc, const char* argv[]) std::filesystem::last_write_time(file) > std::filesystem::last_write_time(object)) { - std::string compiler = "g++ -MMD -c " + file + " -o " + object; - std::cout << compiler << "\n"; - if(system(compiler.data())) - { - return 1; - } + + tasks.emplace_back( + std::async(std::launch::async, + [file, object]() + { + std::string compiler = "g++ -MMD -c " + file + " -o " + object; + std::cout << compiler << "\n"; + if(system(compiler.data())) + { + return 1; + } + return 0; + })); + } + } + + for(auto& task : tasks) + { + task.wait(); + if(task.get() != 0) + { + return 1; } } -- cgit v1.2.3