windows build
Some checks failed
demo.yaml / windows build (push) Failing after 0s

This commit is contained in:
Jorijn van der Graaf 2026-03-01 07:42:04 +01:00
commit e684882cb8
7 changed files with 367 additions and 166 deletions

View file

@ -18,7 +18,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
module;
#include "../lib/json.hpp"
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
#include <dlfcn.h>
#endif
#include <stdlib.h>
module Crafter.Build:Project_impl;
import :Project;
@ -102,7 +104,6 @@ namespace Crafter {
fs::create_directories(buildDir);
}
for (nlohmann::json::iterator it = configs.begin(); it != configs.end(); ++it) {
if(it->contains("name")) {
if((*it)["name"].get<std::string>() == config) {
@ -221,28 +222,20 @@ namespace Crafter {
}
}
});
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 fs::path exeDir = fs::path(path).parent_path().parent_path().string();
std::string command = "clang++ -Wno-unused-command-line-argument";
if(!config.target.empty()) {
command += std::format(" --target={}", config.target);
if(config.target == "wasm32-wasi") {
command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", (exeDir/"wasi-sysroot-28.0").string());
}
}
if(!config.march.empty()) {
command += std::format(" -march={}", config.march);
}
if(!config.standard.empty()) {
command += std::format(" -std={}", config.standard);
} else {
command += std::format(" -std=c++26");
fs::path exeDir = GetPath();
BuildStdPcm(*this, config);
std::string editedTarget = config.target;
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
std::string command = std::format("clang++ --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string());
if(config.target == "wasm32-wasi") {
command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", (exeDir/"wasi-sysroot-28.0").string());
}
for(const Define& define : config.defines) {
if(define.value.empty()) {
command += std::format(" -D {}", define.name);
@ -264,9 +257,7 @@ namespace Crafter {
pcmDir = buildDir;
}
std::string editedTarget = config.target;
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
command += std::format(" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{}", editedTarget);
command += std::format(" -fprebuilt-module-path={}", pcmDir.string());
if(config.debug) {
command += " -g -D CRAFTER_BUILD_CONFIGURATION_DEBUG";
@ -278,100 +269,6 @@ namespace Crafter {
command += std::format(" -I{}", dir);
}
if(config.target == "wasm32-wasi") {
const std::string stdPcm = std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.pcm", exeDir.string());
fs::path stdCc = fs::path(std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.cppm", exeDir.string()));
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
std::string result = RunCommand(std::format("clang++ -fno-exceptions --target=wasm32-wasi -nodefaultlibs --sysroot={}/wasi-sysroot-28.0 -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier -fno-c++-static-destructors --precompile {} -o {}", exeDir.string(), stdCc.string(), stdPcm));
if(result != "") {
throw std::runtime_error(result);
}
}
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}/wasi-sysroot-28.0/share/libc++/v1", pcmDir.string(), exeDir.string());
const fs::path indexPath = std::format("{}/index.html", exeDir.string());
const fs::path indexDstPath = binDir/"index.html";
if(!fs::exists(indexDstPath)) {
fs::copy(indexPath, indexDstPath);
} else if(fs::last_write_time(indexDstPath) < fs::last_write_time(indexPath)) {
fs::remove(indexDstPath);
fs::copy(indexPath, indexDstPath);
}
const fs::path runtimePath = std::format("{}/runtime.js", exeDir.string());
const fs::path runtimeDstPath = binDir/"runtime.js";
if(!fs::exists(runtimeDstPath)) {
fs::copy(runtimePath, runtimeDstPath);
} else if(fs::last_write_time(runtimeDstPath) < fs::last_write_time(runtimePath)) {
fs::remove(runtimeDstPath);
fs::copy(runtimePath, runtimeDstPath);
}
} else if(config.target == "x86_64-w64-mingw32") {
fs::create_directories(exeDir/config.target);
const std::string stdPcm = std::format("{}/{}/std.pcm", exeDir.string(), config.target);
std::vector<std::string> folders;
// Iterate through the directory and collect all subdirectories
for (const auto& entry : fs::directory_iterator("/usr/x86_64-w64-mingw32/include/c++")) {
if (entry.is_directory()) {
folders.push_back(entry.path().filename().string());
}
}
// Sort the folders by version in descending order
std::sort(folders.begin(), folders.end(), [](const std::string& a, const std::string& b) {
return std::lexicographical_compare(b.begin(), b.end(), a.begin(), a.end());
});
std::string mingWversion = folders.front();
fs::path stdCc = fs::path(std::format("/usr/x86_64-w64-mingw32/include/c++/{}/bits/std.cc", mingWversion));
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
std::string result = RunCommand(std::format("cp {} {}/{}/std.cppm\nclang++ --target={} -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/{}/std.cppm -o {}", stdCc.string(), exeDir.string(), config.target, config.target, exeDir.string(), config.target, stdPcm));
if(result != "") {
throw std::runtime_error(result);
}
}
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), (exeDir/config.target).string());
try {
// Iterate over the source directory
for (const auto& entry : fs::directory_iterator("/usr/x86_64-w64-mingw32/bin/")) {
// Check if the file is a regular file and ends with ".dll"
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll") {
// Construct the destination file path
fs::path dest_file = binDir / entry.path().filename();
// Check if the destination file exists and if it is older than the source file
if (!fs::exists(dest_file) || fs::last_write_time(entry.path()) > fs::last_write_time(dest_file)) {
// Copy the file if it doesn't exist or is older
fs::copy(entry.path(), dest_file, fs::copy_options::overwrite_existing);
}
}
}
} catch (const fs::filesystem_error& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
} else {
fs::create_directories(exeDir/config.target);
const std::string stdPcm = std::format("{}/{}/std.pcm", exeDir.string(), config.target);
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("cp {} {}/{}/std.cppm\nclang++ --target={} -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/{}/std.cppm -o {}", stdCc.string(), exeDir.string(), config.target, config.target, exeDir.string(), config.target, stdPcm));
if(result != "") {
throw std::runtime_error(result);
}
}
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), (exeDir/config.target).string());
}
std::unordered_set<std::string> depLibSet;
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
std::mutex libMutex;
@ -527,6 +424,7 @@ namespace Crafter {
}
TestResult Project::RunTest(Test& test) const {
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
fs::path binDir = path/this->binDir/test.config.name;
fs::path buildDir = path/this->buildDir/test.config.name;
@ -565,13 +463,8 @@ namespace Crafter {
return {test.config.name, ""};
}
return {test.config.name, ""};
#else
return {test.config.name, "Tests are not supported on this platform"};
#endif
}
// void AddModule(std::string_view configuration, std::string_view filename);
// void AddModule(Configuration& configuration, std::string_view filename);
// void AddModuleSourcePair(std::string_view configuration, std::string_view filename);
// void AddModuleSourcePair(Configuration& configuration, std::string_view filename);
// void AddTest(std::string_view configuration, std::string_view filename, std::string_view content);
// void AddTest(Configuration& configuration, std::string_view filename, std::string_view content);
// void SaveToJSON(const fs::path& path) const;
}