This commit is contained in:
parent
be1986ca08
commit
4d09eaac2a
10 changed files with 276 additions and 7 deletions
|
|
@ -22,6 +22,7 @@ import std;
|
|||
import :Clang;
|
||||
import :Platform;
|
||||
import :Test;
|
||||
import :Progress;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
|
|
@ -252,6 +253,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
for (const Shader& shader : config.shaders) {
|
||||
if (shader.Check(outputDir)) continue;
|
||||
threads.emplace_back([&shader, &outputDir, &buildError, &buildCancelled]() {
|
||||
Progress::Task task(std::format("Compiling shader {}", shader.path.filename().string()));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
|
||||
std::string result = shader.Compile(outputDir);
|
||||
|
|
@ -265,6 +267,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
}
|
||||
|
||||
threads.emplace_back([&config, &outputDir, &buildCancelled, &buildError]() {
|
||||
Progress::Task task(std::format("Copying files for {}", config.name));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
try {
|
||||
for (const fs::path& additionalFile : config.files) {
|
||||
|
|
@ -320,6 +323,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
externalThreads.reserve(config.externalDependencies.size());
|
||||
for (std::size_t i = 0; i < config.externalDependencies.size(); ++i) {
|
||||
externalThreads.emplace_back([&, i]() {
|
||||
Progress::Task task(std::format("Building external dep {}", config.externalDependencies[i].name));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
externalResults[i] = BuildExternal(config.externalDependencies[i], config.target, buildCancelled);
|
||||
if (!externalResults[i].error.empty()) {
|
||||
|
|
@ -337,7 +341,11 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
fs::create_directories(stdPcmDir);
|
||||
}
|
||||
|
||||
std::string stdPcmResult = BuildStdPcm(config, stdPcmDir/"std.pcm");
|
||||
std::string stdPcmResult;
|
||||
{
|
||||
Progress::Task task(std::format("Building std PCM ({}-{})", config.target, config.march));
|
||||
stdPcmResult = BuildStdPcm(config, stdPcmDir/"std.pcm");
|
||||
}
|
||||
if(!stdPcmResult.empty()) {
|
||||
buildCancelled.store(true);
|
||||
for(std::thread& thread : threads) thread.join();
|
||||
|
|
@ -514,6 +522,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
const std::string srcPath = cFile.string() + ".c";
|
||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled, &config]() {
|
||||
Progress::Task task(std::format("Compiling {}.c", cFile.filename().string()));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
|
||||
std::string result = RunCommand(std::format("clang {}.c --target={} -march={} -mtune={} -O3 -c -o {}_source.o", cFile.string(), config.target, config.march, config.mtune, (buildDir / cFile.filename()).string()));
|
||||
|
|
@ -533,6 +542,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
const std::string srcPath = cFile.string() + ".cu";
|
||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled]() {
|
||||
Progress::Task task(std::format("Compiling {}.cu", cFile.filename().string()));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
|
||||
std::string result = RunCommand(std::format("nvcc {}.cu -c -o {}_source.o -O3 -arch=sm_89", cFile.string(), (buildDir / cFile.filename()).string()));
|
||||
|
|
@ -580,6 +590,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
if(interface->Check(pcmDir, externalFloor)) {
|
||||
Module* mod = interface.get();
|
||||
threads.emplace_back([mod, &command, &pcmDir, &buildDir, &buildCancelled, &buildError]() {
|
||||
Progress::Task task(std::format("Compiling interface {}", mod->path.filename().string()));
|
||||
try {
|
||||
mod->Compile(command, pcmDir, buildDir, buildCancelled, buildError);
|
||||
} catch (const std::exception& e) {
|
||||
|
|
@ -602,6 +613,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
buildResult.repack = true;
|
||||
Implementation* impl = &implementation;
|
||||
threads.emplace_back([impl, &command, &buildDir, &buildCancelled, &buildError]() {
|
||||
Progress::Task task(std::format("Compiling {}.cpp", impl->path.filename().string()));
|
||||
try {
|
||||
impl->Compile(command, buildDir, buildCancelled, buildError);
|
||||
} catch (const std::exception& e) {
|
||||
|
|
@ -694,6 +706,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
}
|
||||
|
||||
if(buildResult.repack) {
|
||||
Progress::Task task(std::format("Linking {}", config.outputName));
|
||||
if(config.type == ConfigurationType::Executable) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
if(config.target == "x86_64-w64-mingw32") {
|
||||
|
|
@ -848,6 +861,7 @@ int Crafter::Run(int argc, char** argv) {
|
|||
bool runTests = false;
|
||||
bool runAfterBuild = false;
|
||||
RunTestsOptions testOpts;
|
||||
Progress::Verbosity verbosity = Progress::Verbosity::Default;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string_view arg = argv[i];
|
||||
|
|
@ -855,6 +869,10 @@ int Crafter::Run(int argc, char** argv) {
|
|||
runTests = true;
|
||||
} else if (arg == "-r") {
|
||||
runAfterBuild = true;
|
||||
} else if (arg == "-v" || arg == "--verbose") {
|
||||
verbosity = Progress::Verbosity::Verbose;
|
||||
} else if (arg == "-q" || arg == "--quiet") {
|
||||
verbosity = Progress::Verbosity::Quiet;
|
||||
} else if (arg.starts_with("--project=")) {
|
||||
projectFile = arg.substr(std::string_view("--project=").size());
|
||||
} else if (runTests && arg.starts_with("--jobs=")) {
|
||||
|
|
@ -872,6 +890,8 @@ int Crafter::Run(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
Progress::SetVerbosity(verbosity);
|
||||
|
||||
// The test run is target-scoped: only tests whose cfg.target equals
|
||||
// testOpts.targetFilter are included. Default = host triple, so a
|
||||
// bare `crafter-build test` runs everything that targets host.
|
||||
|
|
@ -899,10 +919,13 @@ int Crafter::Run(int argc, char** argv) {
|
|||
BuildResult result = Build(config, depResults, depMutex);
|
||||
|
||||
if (!result.result.empty()) {
|
||||
Progress::Clear();
|
||||
std::println(std::cerr, "{}", result.result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Progress::Finalize();
|
||||
|
||||
if (runAfterBuild) {
|
||||
if (config.type != ConfigurationType::Executable) {
|
||||
std::println(std::cerr, "-r: cannot run a library");
|
||||
|
|
@ -925,6 +948,7 @@ int Crafter::Run(int argc, char** argv) {
|
|||
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
Progress::Clear();
|
||||
std::println(std::cerr, "{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue