added additional_files
This commit is contained in:
parent
c0a54c8282
commit
914992cba9
5 changed files with 51 additions and 9 deletions
|
|
@ -24,7 +24,7 @@ module Crafter.Build;
|
||||||
using namespace Crafter::Build;
|
using namespace Crafter::Build;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
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(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, std::vector<fs::path> additionalFiles): name(name), standard(standard), sourceFiles(sourceFiles), moduleFiles(moduleFiles), optimizationLevel(optimizationLevel), buildDir(buildDir), outputDir(outputDir), type(type), target(target), dependencies(dependencies), additionalFiles(additionalFiles) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,6 +54,14 @@ Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json
|
||||||
const std::filesystem::path fullFilePath = workingDir / filePath;
|
const std::filesystem::path fullFilePath = workingDir / filePath;
|
||||||
moduleFiles[i] = fullFilePath.generic_string();
|
moduleFiles[i] = fullFilePath.generic_string();
|
||||||
}
|
}
|
||||||
|
} else if(key == "additional_files") {
|
||||||
|
const std::vector<std::string> tempAdditionalFiles = val.get<std::vector<std::string>>();
|
||||||
|
additionalFiles = std::vector<fs::path>(tempAdditionalFiles.size());
|
||||||
|
for(std::int_fast32_t i = 0; i < additionalFiles.size(); i++){
|
||||||
|
const std::filesystem::path filePath (tempAdditionalFiles[i]);
|
||||||
|
const std::filesystem::path fullFilePath = workingDir / filePath;
|
||||||
|
additionalFiles[i] = fullFilePath.generic_string();
|
||||||
|
}
|
||||||
} else if(key == "optimization_level") {
|
} else if(key == "optimization_level") {
|
||||||
optimizationLevel = val.get<std::string>();
|
optimizationLevel = val.get<std::string>();
|
||||||
} else if(key == "build_dir") {
|
} else if(key == "build_dir") {
|
||||||
|
|
@ -89,6 +97,9 @@ Configuration::Configuration(const nlohmann::json& configs, const nlohmann::json
|
||||||
if(!extendData.moduleFiles.empty()){
|
if(!extendData.moduleFiles.empty()){
|
||||||
moduleFiles.insert(moduleFiles.end(), extendData.moduleFiles.begin(), extendData.moduleFiles.end());
|
moduleFiles.insert(moduleFiles.end(), extendData.moduleFiles.begin(), extendData.moduleFiles.end());
|
||||||
}
|
}
|
||||||
|
if(!extendData.additionalFiles.empty()){
|
||||||
|
additionalFiles.insert(additionalFiles.end(), extendData.additionalFiles.begin(), extendData.additionalFiles.end());
|
||||||
|
}
|
||||||
if(!extendData.optimizationLevel.empty() && optimizationLevel.empty()){
|
if(!extendData.optimizationLevel.empty() && optimizationLevel.empty()){
|
||||||
optimizationLevel = extendData.optimizationLevel;
|
optimizationLevel = extendData.optimizationLevel;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ export namespace Crafter::Build {
|
||||||
std::string standard;
|
std::string standard;
|
||||||
std::vector<fs::path> sourceFiles;
|
std::vector<fs::path> sourceFiles;
|
||||||
std::vector<fs::path> moduleFiles;
|
std::vector<fs::path> moduleFiles;
|
||||||
|
std::vector<fs::path> additionalFiles;
|
||||||
std::string optimizationLevel;
|
std::string optimizationLevel;
|
||||||
std::string buildDir;
|
std::string buildDir;
|
||||||
std::string outputDir;
|
std::string outputDir;
|
||||||
|
|
@ -42,7 +43,7 @@ export namespace Crafter::Build {
|
||||||
std::string target;
|
std::string target;
|
||||||
std::vector<Dependency> dependencies;
|
std::vector<Dependency> dependencies;
|
||||||
std::unordered_map<std::string, nlohmann::json> additionalProperties;
|
std::unordered_map<std::string, nlohmann::json> additionalProperties;
|
||||||
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(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, std::vector<fs::path> additionalFiles);
|
||||||
Configuration(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir);
|
Configuration(const nlohmann::json& configs, const nlohmann::json& config, fs::path workingDir);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ Project::Project(std::string name, fs::path path, std::vector<Configuration> con
|
||||||
void Project::Build(std::string configuration) const {
|
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -55,11 +55,25 @@ void Project::Build(std::string configuration, fs::path outputDir) const {
|
||||||
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, fs::path binDir) const {
|
||||||
|
for(const Configuration& config : configurations) {
|
||||||
|
if(config.name == configuration){
|
||||||
|
Build(config, outputDir, binDir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw std::runtime_error("Configuration: " + configuration + " not found.");
|
||||||
|
}
|
||||||
|
|
||||||
void Project::Build(Configuration configuration) const {
|
void Project::Build(Configuration configuration) const {
|
||||||
Build(configuration, configuration.outputDir);
|
Build(configuration, configuration.outputDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::Build(Configuration config, fs::path outputDir) const {
|
void Project::Build(Configuration config, fs::path outputDir) const {
|
||||||
|
Build(config, outputDir, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) const {
|
||||||
if (!fs::exists(config.buildDir)) {
|
if (!fs::exists(config.buildDir)) {
|
||||||
fs::create_directory(config.buildDir);
|
fs::create_directory(config.buildDir);
|
||||||
}
|
}
|
||||||
|
|
@ -89,8 +103,8 @@ void Project::Build(Configuration config, fs::path outputDir) const {
|
||||||
for(std::int_fast32_t i = 0; i < depThreads.size(); i++) {
|
for(std::int_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||||
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
||||||
libs+=std::format(" -l{}", project.name);
|
libs+=std::format(" -l{}", project.name);
|
||||||
depThreads[i] = std::thread([i, pcmDir, config, project]() {
|
depThreads[i] = std::thread([i, pcmDir, config, project, binDir]() {
|
||||||
project.Build(config.dependencies[i].configuration, pcmDir);
|
project.Build(config.dependencies[i].configuration, pcmDir, binDir);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,11 +112,15 @@ void Project::Build(Configuration config, fs::path outputDir) const {
|
||||||
|
|
||||||
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 -Wl,--export-all -fno-exceptions";
|
||||||
name+=".wasm";
|
if(config.type != "library") {
|
||||||
|
name+=".wasm";
|
||||||
|
}
|
||||||
} else 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";
|
clangDir = "${WASI_SDK_PATH}/bin/clang++ --no-standard-libraries -Wl,--no-entry -Wl,--export-all -Wno-unused-command-line-argument -fno-exceptions";
|
||||||
name+=".wasm";
|
if(config.type != "library") {
|
||||||
|
name+=".wasm";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
clangDir = "clang++ -Wno-unused-command-line-argument";
|
clangDir = "clang++ -Wno-unused-command-line-argument";
|
||||||
}
|
}
|
||||||
|
|
@ -145,6 +163,14 @@ void Project::Build(Configuration config, fs::path outputDir) const {
|
||||||
system(std::format("ar r {}.so {} -shared", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
system(std::format("ar r {}.so {} -shared", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(const fs::path& additionalFile : config.additionalFiles){
|
||||||
|
if(!fs::exists(binDir/additionalFile.filename())) {
|
||||||
|
fs::copy(additionalFile, binDir);
|
||||||
|
} else if (fs::last_write_time(additionalFile) > fs::last_write_time(binDir/additionalFile.filename())){
|
||||||
|
fs::remove(binDir/additionalFile.filename());
|
||||||
|
fs::copy(additionalFile, binDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Project Project::LoadFromJSON(fs::path path) {
|
Project Project::LoadFromJSON(fs::path path) {
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,10 @@ export namespace Crafter::Build {
|
||||||
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) const;
|
void Build(std::string configuration) const;
|
||||||
void Build(std::string configuration, fs::path outputDir) const;
|
void Build(std::string configuration, fs::path outputDir) const;
|
||||||
|
void Build(std::string configuration, fs::path outputDir, fs::path binDir) const;
|
||||||
void Build(Configuration configuration) const;
|
void Build(Configuration configuration) const;
|
||||||
void Build(Configuration configuration, fs::path outputDir) const;
|
void Build(Configuration configuration, fs::path outputDir) const;
|
||||||
|
void Build(Configuration configuration, fs::path outputDir, fs::path binDir) const;
|
||||||
void SaveToJSON(fs::path path) const;
|
void SaveToJSON(fs::path path) const;
|
||||||
static Project LoadFromJSON(fs::path path);
|
static Project LoadFromJSON(fs::path path);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ Save and close, then run ``crafter-build -c debug``. Now you can run the ``hello
|
||||||
|
|
||||||
``module_files`` All C++ 20 module files of the project ``.cppm`` extension is assumed.
|
``module_files`` All C++ 20 module files of the project ``.cppm`` extension is assumed.
|
||||||
|
|
||||||
|
``additional_files`` Files that will be copied to the output_dir.
|
||||||
|
|
||||||
``build_dir`` The directory where intermediate files are stored.
|
``build_dir`` The directory where intermediate files are stored.
|
||||||
|
|
||||||
``output_dir`` The directory where the output files will be placed.
|
``output_dir`` The directory where the output files will be placed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue