working dependencies
This commit is contained in:
parent
c5d6aa532c
commit
59b995cb7c
5 changed files with 37 additions and 16 deletions
|
|
@ -81,7 +81,7 @@ Configuration::Configuration(nlohmann::json& configs, nlohmann::json& config, fs
|
||||||
if(config.contains("dependencies")) {
|
if(config.contains("dependencies")) {
|
||||||
nlohmann::json dependenciesJson = config["dependencies"];
|
nlohmann::json dependenciesJson = config["dependencies"];
|
||||||
for (nlohmann::json::iterator it = dependenciesJson.begin(); it != dependenciesJson.end(); ++it) {
|
for (nlohmann::json::iterator it = dependenciesJson.begin(); it != dependenciesJson.end(); ++it) {
|
||||||
dependencies.emplace_back((*it)["path"].get<std::string>(), (*it)["configuration"].get<std::string>(), (*it)["filename"].get<std::string>());
|
dependencies.emplace_back((*it)["path"].get<std::string>(), (*it)["configuration"].get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(config.contains("extends")){
|
if(config.contains("extends")){
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,6 @@ module Crafter.Build:DependencyImpl;
|
||||||
import :Dependency;
|
import :Dependency;
|
||||||
using namespace Crafter::Build;
|
using namespace Crafter::Build;
|
||||||
|
|
||||||
Dependency::Dependency(std::string path, std::string configuration, std::string filename): path(path), configuration(configuration), filename(filename) {
|
Dependency::Dependency(std::string path, std::string configuration): path(path), configuration(configuration) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ export namespace Crafter::Build {
|
||||||
class Dependency {
|
class Dependency {
|
||||||
public:
|
public:
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string filename;
|
|
||||||
std::string configuration;
|
std::string configuration;
|
||||||
Dependency(std::string path, std::string configuration, std::string filename);
|
Dependency(std::string path, std::string configuration);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ Project::Project(std::string name, fs::path path, std::vector<Configuration> con
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::Build(std::string configuration) {
|
void Project::Build(std::string configuration) const {
|
||||||
for(const Configuration& config : configurations) {
|
for(const Configuration& config : configurations) {
|
||||||
if(config.name == configuration){
|
if(config.name == configuration){
|
||||||
Build(config, config.outputDir);
|
Build(config, config.outputDir);
|
||||||
|
|
@ -48,7 +48,7 @@ void Project::Build(std::string configuration) {
|
||||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::Build(std::string configuration, fs::path outputDir) {
|
void Project::Build(std::string configuration, fs::path outputDir) const {
|
||||||
for(const Configuration& config : configurations) {
|
for(const Configuration& config : configurations) {
|
||||||
if(config.name == configuration){
|
if(config.name == configuration){
|
||||||
Build(config, outputDir);
|
Build(config, outputDir);
|
||||||
|
|
@ -58,11 +58,11 @@ void Project::Build(std::string configuration, fs::path outputDir) {
|
||||||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::Build(Configuration configuration) {
|
void Project::Build(Configuration configuration) const {
|
||||||
Build(configuration, configuration.outputDir);
|
Build(configuration, configuration.outputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::Build(Configuration config, fs::path outputDir) {
|
void Project::Build(Configuration config, fs::path outputDir) const {
|
||||||
if (!fs::exists(config.buildDir)) {
|
if (!fs::exists(config.buildDir)) {
|
||||||
fs::create_directory(config.buildDir);
|
fs::create_directory(config.buildDir);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -89,6 +89,24 @@ void Project::Build(Configuration config, fs::path outputDir) {
|
||||||
pcmDir = config.buildDir;
|
pcmDir = config.buildDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string libs;
|
||||||
|
|
||||||
|
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||||
|
|
||||||
|
if(config.dependencies.size() > 0){
|
||||||
|
libs += std::format(" -L{}", pcmDir.generic_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::int_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||||
|
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
||||||
|
libs+=std::format(" -l{}", project.name);
|
||||||
|
depThreads[i] = std::thread([i, pcmDir, config, project]() {
|
||||||
|
project.Build(config.dependencies[i].configuration, pcmDir);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name = this->name;
|
||||||
|
|
||||||
std::string clangDir;
|
std::string clangDir;
|
||||||
if(config.target == "wasm32-unknown-wasi" || config.target == "wasm64-unknown-wasi"){
|
if(config.target == "wasm32-unknown-wasi" || config.target == "wasm64-unknown-wasi"){
|
||||||
clangDir = "${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -Wno-unused-command-line-argument";
|
clangDir = "${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -Wno-unused-command-line-argument";
|
||||||
|
|
@ -100,6 +118,10 @@ void Project::Build(Configuration config, fs::path outputDir) {
|
||||||
clangDir = "clang++ -Wno-unused-command-line-argument";
|
clangDir = "clang++ -Wno-unused-command-line-argument";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(std::thread& thread : depThreads){
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
//clangDir+= std::format(" -I {} ", pcmDir);
|
//clangDir+= std::format(" -I {} ", pcmDir);
|
||||||
|
|
||||||
for(const fs::path& moduleFile : config.moduleFiles){
|
for(const fs::path& moduleFile : config.moduleFiles){
|
||||||
|
|
@ -123,11 +145,11 @@ void Project::Build(Configuration config, fs::path outputDir) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
if(config.type == "executable"){
|
if(config.type == "executable"){
|
||||||
system(std::format("{} {}-O{} -o {} {}", clangDir, files, config.optimizationLevel, (outputDir/name).generic_string(), target).c_str());
|
system(std::format("{} {}-O{} -o {} {} {}", clangDir, files, config.optimizationLevel, (outputDir/name).generic_string(), target, libs).c_str());
|
||||||
} else if(config.type == "library"){
|
} else if(config.type == "library"){
|
||||||
system(std::format("ar r {}.a {}", (outputDir/name).generic_string(), files).c_str());
|
system(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||||
} else if(config.type == "shared-library"){
|
} else if(config.type == "shared-library"){
|
||||||
system(std::format("ar r {}.so {} -shared", (outputDir/name).generic_string(), files).c_str());
|
system(std::format("ar r {}.so {} -shared", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ export namespace Crafter::Build {
|
||||||
fs::path path;
|
fs::path path;
|
||||||
std::vector<Configuration> configurations;
|
std::vector<Configuration> configurations;
|
||||||
Project(std::string name, fs::path path, std::vector<Configuration> configurations);
|
Project(std::string name, fs::path path, std::vector<Configuration> configurations);
|
||||||
void Build(std::string configuration);
|
void Build(std::string configuration) const;
|
||||||
void Build(std::string configuration, fs::path outputDir);
|
void Build(std::string configuration, fs::path outputDir) const;
|
||||||
void Build(Configuration configuration);
|
void Build(Configuration configuration) const;
|
||||||
void Build(Configuration configuration, fs::path outputDir);
|
void Build(Configuration configuration, fs::path outputDir) const;
|
||||||
void SaveToJSON(fs::path path);
|
void SaveToJSON(fs::path path) const;
|
||||||
static Project LoadFromJSON(fs::path path);
|
static Project LoadFromJSON(fs::path path);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue