forked from OctaForge/libostd
threaded build.cc
This commit is contained in:
parent
b3d6d2a30a
commit
19badf6140
44
build.cc
44
build.cc
|
@ -7,6 +7,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
/* no dependency on the rest of ostd or the built library, so it's fine */
|
||||||
|
#include "ostd/thread_pool.hh"
|
||||||
|
|
||||||
#if __has_include(<filesystem>)
|
#if __has_include(<filesystem>)
|
||||||
# include <filesystem>
|
# include <filesystem>
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
@ -332,7 +335,7 @@ int main(int argc, char **argv) {
|
||||||
auto f = std::fopen(ccf.data(), "w");
|
auto f = std::fopen(ccf.data(), "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
std::printf("cannot open '%s' for writing\n", ccf.data());
|
std::printf("cannot open '%s' for writing\n", ccf.data());
|
||||||
throw std::runtime_error{"test write failure"};
|
std::exit(1);
|
||||||
}
|
}
|
||||||
fprintf(
|
fprintf(
|
||||||
f,
|
f,
|
||||||
|
@ -364,6 +367,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
std::string asm_obj, cxx_obj, cxx_dynobj;
|
std::string asm_obj, cxx_obj, cxx_dynobj;
|
||||||
|
|
||||||
|
ostd::thread_pool tp;
|
||||||
|
tp.start();
|
||||||
|
|
||||||
std::printf("Building the library...\n");
|
std::printf("Building the library...\n");
|
||||||
for (auto aso: ASM_SOURCES) {
|
for (auto aso: ASM_SOURCES) {
|
||||||
std::string base = ASM_SOURCE_DIR;
|
std::string base = ASM_SOURCE_DIR;
|
||||||
|
@ -371,7 +377,9 @@ int main(int argc, char **argv) {
|
||||||
base += aso;
|
base += aso;
|
||||||
auto ass = base + ".S";
|
auto ass = base + ".S";
|
||||||
auto asob = base + ".o";
|
auto asob = base + ".o";
|
||||||
call_as(ass.data(), asob.data());
|
tp.push([&call_as, ass, asob]() {
|
||||||
|
call_as(ass.data(), asob.data());
|
||||||
|
});
|
||||||
asm_obj += ' ';
|
asm_obj += ' ';
|
||||||
asm_obj += asob;
|
asm_obj += asob;
|
||||||
}
|
}
|
||||||
|
@ -382,18 +390,27 @@ int main(int argc, char **argv) {
|
||||||
auto css = base + ".cc";
|
auto css = base + ".cc";
|
||||||
if (build_static) {
|
if (build_static) {
|
||||||
auto csob = base + ".o";
|
auto csob = base + ".o";
|
||||||
call_cxx(css.data(), csob.data(), false);
|
tp.push([&call_cxx, css, csob]() {
|
||||||
|
call_cxx(css.data(), csob.data(), false);
|
||||||
|
});
|
||||||
cxx_obj += ' ';
|
cxx_obj += ' ';
|
||||||
cxx_obj += csob;
|
cxx_obj += csob;
|
||||||
}
|
}
|
||||||
if (build_shared) {
|
if (build_shared) {
|
||||||
auto csob = base + "_dyn.o";
|
auto csob = base + "_dyn.o";
|
||||||
call_cxx(css.data(), csob.data(), true);
|
tp.push([&call_cxx, css, csob]() {
|
||||||
|
call_cxx(css.data(), csob.data(), true);
|
||||||
|
});
|
||||||
cxx_dynobj += ' ';
|
cxx_dynobj += ' ';
|
||||||
cxx_dynobj += csob;
|
cxx_dynobj += csob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* excessive, but whatever... maybe add better
|
||||||
|
* sync later without restarting all the threads
|
||||||
|
*/
|
||||||
|
tp.destroy();
|
||||||
|
|
||||||
if (build_static) {
|
if (build_static) {
|
||||||
std::string all_obj = asm_obj;
|
std::string all_obj = asm_obj;
|
||||||
all_obj += ' ';
|
all_obj += ' ';
|
||||||
|
@ -407,10 +424,15 @@ int main(int argc, char **argv) {
|
||||||
call_ldlib(OSTD_SHARED_LIB, all_obj.data(), true);
|
call_ldlib(OSTD_SHARED_LIB, all_obj.data(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* examples are parallel */
|
||||||
|
tp.start();
|
||||||
|
|
||||||
if (build_examples) {
|
if (build_examples) {
|
||||||
std::printf("Building examples...\n");
|
std::printf("Building examples...\n");
|
||||||
for (auto ex: EXAMPLES) {
|
for (auto ex: EXAMPLES) {
|
||||||
build_example(ex);
|
tp.push([&build_example, ex]() {
|
||||||
|
build_example(ex);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,12 +446,16 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto test: TEST_CASES) {
|
for (auto test: TEST_CASES) {
|
||||||
try {
|
tp.push([&build_test, test]() {
|
||||||
build_test(test);
|
build_test(test);
|
||||||
} catch (std::runtime_error const &) {
|
});
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wait for tests and examples to be done */
|
||||||
|
tp.destroy();
|
||||||
|
|
||||||
|
if (build_testsuite) {
|
||||||
std::string cmd = "./test_runner ";
|
std::string cmd = "./test_runner ";
|
||||||
cmd += TEST_DIR;
|
cmd += TEST_DIR;
|
||||||
system_v(cmd.data());
|
system_v(cmd.data());
|
||||||
|
|
|
@ -151,6 +151,7 @@ struct thread_pool {
|
||||||
tid.join();
|
tid.join();
|
||||||
p_cond.notify_all();
|
p_cond.notify_all();
|
||||||
}
|
}
|
||||||
|
p_thrs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Queues a new task for execution.
|
/** @brief Queues a new task for execution.
|
||||||
|
|
Loading…
Reference in a new issue