improved paths
This commit is contained in:
parent
aab781db5f
commit
905df28711
10 changed files with 242 additions and 129 deletions
|
|
@ -23,10 +23,103 @@ module;
|
|||
#include <string>
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
#include <filesystem>
|
||||
module Crafter.Build:ConfigurationImpl;
|
||||
import :Configuration;
|
||||
import :Dependency;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
Configuration::Configuration(std::string name, std::string standard, std::vector<std::string> sourceFiles, std::vector<std::string> moduleFiles, std::string optimizationLevel, std::string buildDir, std::string outputDir, std::string type, std::string target): name(name), standard(standard), sourceFiles(sourceFiles), moduleFiles(moduleFiles), optimizationLevel(optimizationLevel), buildDir(buildDir), outputDir(outputDir), type(type), target(target){
|
||||
Configuration::Configuration(std::string name, std::string standard, std::vector<fs::path> sourceFiles, std::vector<fs::path> moduleFiles, std::string optimizationLevel, std::string buildDir, std::string outputDir, std::string type, std::string target, std::vector<Dependency> dependencies): name(name), standard(standard), sourceFiles(sourceFiles), moduleFiles(moduleFiles), optimizationLevel(optimizationLevel), buildDir(buildDir), outputDir(outputDir), type(type), target(target), dependencies(dependencies) {
|
||||
|
||||
}
|
||||
|
||||
Configuration::Configuration(nlohmann::json& configs, nlohmann::json& config, fs::path workingDir) {
|
||||
name = config["name"].get<std::string>();
|
||||
if(config.contains("standard")) {
|
||||
standard = config["standard"].get<std::string>();
|
||||
}
|
||||
if(config.contains("target")) {
|
||||
target = config["target"].get<std::string>();
|
||||
}
|
||||
if(config.contains("type")) {
|
||||
type = config["type"].get<std::string>();
|
||||
}
|
||||
if(config.contains("source_files")) {
|
||||
const std::vector<std::string> tempSourceFiles = config["source_files"].get<std::vector<std::string>>();
|
||||
sourceFiles = std::vector<fs::path>(tempSourceFiles.size());
|
||||
for(std::int_fast32_t i = 0; i < sourceFiles.size(); i++){
|
||||
std::filesystem::path filePath (tempSourceFiles[i]);
|
||||
std::filesystem::path fullFilePath = workingDir / filePath;
|
||||
sourceFiles[i] = fullFilePath.generic_string();
|
||||
}
|
||||
}
|
||||
if(config.contains("module_files")) {
|
||||
const std::vector<std::string> tempModuleFiles = config["module_files"].get<std::vector<std::string>>();
|
||||
moduleFiles = std::vector<fs::path>(tempModuleFiles.size());
|
||||
for(std::int_fast32_t i = 0; i < moduleFiles.size(); i++){
|
||||
std::filesystem::path filePath (tempModuleFiles[i]);
|
||||
std::filesystem::path fullFilePath = workingDir / filePath;
|
||||
moduleFiles[i] = fullFilePath.generic_string();
|
||||
}
|
||||
}
|
||||
if(config.contains("optimization_level")) {
|
||||
optimizationLevel = config["optimization_level"].get<std::string>();
|
||||
}
|
||||
if(config.contains("build_dir")) {
|
||||
const std::string tempBuildDir = config["build_dir"].get<std::string>();
|
||||
std::filesystem::path buildPath (tempBuildDir);
|
||||
std::filesystem::path fullBuildPath = workingDir / buildPath;
|
||||
buildDir = fullBuildPath.generic_string();
|
||||
}
|
||||
if(config.contains("output_dir")) {
|
||||
const std::string tempOutputDir = config["output_dir"].get<std::string>();
|
||||
std::filesystem::path outputPath (tempOutputDir);
|
||||
std::filesystem::path fullOutputPath = workingDir / outputPath;
|
||||
outputDir = fullOutputPath.generic_string();
|
||||
}
|
||||
if(config.contains("dependencies")) {
|
||||
nlohmann::json dependenciesJson = config["dependencies"];
|
||||
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>());
|
||||
}
|
||||
}
|
||||
if(config.contains("extends")){
|
||||
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
|
||||
for(const std::string& extendName : extends) {
|
||||
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
|
||||
if((*it)["name"].get<std::string>() == extendName){
|
||||
Configuration extendData = Configuration(configs, (*it), workingDir);
|
||||
if(!extendData.standard.empty() && standard.empty()){
|
||||
standard = extendData.standard;
|
||||
}
|
||||
if(!extendData.sourceFiles.empty()){
|
||||
sourceFiles.insert(sourceFiles.end(), extendData.sourceFiles.begin(), extendData.sourceFiles.end());
|
||||
}
|
||||
if(!extendData.moduleFiles.empty()){
|
||||
moduleFiles.insert(moduleFiles.end(), extendData.moduleFiles.begin(), extendData.moduleFiles.end());
|
||||
}
|
||||
if(!extendData.optimizationLevel.empty() && optimizationLevel.empty()){
|
||||
optimizationLevel = extendData.optimizationLevel;
|
||||
}
|
||||
if(!extendData.dependencies.empty()){
|
||||
dependencies.insert(dependencies.end(), extendData.dependencies.begin(), extendData.dependencies.end());
|
||||
}
|
||||
if(!extendData.buildDir.empty() && buildDir.empty()) {
|
||||
buildDir = extendData.buildDir;
|
||||
}
|
||||
if(!extendData.outputDir.empty() && outputDir.empty()) {
|
||||
outputDir = extendData.outputDir;
|
||||
}
|
||||
if(!extendData.target.empty() && target.empty()) {
|
||||
target = extendData.target;
|
||||
}
|
||||
if(!extendData.type.empty() && type.empty()) {
|
||||
type = extendData.type;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,20 +22,26 @@ module;
|
|||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "json.hpp"
|
||||
export module Crafter.Build:Configuration;
|
||||
import :Dependency;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
export namespace Crafter::Build {
|
||||
class Configuration {
|
||||
public:
|
||||
std::string name;
|
||||
std::string standard;
|
||||
std::vector<std::string> sourceFiles;
|
||||
std::vector<std::string> moduleFiles;
|
||||
std::vector<fs::path> sourceFiles;
|
||||
std::vector<fs::path> moduleFiles;
|
||||
std::string optimizationLevel;
|
||||
std::string buildDir;
|
||||
std::string outputDir;
|
||||
std::string type;
|
||||
std::string target;
|
||||
Configuration(std::string name, std::string standard, std::vector<std::string> sourceFiles, std::vector<std::string> moduleFiles, std::string optimizationLevel, std::string buildDir, std::string outputDir, std::string type, std::string target);
|
||||
std::vector<Dependency> dependencies;
|
||||
Configuration(std::string name, std::string standard, std::vector<fs::path> sourceFiles, std::vector<fs::path> moduleFiles, std::string optimizationLevel, std::string buildDir, std::string outputDir, std::string type, std::string target, std::vector<Dependency> dependencies);
|
||||
Configuration(nlohmann::json& configs, nlohmann::json& config, fs::path workingDir);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
29
Crafter.Build-Dependency.cpp
Normal file
29
Crafter.Build-Dependency.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Crafter.Build
|
||||
* Copyright (C) 2024 Jorijn van der Graaf
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
module;
|
||||
#include <string>
|
||||
module Crafter.Build:DependencyImpl;
|
||||
import :Dependency;
|
||||
using namespace Crafter::Build;
|
||||
|
||||
Dependency::Dependency(std::string path, std::string configuration, std::string filename): path(path), configuration(configuration), filename(filename) {
|
||||
|
||||
}
|
||||
33
Crafter.Build-Dependency.cppm
Normal file
33
Crafter.Build-Dependency.cppm
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Crafter.Build
|
||||
* Copyright (C) 2024 Jorijn van der Graaf
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
module;
|
||||
#include <string>
|
||||
export module Crafter.Build:Dependency;
|
||||
|
||||
export namespace Crafter::Build {
|
||||
class Dependency {
|
||||
public:
|
||||
std::string path;
|
||||
std::string filename;
|
||||
std::string configuration;
|
||||
Dependency(std::string path, std::string configuration, std::string filename);
|
||||
};
|
||||
}
|
||||
|
|
@ -26,90 +26,18 @@ module;
|
|||
#include "json.hpp"
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include <stdlib.h>
|
||||
module Crafter.Build:ProjectImpl;
|
||||
import :Project;
|
||||
import :Configuration;
|
||||
import :Dependency;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
Project::Project(std::string name, std::vector<Configuration> configurations) : name(name), configurations(configurations) {
|
||||
Project::Project(std::string name, fs::path path, std::vector<Configuration> configurations) : name(name), path(path), configurations(configurations) {
|
||||
|
||||
}
|
||||
|
||||
struct ConfigData {
|
||||
std::string standard;
|
||||
std::vector<std::string> sourceFiles;
|
||||
std::vector<std::string> moduleFiles;
|
||||
std::string optimizationLevel;
|
||||
std::string buildDir;
|
||||
std::string outputDir;
|
||||
std::string type;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
ConfigData CollapseConfig(nlohmann::json& configs,nlohmann::json& config) {
|
||||
ConfigData data;
|
||||
if(config.contains("standard")) {
|
||||
data.standard = config["standard"].get<std::string>();
|
||||
}
|
||||
if(config.contains("target")) {
|
||||
data.target = config["target"].get<std::string>();
|
||||
}
|
||||
if(config.contains("type")) {
|
||||
data.type = config["type"].get<std::string>();
|
||||
}
|
||||
if(config.contains("source_files")) {
|
||||
data.sourceFiles = config["source_files"].get<std::vector<std::string>>();
|
||||
}
|
||||
if(config.contains("module_files")) {
|
||||
data.moduleFiles = config["module_files"].get<std::vector<std::string>>();
|
||||
}
|
||||
if(config.contains("optimization_level")) {
|
||||
data.optimizationLevel = config["optimization_level"].get<std::string>();
|
||||
}
|
||||
if(config.contains("build_dir")) {
|
||||
data.buildDir = config["build_dir"].get<std::string>();
|
||||
}
|
||||
if(config.contains("output_dir")) {
|
||||
data.outputDir = config["output_dir"].get<std::string>();
|
||||
}
|
||||
if(config.contains("extends")){
|
||||
const std::vector<std::string> extends = config["extends"].get<std::vector<std::string>>();
|
||||
for(const std::string& extendName : extends) {
|
||||
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
|
||||
if((*it)["name"].get<std::string>() == extendName){
|
||||
ConfigData extendData = CollapseConfig(configs, (*it));
|
||||
if(!extendData.standard.empty() && data.standard.empty()){
|
||||
data.standard = extendData.standard;
|
||||
}
|
||||
if(!extendData.sourceFiles.empty()){
|
||||
data.sourceFiles.insert(data.sourceFiles.end(), extendData.sourceFiles.begin(), extendData.sourceFiles.end());
|
||||
}
|
||||
if(!extendData.moduleFiles.empty()){
|
||||
data.moduleFiles.insert(data.moduleFiles.end(), extendData.moduleFiles.begin(), extendData.moduleFiles.end());
|
||||
}
|
||||
if(!extendData.optimizationLevel.empty() && data.standard.empty()){
|
||||
data.optimizationLevel = extendData.optimizationLevel;
|
||||
}
|
||||
if(!extendData.buildDir.empty() && data.buildDir.empty()) {
|
||||
data.buildDir = extendData.buildDir;
|
||||
}
|
||||
if(!extendData.outputDir.empty() && data.outputDir.empty()) {
|
||||
data.outputDir = extendData.outputDir;
|
||||
}
|
||||
if(!extendData.target.empty() && data.target.empty()) {
|
||||
data.target = extendData.target;
|
||||
}
|
||||
if(!extendData.type.empty() && data.type.empty()) {
|
||||
data.type = extendData.type;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void Project::Build(std::string configuration) {
|
||||
for(const Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
|
|
@ -120,7 +48,7 @@ void Project::Build(std::string configuration) {
|
|||
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||
}
|
||||
|
||||
void Project::Build(std::string configuration, std::string outputDir) {
|
||||
void Project::Build(std::string configuration, fs::path outputDir) {
|
||||
for(const Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, outputDir);
|
||||
|
|
@ -134,19 +62,19 @@ void Project::Build(Configuration configuration) {
|
|||
Build(configuration, configuration.outputDir);
|
||||
}
|
||||
|
||||
void Project::Build(Configuration config, std::string outputDir) {
|
||||
if (!std::filesystem::exists(config.buildDir)) {
|
||||
std::filesystem::create_directory(config.buildDir);
|
||||
void Project::Build(Configuration config, fs::path outputDir) {
|
||||
if (!fs::exists(config.buildDir)) {
|
||||
fs::create_directory(config.buildDir);
|
||||
} else {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(config.buildDir)){
|
||||
std::filesystem::remove_all(entry.path());
|
||||
for (const auto& entry : fs::directory_iterator(config.buildDir)){
|
||||
fs::remove_all(entry.path());
|
||||
}
|
||||
}
|
||||
if (!std::filesystem::exists(outputDir)) {
|
||||
std::filesystem::create_directory(outputDir);
|
||||
if (!fs::exists(outputDir)) {
|
||||
fs::create_directory(outputDir);
|
||||
} else {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(outputDir)){
|
||||
std::filesystem::remove_all(entry.path());
|
||||
for (const auto& entry : fs::directory_iterator(outputDir)){
|
||||
fs:remove_all(entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,67 +82,70 @@ void Project::Build(Configuration config, std::string outputDir) {
|
|||
if(!config.target.empty()){
|
||||
target = std::format("-target {}", config.target);
|
||||
}
|
||||
std::string pcmDir;
|
||||
fs::path pcmDir;
|
||||
if(config.type == "library" || config.type == "shared-library"){
|
||||
pcmDir = outputDir;
|
||||
}else{
|
||||
pcmDir = config.buildDir;
|
||||
}
|
||||
|
||||
std::string clangDir;
|
||||
if(config.target == "wasm32-unknown-wasi" || config.target == "wasm64-unknown-wasi"){
|
||||
clangDir = "${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot";
|
||||
clangDir = "${WASI_SDK_PATH}/bin/clang++ --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -Wno-unused-command-line-argument";
|
||||
name+=".wasm";
|
||||
} else{
|
||||
clangDir = "clang++";
|
||||
}
|
||||
|
||||
if(config.target == "wasm32" || config.target == "wasm64") {
|
||||
} else if(config.target == "wasm32" || config.target == "wasm64") {
|
||||
clangDir = "${WASI_SDK_PATH}/bin/clang++ --no-standard-libraries -Wl,--no-entry -Wl,--export-all -Wno-unused-command-line-argument";
|
||||
name+=".wasm";
|
||||
} else {
|
||||
clangDir = "clang++ -Wno-unused-command-line-argument";
|
||||
}
|
||||
|
||||
for(const std::string& moduleFile : config.moduleFiles){
|
||||
system(std::format("{} -std={} {}.cppm --precompile -fprebuilt-module-path={} -o {}/{}.pcm {}", clangDir, config.standard, moduleFile, pcmDir, pcmDir, moduleFile, target).c_str());
|
||||
//clangDir+= std::format(" -I {} ", pcmDir);
|
||||
|
||||
for(const fs::path& moduleFile : config.moduleFiles){
|
||||
system(std::format("{} -std={} {}.cppm --precompile -fprebuilt-module-path={} -o {}.pcm {}", clangDir, config.standard, moduleFile.generic_string(), pcmDir.generic_string(), (pcmDir/moduleFile.filename()).generic_string(), target).c_str());
|
||||
}
|
||||
std::vector<std::thread> threads = std::vector<std::thread>(config.moduleFiles.size() + config.sourceFiles.size());
|
||||
std::string files;
|
||||
for(std::int_fast32_t i = 0; i < config.moduleFiles.size(); i++) {
|
||||
files+=std::format("{}/{}.o ",config.buildDir, config.moduleFiles[i]);
|
||||
files+=std::format("{}.o ",(config.buildDir/config.moduleFiles[i].filename()).generic_string());
|
||||
threads[i] = std::thread([i, config, pcmDir, target, clangDir](){
|
||||
system(std::format("{} -std={} {}/{}.pcm -fprebuilt-module-path={} -c -O{} -o {}/{}.o {}", clangDir, config.standard, pcmDir, config.moduleFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.moduleFiles[i], target).c_str());
|
||||
system(std::format("{} -std={} {}.pcm -fprebuilt-module-path={} -c -O{} -o {}.o {}", clangDir, config.standard, (pcmDir/config.moduleFiles[i].filename()).generic_string(), pcmDir.generic_string(), config.optimizationLevel, (config.buildDir/config.moduleFiles[i].filename()).generic_string(), target).c_str());
|
||||
});
|
||||
}
|
||||
for(std::int_fast32_t i = 0; i < config.sourceFiles.size(); i++) {
|
||||
files+=std::format("{}/{}_source.o ",config.buildDir, config.sourceFiles[i]);
|
||||
files+=std::format("{}_source.o ",(config.buildDir/config.sourceFiles[i].filename()).generic_string());
|
||||
threads[config.moduleFiles.size()+i] = std::thread([i, config, pcmDir, target, clangDir](){
|
||||
system(std::format("{} -std={} {}.cpp -fprebuilt-module-path={} -c -O{} -o {}/{}_source.o {}", clangDir, config.standard, config.sourceFiles[i], pcmDir, config.optimizationLevel, config.buildDir, config.sourceFiles[i], target).c_str());
|
||||
system(std::format("{} -std={} {}.cpp -fprebuilt-module-path={} -c -O{} -o {}_source.o {}", clangDir, config.standard, config.sourceFiles[i].generic_string(), pcmDir.generic_string(), config.optimizationLevel, (config.buildDir/config.sourceFiles[i].filename()).generic_string(), target).c_str());
|
||||
});
|
||||
}
|
||||
for(std::thread& thread : threads){
|
||||
thread.join();
|
||||
}
|
||||
if(config.type == "executable"){
|
||||
system(std::format("{} {}-O{} -o {}/{} {}", clangDir, files, config.optimizationLevel, outputDir, name, target).c_str());
|
||||
system(std::format("{} {}-O{} -o {} {}", clangDir, files, config.optimizationLevel, (outputDir/name).generic_string(), target).c_str());
|
||||
} else if(config.type == "library"){
|
||||
system(std::format("ar r {}/{}.a {}", clangDir, outputDir, name, files, target).c_str());
|
||||
system(std::format("ar r {}.a {}", (outputDir/name).generic_string(), files).c_str());
|
||||
} else if(config.type == "shared-library"){
|
||||
system(std::format("ar r {}/{}.so {} -shared", outputDir, name, files, target).c_str());
|
||||
system(std::format("ar r {}.so {} -shared", (outputDir/name).generic_string(), files).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Project Project::LoadFromJSON(std::string file) {
|
||||
if (!std::filesystem::exists(file)) {
|
||||
throw std::runtime_error("Project file: " + file + " not found.");
|
||||
Project Project::LoadFromJSON(fs::path path) {
|
||||
if (!fs::exists(path)) {
|
||||
throw std::runtime_error(std::format("Project file: {} not found.", path.generic_string()));
|
||||
}
|
||||
std::ifstream f(file);
|
||||
|
||||
std::ifstream f(path);
|
||||
nlohmann::json data = nlohmann::json::parse(f);
|
||||
const std::string name = data["name"].get<std::string>();
|
||||
std::vector<Configuration> configurations;
|
||||
nlohmann::json configs = data["configurations"];
|
||||
|
||||
const fs::path workingDir = path.remove_filename();
|
||||
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
|
||||
ConfigData configData = CollapseConfig(configs, (*it));
|
||||
configurations.emplace_back((*it)["name"].get<std::string>(), configData.standard, configData.sourceFiles, configData.moduleFiles, configData.optimizationLevel, configData.buildDir, configData.outputDir,configData.type, configData.target);
|
||||
configurations.emplace_back(configs, (*it), workingDir);
|
||||
}
|
||||
return Project(name,configurations);
|
||||
return Project(name, workingDir, configurations);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,20 +21,23 @@ USA
|
|||
module;
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
export module Crafter.Build:Project;
|
||||
import :Configuration;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
export namespace Crafter::Build {
|
||||
class Project {
|
||||
public:
|
||||
std::string name;
|
||||
fs::path path;
|
||||
std::vector<Configuration> configurations;
|
||||
Project(std::string name, 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, std::string outputDir);
|
||||
void Build(std::string configuration, fs::path outputDir);
|
||||
void Build(Configuration configuration);
|
||||
void Build(Configuration configuration, std::string outputDir);
|
||||
void SaveToJSON(std::string path);
|
||||
static Project LoadFromJSON(std::string file);
|
||||
void Build(Configuration configuration, fs::path outputDir);
|
||||
void SaveToJSON(fs::path path);
|
||||
static Project LoadFromJSON(fs::path path);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ USA
|
|||
*/
|
||||
|
||||
export module Crafter.Build;
|
||||
export import :Dependency;
|
||||
export import :Project;
|
||||
export import :Configuration;
|
||||
|
|
|
|||
7
build.sh
7
build.sh
|
|
@ -1,14 +1,19 @@
|
|||
clear
|
||||
mkdir build
|
||||
mkdir bin
|
||||
|
||||
clang++ -std=c++26 Crafter.Build-Dependency.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Dependency.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Configuration.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Configuration.pcm
|
||||
clang++ -std=c++26 Crafter.Build-Project.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build-Project.pcm
|
||||
clang++ -std=c++26 Crafter.Build.cppm --precompile -fprebuilt-module-path=./build -o ./build/Crafter.Build.pcm
|
||||
|
||||
clang++ -std=c++26 Crafter.Build-Dependency.cpp -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Dependency_source.o
|
||||
clang++ -std=c++26 Crafter.Build-Configuration.cpp -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Configuration_source.o
|
||||
clang++ -std=c++26 Crafter.Build-Project.cpp -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Project_source.o
|
||||
clang++ -std=c++26 main.cpp -fprebuilt-module-path=./build -c -o ./build/main.o
|
||||
|
||||
clang++ -std=c++26 ./build/Crafter.Build-Project.pcm -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Project.o
|
||||
clang++ -std=c++26 ./build/Crafter.Build-Configuration.pcm -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Configuration.o
|
||||
clang++ -std=c++26 ./build/Crafter.Build-Dependency.pcm -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build-Dependency.o
|
||||
clang++ -std=c++26 ./build/Crafter.Build.pcm -fprebuilt-module-path=./build -c -O3 -o ./build/Crafter.Build.o
|
||||
clang++ ./build/main.o ./build/Crafter.Build.o ./build/Crafter.Build-Configuration.o ./build/Crafter.Build-Configuration_source.o ./build/Crafter.Build-Project.o ./build/Crafter.Build-Project_source.o -O3 -o ./bin/crafter-build
|
||||
clang++ ./build/main.o ./build/Crafter.Build.o ./build/Crafter.Build-Configuration.o ./build/Crafter.Build-Configuration_source.o ./build/Crafter.Build-Project.o ./build/Crafter.Build-Project_source.o ./build/Crafter.Build-Dependency.o ./build/Crafter.Build-Dependency_source.o -O3 -o ./bin/crafter-build
|
||||
|
|
|
|||
21
main.cpp
21
main.cpp
|
|
@ -23,35 +23,46 @@ USA
|
|||
#include <fstream>
|
||||
#include <print>
|
||||
#include "json.hpp"
|
||||
#include <linux/limits.h>
|
||||
#include <unistd.h>
|
||||
import Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
int main(int argc, char* argv[]) {
|
||||
if(argc == 1) {
|
||||
std::println("No arguments provided, use --help for help");
|
||||
}
|
||||
std::string filename = "project.json";
|
||||
fs::path filepath = "project.json";
|
||||
std::string configuration;
|
||||
std::string outputDir;
|
||||
for (std::uint_fast32_t i = 1; i < argc; i++) {
|
||||
std::string arg = std::string(argv[i]);
|
||||
if(arg == "--help"){
|
||||
std::println("--help\tDisplays this help message.\n-c The name of the configuration to build.\n-p\nThe name of the project file.\n-o Overrides the output folder.\n");
|
||||
std::println("--help\tDisplays this help message.\n-c The name of the configuration to build.\n-p The path to the project file.\n-o Overrides the output folder.\n");
|
||||
return 0;
|
||||
} else if(arg == "-c"){
|
||||
configuration = argv[++i];
|
||||
} else if(arg == "-o"){
|
||||
outputDir = argv[++i];
|
||||
} else if(arg == "-p"){
|
||||
filename = argv[++i];
|
||||
filepath = fs::path(argv[++i]);
|
||||
} else{
|
||||
std::println("Unkown argument: {}", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Project project = Project::LoadFromJSON(filename);
|
||||
|
||||
fs::path projectPath;
|
||||
if(filepath.is_relative()){
|
||||
projectPath = fs::current_path()/filepath;
|
||||
}else{
|
||||
projectPath = filepath;
|
||||
}
|
||||
|
||||
Project project = Project::LoadFromJSON(projectPath);
|
||||
if(outputDir.empty()){
|
||||
project.Build(configuration);
|
||||
} else{
|
||||
project.Build(configuration, outputDir);
|
||||
project.Build(configuration, fs::path(outputDir));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
{
|
||||
"name": "base",
|
||||
"standard": "c++26",
|
||||
"source_files": ["main", "Crafter.Build-Configuration", "Crafter.Build-Project"],
|
||||
"module_files": ["Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build"],
|
||||
"source_files": ["Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build-Dependency"],
|
||||
"module_files": ["Crafter.Build-Dependency", "Crafter.Build-Configuration", "Crafter.Build-Project", "Crafter.Build"],
|
||||
"build_dir": "./build",
|
||||
"output_dir": "./bin"
|
||||
},
|
||||
{
|
||||
"name": "executable",
|
||||
"extends": ["base"],
|
||||
"type":"executable"
|
||||
"type":"executable",
|
||||
"source_files": ["main"]
|
||||
},
|
||||
{
|
||||
"name": "lib",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue