defines
This commit is contained in:
parent
35f943af53
commit
5af6d0080a
8 changed files with 93 additions and 73 deletions
|
|
@ -30,73 +30,54 @@ module;
|
|||
#include <thread>
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
#include <regex>
|
||||
#include <mutex>
|
||||
module Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
std::vector<std::string> mergeUnique(const std::vector<std::string>& vec1, const std::vector<std::string>& vec2) {
|
||||
std::unordered_set<std::string> uniqueElements;
|
||||
std::vector<std::string> result;
|
||||
|
||||
for (const auto& str : vec1) {
|
||||
if (uniqueElements.insert(str).second) {
|
||||
result.push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& str : vec2) {
|
||||
if (uniqueElements.insert(str).second) {
|
||||
result.push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Project::Project(std::string name, fs::path path, std::vector<Configuration> configurations) : name(name), path(path), configurations(configurations) {
|
||||
|
||||
}
|
||||
|
||||
void Project::Build(std::string configuration) const {
|
||||
for(const Configuration& config : configurations) {
|
||||
const Configuration& Project::Build(std::string configuration) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config);
|
||||
return;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
void Project::Build(std::string configuration, fs::path outputDir) const {
|
||||
for(const Configuration& config : configurations) {
|
||||
const Configuration& Project::Build(std::string configuration, fs::path outputDir) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, outputDir);
|
||||
return;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
void Project::Build(std::string configuration, fs::path outputDir, fs::path binDir) const {
|
||||
for(const Configuration& config : configurations) {
|
||||
const Configuration& Project::Build(std::string configuration, fs::path outputDir, fs::path binDir) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, outputDir, binDir);
|
||||
return;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
void Project::Build(Configuration configuration) const {
|
||||
void Project::Build(Configuration& configuration) {
|
||||
Build(configuration, configuration.outputDir);
|
||||
}
|
||||
|
||||
void Project::Build(Configuration config, fs::path outputDir) const {
|
||||
void Project::Build(Configuration& config, fs::path outputDir) {
|
||||
Build(config, outputDir, outputDir);
|
||||
}
|
||||
|
||||
void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) const {
|
||||
void Project::Build(Configuration& config, fs::path outputDir, fs::path binDir) {
|
||||
if(config.standard.empty()) {
|
||||
config.standard = "c++26";
|
||||
}
|
||||
|
|
@ -149,7 +130,7 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
}
|
||||
|
||||
for(Shader& shader : config.shaderFiles) {
|
||||
shader.Compile(outputDir);
|
||||
shader.Compile(binDir);
|
||||
}
|
||||
|
||||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||
|
|
@ -157,7 +138,7 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
if(config.dependencies.size() > 0){
|
||||
libs += std::format(" -L{}", pcmDir.generic_string());
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> depLibSet;
|
||||
for(std::int_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||
if(config.dependencies[i].path.ends_with(".git")) {
|
||||
fs::path name = fs::path(config.dependencies[i].path).filename();
|
||||
|
|
@ -176,26 +157,37 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
}
|
||||
config.dependencies[i].path = fs::path(config.dependencies[i].path).filename().replace_extension();
|
||||
Project project = Project::LoadFromJSON(fs::path(buildDir)/config.dependencies[i].path/"project.json");
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
depThreads[i] = std::thread([i, pcmDir, config, project, binDir]() {
|
||||
project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
});
|
||||
for(const Configuration& config2 : project.configurations) {
|
||||
if(config2.name == config.dependencies[i].configuration){
|
||||
config.libs = mergeUnique(config.libs, config2.libs);
|
||||
break;
|
||||
config.dependencies[i].name = project.name;
|
||||
if (depLibSet.insert(project.name).second) {
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
}
|
||||
const Configuration& depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
for(const std::string& lib2 : depConfig.libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
libs+=std::format(" -l{}", lib2);
|
||||
}
|
||||
}
|
||||
for(const Dependency& dep2 : depConfig.dependencies) {
|
||||
if (depLibSet.insert(dep2.name).second) {
|
||||
libs+=std::format(" -l{}", dep2.name);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
depThreads[i] = std::thread([i, pcmDir, config, project, binDir]() {
|
||||
project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
});
|
||||
for(const Configuration& config2 : project.configurations) {
|
||||
if(config2.name == config.dependencies[i].configuration){
|
||||
config.libs = mergeUnique(config.libs, config2.libs);
|
||||
break;
|
||||
config.dependencies[i].name = project.name;
|
||||
|
||||
if (depLibSet.insert(project.name).second) {
|
||||
libs+=std::format(" -l{}", project.name);
|
||||
}
|
||||
const Configuration& depConfig = project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||
for(const std::string& lib2 : depConfig.libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
libs+=std::format(" -l{}", lib2);
|
||||
}
|
||||
}
|
||||
for(const Dependency& dep2 : depConfig.dependencies) {
|
||||
if (depLibSet.insert(dep2.name).second) {
|
||||
libs+=std::format(" -l{}", dep2.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -231,10 +223,6 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
libs+= std::format(" -l{}",lib);
|
||||
}
|
||||
|
||||
for(std::thread& thread : depThreads){
|
||||
thread.join();
|
||||
}
|
||||
|
||||
std::string march;
|
||||
if(config.target != "wasm32-unknown-wasi"){
|
||||
march = std::format("-march={}", config.march);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue