test fixes
This commit is contained in:
parent
0eed272765
commit
c63f3430a5
12 changed files with 4207 additions and 118 deletions
4
build.sh
4
build.sh
|
|
@ -1,5 +1,7 @@
|
||||||
mkdir build
|
mkdir build
|
||||||
mkdir bin
|
mkdir bin
|
||||||
|
mkdir bin/executable
|
||||||
|
|
||||||
|
|
||||||
GCC_VERSION=$(g++ -dumpversion)
|
GCC_VERSION=$(g++ -dumpversion)
|
||||||
STD_HEADER="/usr/include/c++/$GCC_VERSION/bits/std.cc"
|
STD_HEADER="/usr/include/c++/$GCC_VERSION/bits/std.cc"
|
||||||
|
|
@ -38,7 +40,7 @@ clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Craft
|
||||||
clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Project.cpp -o ./build/Crafter.Build-Project_impl.o
|
clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Project.cpp -o ./build/Crafter.Build-Project_impl.o
|
||||||
clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/main.cpp -o ./build/main.o
|
clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/main.cpp -o ./build/main.o
|
||||||
|
|
||||||
clang++ -std=c++26 -O3 -L/usr/local/lib -L/usr/lib/ -lvulkan -lMachineIndependent -lOSDependent -lGenericCodeGen -lglslang -lglslang-default-resource-limits -lSPIRV -ltbb -fuse-ld=lld ./build/Crafter.Build-Command.o ./build/Crafter.Build-FixedVector.o ./build/Crafter.Build-Shader.o ./build/Crafter.Build-Module.o ./build/Crafter.Build-Configuration.o ./build/Crafter.Build-Project.o ./build/Crafter.Build.o ./build/Crafter.Build-Command_impl.o ./build/Crafter.Build-Shader_impl.o ./build/Crafter.Build-Module_impl.o ./build/Crafter.Build-Configuration_impl.o ./build/Crafter.Build-Project_impl.o ./build/Crafter.Build-Implementation.o ./build/Crafter.Build-Implementation_impl.o ./build/Crafter.Build-Test_impl.o ./build/Crafter.Build-Test.o ./build/main.o -o ./bin/crafter-build
|
clang++ -std=c++26 -O3 -L/usr/local/lib -L/usr/lib/ -lvulkan -lMachineIndependent -lOSDependent -lGenericCodeGen -lglslang -lglslang-default-resource-limits -lSPIRV -ltbb -fuse-ld=lld ./build/Crafter.Build-Command.o ./build/Crafter.Build-FixedVector.o ./build/Crafter.Build-Shader.o ./build/Crafter.Build-Module.o ./build/Crafter.Build-Configuration.o ./build/Crafter.Build-Project.o ./build/Crafter.Build.o ./build/Crafter.Build-Command_impl.o ./build/Crafter.Build-Shader_impl.o ./build/Crafter.Build-Module_impl.o ./build/Crafter.Build-Configuration_impl.o ./build/Crafter.Build-Project_impl.o ./build/Crafter.Build-Implementation.o ./build/Crafter.Build-Implementation_impl.o ./build/Crafter.Build-Test_impl.o ./build/Crafter.Build-Test.o ./build/main.o -o ./bin/executable/crafter-build
|
||||||
|
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,12 +218,6 @@ namespace Crafter {
|
||||||
additionalFiles.push_back( workingDir / file);
|
additionalFiles.push_back( workingDir / file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(config.contains("build_dir")) {
|
|
||||||
buildDir = workingDir / config["build_dir"].get<std::string>();
|
|
||||||
}
|
|
||||||
if(config.contains("output_dir")) {
|
|
||||||
outputDir = workingDir / config["output_dir"].get<std::string>();
|
|
||||||
}
|
|
||||||
if(config.contains("dependencies")) {
|
if(config.contains("dependencies")) {
|
||||||
for (auto it : config["dependencies"]) {
|
for (auto it : config["dependencies"]) {
|
||||||
std::string commit;
|
std::string commit;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Crafter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Implementation::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir) const {
|
void Implementation::Compile(const std::string_view clang, const fs::path& buildDir) const {
|
||||||
for(ModulePartition* dependency : partitionDependencies) {
|
for(ModulePartition* dependency : partitionDependencies) {
|
||||||
if(!dependency->compiled.load()) {
|
if(!dependency->compiled.load()) {
|
||||||
dependency->compiled.wait(false);
|
dependency->compiled.wait(false);
|
||||||
|
|
@ -56,6 +56,6 @@ namespace Crafter {
|
||||||
dependency->compiled.wait(false);
|
dependency->compiled.wait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RunClang(std::format("{} {}.cpp -fprebuilt-module-path={} -fprebuilt-module-path={} -c -o {}_impl.o", clang, path.string(), pcmDir.string(), buildDir.parent_path().string(), (buildDir/path.filename()).string()));
|
RunClang(std::format("{} {}.cpp -c -o {}_impl.o", clang, path.string(), (buildDir/path.filename()).string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ namespace Crafter {
|
||||||
dependency->compiled.wait(false);
|
dependency->compiled.wait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RunClang(std::format("{} {}.cppm --precompile -fprebuilt-module-path={} -fprebuilt-module-path={} -o {}.pcm", clang, path.string(), pcmDir.string(), buildDir.parent_path().string(), (pcmDir/path.filename()).string()));
|
RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||||
RunClang(std::format("{} {}.pcm -fprebuilt-module-path={} -fprebuilt-module-path={} -c -o {}.o", clang, (pcmDir/path.filename()).string(), pcmDir.string(), buildDir.parent_path().string(), (buildDir/path.filename()).string()));
|
RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||||
compiled.store(true);
|
compiled.store(true);
|
||||||
compiled.notify_all();
|
compiled.notify_all();
|
||||||
}
|
}
|
||||||
|
|
@ -130,8 +130,8 @@ namespace Crafter {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
RunClang(std::format("{} {}.cppm --precompile -fprebuilt-module-path={} -fprebuilt-module-path={} -o {}.pcm", clang, path.string(), pcmDir.string(), buildDir.parent_path().string(), (pcmDir/path.filename()).string()));
|
RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||||
RunClang(std::format("{} {}.pcm -fprebuilt-module-path={} -fprebuilt-module-path={} -c -o {}.o", clang, (pcmDir/path.filename()).string(), pcmDir.string(), buildDir.parent_path().string(), (buildDir/path.filename()).string()));
|
RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||||
|
|
||||||
compiled.store(true);
|
compiled.store(true);
|
||||||
compiled.notify_all();
|
compiled.notify_all();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
module;
|
module;
|
||||||
#include "../lib/json.hpp"
|
#include "../lib/json.hpp"
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <stdlib.h>
|
||||||
module Crafter.Build:Project_impl;
|
module Crafter.Build:Project_impl;
|
||||||
import :Project;
|
import :Project;
|
||||||
import std;
|
import std;
|
||||||
|
|
@ -38,55 +39,55 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||||
}
|
}
|
||||||
Configuration& Project::Build(std::string_view configuration, const fs::path& outputDir) {
|
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir) {
|
||||||
for(Configuration& config : configurations) {
|
for(Configuration& config : configurations) {
|
||||||
if(config.name == configuration){
|
if(config.name == configuration){
|
||||||
Build(config, outputDir);
|
Build(config, binDir, name);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||||
}
|
}
|
||||||
Configuration& Project::Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir) {
|
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& buildDir) {
|
||||||
for(Configuration& config : configurations) {
|
for(Configuration& config : configurations) {
|
||||||
if(config.name == configuration){
|
if(config.name == configuration){
|
||||||
Build(config, outputDir, binDir);
|
Build(config, binDir, buildDir, name);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||||
}
|
}
|
||||||
Configuration& Project::Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir, const fs::path& buildDir) {
|
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& buildDir, const std::string_view outputName) {
|
||||||
for(Configuration& config : configurations) {
|
for(Configuration& config : configurations) {
|
||||||
if(config.name == configuration){
|
if(config.name == configuration){
|
||||||
Build(config, outputDir, binDir, buildDir);
|
Build(config, binDir, buildDir, outputName);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||||
}
|
}
|
||||||
void Project::Build(Configuration& config) const {
|
void Project::Build(Configuration& config) const {
|
||||||
if(config.outputDir.empty()) {
|
if(binDir.empty()) {
|
||||||
Build(config, "bin");
|
Build(config, "bin"/fs::path(config.name));
|
||||||
} else {
|
} else {
|
||||||
Build(config, config.outputDir);
|
Build(config, this->binDir/config.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Project::Build(Configuration& config, const fs::path& outputDir) const {
|
void Project::Build(Configuration& config, const fs::path& binDir) const {
|
||||||
Build(config, outputDir, outputDir);
|
|
||||||
}
|
|
||||||
void Project::Build(Configuration& config, const fs::path& outputDir, const fs::path& binDir) const {
|
|
||||||
fs::path buildDir;
|
fs::path buildDir;
|
||||||
if(config.buildDir.empty()) {
|
if(this->buildDir.empty()) {
|
||||||
buildDir = "build"/fs::path(config.name);
|
buildDir = "build"/fs::path(config.name);
|
||||||
} else {
|
} else {
|
||||||
buildDir = config.buildDir/config.name;
|
buildDir = this->buildDir/config.name;
|
||||||
}
|
}
|
||||||
Build(config, outputDir, binDir, buildDir);
|
Build(config, binDir, buildDir, name);
|
||||||
}
|
}
|
||||||
void Project::Build(Configuration& config, const fs::path& outputDir, const fs::path& binDir, const fs::path& buildDir) const {
|
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& buildDir) const {
|
||||||
if (!fs::exists(outputDir)) {
|
Build(config, binDir, buildDir, name);
|
||||||
fs::create_directories(outputDir);
|
}
|
||||||
|
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& buildDir, const std::string_view outputName) const {
|
||||||
|
if (!fs::exists(binDir)) {
|
||||||
|
fs::create_directories(binDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs::exists(buildDir)) {
|
if (!fs::exists(buildDir)) {
|
||||||
|
|
@ -95,7 +96,7 @@ namespace Crafter {
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for(const Shader& shader : config.shaders) {
|
for(const Shader& shader : config.shaders) {
|
||||||
if(shader.Check(outputDir)) {
|
if(shader.Check(binDir)) {
|
||||||
threads.emplace_back(&Shader::Compile, &shader, binDir);
|
threads.emplace_back(&Shader::Compile, &shader, binDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +112,6 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
std::string command = "clang++";
|
std::string command = "clang++";
|
||||||
if(!config.target.empty()) {
|
if(!config.target.empty()) {
|
||||||
command += std::format(" -target={}", config.target);
|
command += std::format(" -target={}", config.target);
|
||||||
|
|
@ -131,11 +131,11 @@ namespace Crafter {
|
||||||
fs::path pcmDir;
|
fs::path pcmDir;
|
||||||
|
|
||||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_SHARED_LIBRARY) {
|
if(config.type == CRAFTER_CONFIGURATION_TYPE_SHARED_LIBRARY) {
|
||||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
command += " -fPIC -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||||
pcmDir = outputDir;
|
pcmDir = binDir;
|
||||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
||||||
pcmDir = outputDir;
|
pcmDir = binDir;
|
||||||
} else {
|
} else {
|
||||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
||||||
pcmDir = buildDir;
|
pcmDir = buildDir;
|
||||||
|
|
@ -147,6 +147,28 @@ namespace Crafter {
|
||||||
command += " -O3";
|
command += " -O3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char path[PATH_MAX];
|
||||||
|
ssize_t count = readlink("/proc/self/exe", path, PATH_MAX);
|
||||||
|
if (count == -1) {
|
||||||
|
throw std::runtime_error("Failed to get executable path");
|
||||||
|
}
|
||||||
|
path[count] = '\0';
|
||||||
|
const std::string exeDir = fs::path(path).parent_path().parent_path().string();
|
||||||
|
const std::string stdPcm = std::format("{}/std.pcm", exeDir);
|
||||||
|
std::string gccVersion = RunCommand("g++ -dumpversion");
|
||||||
|
gccVersion.pop_back();
|
||||||
|
fs::path stdCc = fs::path(std::format("/usr/include/c++/{}/bits/std.cc", gccVersion));
|
||||||
|
|
||||||
|
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
||||||
|
std::string result = RunCommand(std::format(R"(cp {} {}/std.cppm
|
||||||
|
clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/std.cppm -o {} )", stdCc.string(), exeDir, exeDir, stdPcm));
|
||||||
|
if(result != "") {
|
||||||
|
throw std::runtime_error(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), exeDir);
|
||||||
|
|
||||||
std::unordered_set<std::string> depLibSet;
|
std::unordered_set<std::string> depLibSet;
|
||||||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||||
std::mutex libMutex;
|
std::mutex libMutex;
|
||||||
|
|
@ -175,12 +197,12 @@ namespace Crafter {
|
||||||
for(Configuration& depConfig : project.configurations) {
|
for(Configuration& depConfig : project.configurations) {
|
||||||
if(depConfig.name == config.dependencies[i].configuration){
|
if(depConfig.name == config.dependencies[i].configuration){
|
||||||
fs::path depBuildDir;
|
fs::path depBuildDir;
|
||||||
if(depConfig.buildDir.empty()) {
|
if(project.buildDir.empty()) {
|
||||||
depBuildDir = "build"/fs::path(config.name);
|
depBuildDir = fs::path(config.dependencies[i].path).parent_path()/"build"/fs::path(depConfig.name);
|
||||||
} else {
|
} else {
|
||||||
depBuildDir = depConfig.buildDir/config.name;
|
depBuildDir = fs::path(config.dependencies[i].path).parent_path()/project.buildDir/depConfig.name;
|
||||||
}
|
}
|
||||||
project.Build(depConfig, pcmDir, binDir, (fs::path(config.dependencies[i].path).parent_path()/depBuildDir/depConfig.name));
|
project.Build(depConfig, binDir, depBuildDir);
|
||||||
libMutex.lock();
|
libMutex.lock();
|
||||||
if (depLibSet.insert(project.name).second) {
|
if (depLibSet.insert(project.name).second) {
|
||||||
libsString+=std::format(" -l{}", project.name);
|
libsString+=std::format(" -l{}", project.name);
|
||||||
|
|
@ -203,20 +225,6 @@ namespace Crafter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fs::exists((fs::path(buildDir).parent_path()/path.filename()).string()+".o")) {
|
|
||||||
std::string result = RunCommand(std::format(R"(GCC_VERSION=$(g++ -dumpversion)
|
|
||||||
STD_HEADER="/usr/include/c++/$GCC_VERSION/bits/std.cc"
|
|
||||||
if [ ! -f "$STD_HEADER" ]; then
|
|
||||||
echo "Cannot find std.cc for GCC $GCC_VERSION"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cp "$STD_HEADER" {}/std.cppm
|
|
||||||
clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/std.cppm -o {}/std.pcm )", fs::path(buildDir).parent_path().string(), fs::path(buildDir).parent_path().string(), fs::path(buildDir).parent_path().string()));
|
|
||||||
if(result != "") {
|
|
||||||
throw std::runtime_error(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::thread& thread : depThreads) {
|
for(std::thread& thread : depThreads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
@ -237,7 +245,7 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
for(const Implementation& implementation : config.implementations) {
|
for(const Implementation& implementation : config.implementations) {
|
||||||
if(implementation.Check(buildDir, pcmDir)) {
|
if(implementation.Check(buildDir, pcmDir)) {
|
||||||
repack = true;
|
repack = true;
|
||||||
threads.emplace_back(&Implementation::Compile, &implementation, command, pcmDir, buildDir);
|
threads.emplace_back(&Implementation::Compile, &implementation, command, buildDir);
|
||||||
}
|
}
|
||||||
files += std::format(" {}/{}_impl.o", buildDir.string(), implementation.path.filename().string());
|
files += std::format(" {}/{}_impl.o", buildDir.string(), implementation.path.filename().string());
|
||||||
}
|
}
|
||||||
|
|
@ -262,12 +270,12 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
|
|
||||||
if(repack) {
|
if(repack) {
|
||||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE){
|
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE){
|
||||||
RunClang(std::format("{}{} -o {} -fuse-ld=lld", command, files, (outputDir/name).string()));
|
RunClang(std::format("{}{} -o {} -fuse-ld=lld", command, files, (binDir/outputName).string()));
|
||||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY){
|
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY){
|
||||||
std::cout << std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).string(), files) << std::endl;
|
std::cout << std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files) << std::endl;
|
||||||
RunCommandIgnore(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).string(), files));
|
RunCommandIgnore(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
||||||
} else {
|
} else {
|
||||||
RunClang(std::format("{}{} -shared -o {}.so -fuse-ld=lld", command, files, (outputDir/name).string()));
|
RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -280,13 +288,15 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
std::ifstream f(path);
|
std::ifstream f(path);
|
||||||
nlohmann::json data = nlohmann::json::parse(f);
|
nlohmann::json data = nlohmann::json::parse(f);
|
||||||
std::string name = data["name"].get<std::string>();
|
std::string name = data["name"].get<std::string>();
|
||||||
|
|
||||||
|
fs::path workingDir = path;
|
||||||
|
workingDir.remove_filename();
|
||||||
|
|
||||||
std::vector<Configuration> configurations;
|
std::vector<Configuration> configurations;
|
||||||
nlohmann::json configs = data["configurations"];
|
nlohmann::json configs = data["configurations"];
|
||||||
std::vector<Test> tests;
|
std::vector<Test> tests;
|
||||||
nlohmann::json testJson = data["tests"];
|
nlohmann::json testJson = data["tests"];
|
||||||
|
|
||||||
fs::path workingDir = path;
|
|
||||||
workingDir.remove_filename();
|
|
||||||
|
|
||||||
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
|
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
|
||||||
configurations.emplace_back(configs, (*it), workingDir);
|
configurations.emplace_back(configs, (*it), workingDir);
|
||||||
|
|
@ -297,6 +307,12 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
}
|
}
|
||||||
|
|
||||||
Project project(std::move(name), std::move(workingDir), std::move(configurations));
|
Project project(std::move(name), std::move(workingDir), std::move(configurations));
|
||||||
|
if(data.contains("build_dir")) {
|
||||||
|
project.buildDir = workingDir / data["build_dir"].get<std::string>();
|
||||||
|
}
|
||||||
|
if(data.contains("bin_dir")) {
|
||||||
|
project.binDir = workingDir / data["bin_dir"].get<std::string>();
|
||||||
|
}
|
||||||
project.tests = std::move(tests);
|
project.tests = std::move(tests);
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
@ -318,40 +334,27 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
throw std::runtime_error(std::format("Test: {} not found.", testName));
|
throw std::runtime_error(std::format("Test: {} not found.", testName));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult Project::RunTest(Test& test) {
|
TestResult Project::RunTest(Test& test) const {
|
||||||
|
fs::path binDir;
|
||||||
|
if(this->binDir.empty()) {
|
||||||
|
binDir = "bin"/fs::path(test.config.name);
|
||||||
|
} else {
|
||||||
|
binDir = this->binDir/test.config.name;
|
||||||
|
}
|
||||||
fs::path buildDir;
|
fs::path buildDir;
|
||||||
if(test.config.buildDir.empty()) {
|
if(this->buildDir.empty()) {
|
||||||
buildDir = "build"/fs::path(test.config.name);
|
buildDir = "build"/fs::path(test.config.name);
|
||||||
} else {
|
} else {
|
||||||
buildDir = test.config.buildDir/test.config.name;
|
buildDir = this->buildDir/test.config.name;
|
||||||
}
|
}
|
||||||
char path[PATH_MAX];//
|
|
||||||
ssize_t count = readlink("/proc/self/exe", path, PATH_MAX);
|
try {
|
||||||
if (count == -1) {
|
Build(test.config, binDir, buildDir, test.config.name);
|
||||||
throw std::runtime_error("Failed to get executable path");
|
} catch(std::exception& e) {
|
||||||
|
return {test.config.name, std::string(e.what())};
|
||||||
}
|
}
|
||||||
path[count] = '\0';
|
|
||||||
if (!fs::exists(buildDir)) {
|
std::string lib = std::format("{}/lib{}.so", binDir.string(), test.config.name);
|
||||||
fs::create_directories(buildDir);
|
|
||||||
}
|
|
||||||
if(!fs::exists((fs::path(buildDir).parent_path()/this->path.filename()).string()+".o")) {
|
|
||||||
std::string result = RunCommand(std::format(R"(GCC_VERSION=$(g++ -dumpversion)
|
|
||||||
STD_HEADER="/usr/include/c++/$GCC_VERSION/bits/std.cc"
|
|
||||||
if [ ! -f "$STD_HEADER" ]; then
|
|
||||||
echo "Cannot find std.cc for GCC $GCC_VERSION"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cp "$STD_HEADER" {}/std.cppm
|
|
||||||
clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/std.cppm -o {}/std.pcm )", fs::path(buildDir).parent_path().string(), fs::path(buildDir).parent_path().string(), fs::path(buildDir).parent_path().string()));
|
|
||||||
if(result != "") {
|
|
||||||
throw std::runtime_error(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if(!fs::exists(buildDir.parent_path().string()+"/Crafter.Test.pcm")) {
|
|
||||||
// RunClang(std::format("clang++ -std=c++26 --precompile -fprebuilt-module-path={} {}/interfaces/Crafter.Test.cppm -o {}/Crafter.Test.pcm", buildDir.parent_path().string(), std::filesystem::absolute(path).parent_path().parent_path().string(), buildDir.parent_path().string()));
|
|
||||||
// }
|
|
||||||
Build(test.config, buildDir, buildDir);
|
|
||||||
std::string lib = std::format("{}/{}.so", buildDir.string(), name);
|
|
||||||
void* handle = dlopen(lib.c_str(), RTLD_NOW);
|
void* handle = dlopen(lib.c_str(), RTLD_NOW);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
throw std::runtime_error(std::format("Failed to load test library, {}, {}", lib, dlerror()));
|
throw std::runtime_error(std::format("Failed to load test library, {}, {}", lib, dlerror()));
|
||||||
|
|
@ -361,8 +364,9 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
RunTestFunc loadedTest = (RunTestFunc) dlsym(handle, "RunTest");
|
RunTestFunc loadedTest = (RunTestFunc) dlsym(handle, "RunTest");
|
||||||
const char* dlsym_error = dlerror();
|
const char* dlsym_error = dlerror();
|
||||||
if (dlsym_error) {
|
if (dlsym_error) {
|
||||||
|
std::string msg = std::string(dlsym_error);
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
throw std::runtime_error(std::format("Cannot load symbol 'RunTest': {}", dlsym_error));
|
throw std::runtime_error(std::format("Cannot load symbol 'RunTest': {}", msg));
|
||||||
}
|
}
|
||||||
std::string* testResult = loadedTest();
|
std::string* testResult = loadedTest();
|
||||||
if(testResult != nullptr) {
|
if(testResult != nullptr) {
|
||||||
|
|
@ -372,6 +376,7 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
} else {
|
} else {
|
||||||
return {test.config.name, ""};
|
return {test.config.name, ""};
|
||||||
}
|
}
|
||||||
|
return {test.config.name, ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
// void AddModule(std::string_view configuration, std::string_view filename);
|
// void AddModule(std::string_view configuration, std::string_view filename);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
fs::path filepath = "project.json";
|
fs::path filepath = "project.json";
|
||||||
std::string configuration;
|
std::string configuration;
|
||||||
std::string outputDir;
|
|
||||||
std::string command = std::string(argv[1]);
|
std::string command = std::string(argv[1]);
|
||||||
std::string argument;
|
std::string argument;
|
||||||
if(argc > 2) {
|
if(argc > 2) {
|
||||||
|
|
@ -44,8 +43,6 @@ int main(int argc, char* argv[]) {
|
||||||
std::string arg = std::string(argv[i]);
|
std::string arg = std::string(argv[i]);
|
||||||
if(arg == "-r"){
|
if(arg == "-r"){
|
||||||
run = true;
|
run = true;
|
||||||
} else if(arg == "-o"){
|
|
||||||
outputDir = argv[++i];
|
|
||||||
} else if(arg == "-p"){
|
} else if(arg == "-p"){
|
||||||
filepath = fs::path(argv[++i]);
|
filepath = fs::path(argv[++i]);
|
||||||
} else{
|
} else{
|
||||||
|
|
@ -64,22 +61,20 @@ int main(int argc, char* argv[]) {
|
||||||
Project project = Project::LoadFromJSON(projectPath);
|
Project project = Project::LoadFromJSON(projectPath);
|
||||||
|
|
||||||
if(command == "build") {
|
if(command == "build") {
|
||||||
if(outputDir.empty()){
|
Configuration& config = project.Build(argument);
|
||||||
project.Build(argument);
|
|
||||||
} else{
|
|
||||||
project.Build(argument, fs::path(outputDir));
|
|
||||||
}
|
|
||||||
if(run){
|
if(run){
|
||||||
for(Configuration& config : project.configurations) {
|
std::string binDir;
|
||||||
if(config.name == configuration) {
|
if(project.binDir.empty()) {
|
||||||
if(config.debug) {
|
binDir = std::format("bin/{}", config.name);
|
||||||
system(std::format("cd {} && ./{}", (projectPath/fs::path(config.outputDir)).generic_string(), project.name).c_str());
|
} else {
|
||||||
} else {
|
binDir = std::format("{}/{}", project.binDir.string(), config.name);
|
||||||
system(std::format("cd {} && lldb -o run {}", (projectPath/fs::path(config.outputDir)).generic_string(), project.name).c_str());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(config.debug) {
|
||||||
|
system(std::format("cd {} && ./{}", (projectPath/fs::path(binDir)).string(), project.name).c_str());
|
||||||
|
} else {
|
||||||
|
system(std::format("cd {} && lldb -o run {}", (projectPath/fs::path(binDir)).string(), project.name).c_str());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} else if(command == "test") {
|
} else if(command == "test") {
|
||||||
if(argument.empty()) {
|
if(argument.empty()) {
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,6 @@ namespace Crafter {
|
||||||
std::vector<Shader> shaders;
|
std::vector<Shader> shaders;
|
||||||
std::vector<fs::path> additionalFiles;
|
std::vector<fs::path> additionalFiles;
|
||||||
std::vector<Define> defines;
|
std::vector<Define> defines;
|
||||||
fs::path buildDir;
|
|
||||||
fs::path outputDir;
|
|
||||||
ConfigurationType type;
|
ConfigurationType type;
|
||||||
std::string target;
|
std::string target;
|
||||||
std::string march;
|
std::string march;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ namespace Crafter {
|
||||||
fs::path path;
|
fs::path path;
|
||||||
Implementation(fs::path&& path);
|
Implementation(fs::path&& path);
|
||||||
bool Check(const fs::path& buildDir, const fs::path& pcmDir) const;
|
bool Check(const fs::path& buildDir, const fs::path& pcmDir) const;
|
||||||
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir) const;
|
void Compile(const std::string_view clang, const fs::path& buildDir) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ namespace Crafter {
|
||||||
public:
|
public:
|
||||||
std::string name;
|
std::string name;
|
||||||
fs::path path;
|
fs::path path;
|
||||||
|
fs::path buildDir;
|
||||||
|
fs::path binDir;
|
||||||
std::vector<Configuration> configurations;
|
std::vector<Configuration> configurations;
|
||||||
std::vector<Test> tests;
|
std::vector<Test> tests;
|
||||||
Project(std::string&& name, fs::path&& path, std::vector<Configuration>&& configurations);
|
Project(std::string&& name, fs::path&& path, std::vector<Configuration>&& configurations);
|
||||||
|
|
@ -35,13 +37,13 @@ namespace Crafter {
|
||||||
Configuration& Build(std::string_view configuration);
|
Configuration& Build(std::string_view configuration);
|
||||||
Configuration& Build(std::string_view configuration, const fs::path& outputDir);
|
Configuration& Build(std::string_view configuration, const fs::path& outputDir);
|
||||||
Configuration& Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir);
|
Configuration& Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir);
|
||||||
Configuration& Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir, const fs::path& builDir);
|
Configuration& Build(std::string_view configuration, const fs::path& outputDir, const fs::path& binDir, const std::string_view outputName);
|
||||||
void Build(Configuration& configuration) const;
|
void Build(Configuration& configuration) const;
|
||||||
void Build(Configuration& configuration, const fs::path& outputDir) const;
|
void Build(Configuration& configuration, const fs::path& binDir) const;
|
||||||
void Build(Configuration& configuration, const fs::path& outputDir, const fs::path& binDir) const;
|
void Build(Configuration& configuration, const fs::path& binDir, const fs::path& builDir) const;
|
||||||
void Build(Configuration& configuration, const fs::path& outputDir, const fs::path& binDir, const fs::path& builDir) const;
|
void Build(Configuration& configuration, const fs::path& binDir, const fs::path& builDir, const std::string_view outputName) const;
|
||||||
TestResult RunTest(const std::string_view test);
|
TestResult RunTest(const std::string_view test);
|
||||||
TestResult RunTest(Test& test);
|
TestResult RunTest(Test& test) const;
|
||||||
std::vector<TestResult> RunTests();
|
std::vector<TestResult> RunTests();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@
|
||||||
"extends": ["base"],
|
"extends": ["base"],
|
||||||
"type":"library"
|
"type":"library"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "lib-shared",
|
||||||
|
"extends": ["base"],
|
||||||
|
"type":"shared-library"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "lib-debug",
|
"name": "lib-debug",
|
||||||
"extends": ["lib"],
|
"extends": ["lib"],
|
||||||
|
|
@ -36,7 +41,7 @@
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
{
|
{
|
||||||
"path":"./project.json",
|
"path":"./project.json",
|
||||||
"configuration":"lib"
|
"configuration":"lib-shared"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
std.pcm
Normal file
BIN
std.pcm
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue