summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-11 19:20:06 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-11 19:20:06 +0200
commit799921f0b1f5dcaf8dd2aa2f40adaf8c8490affc (patch)
treeae46ebb4c7adbd7337060f5a9d666e1d620a59f2 /libcppbuild.cc
parent474ce1322f3c13fe414b5e2201d82a4136a947da (diff)
Naiive async compilation
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index ff208b3..ddc0b66 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -5,6 +5,8 @@
#include <fstream>
#include <regex>
#include <utility>
+//#include <thread>
+#include <future>
#include "libcppbuild.h"
@@ -102,6 +104,8 @@ int main(int argc, const char* argv[])
const auto& files = project.sources;
std::vector<std::string> objects;
+ std::vector<std::future<int>> 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;
}
}