From d3c91fc1fdb504b4a1ae2310f75fbf0716a934d0 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Mon, 23 Feb 2026 03:10:00 +0100 Subject: [PATCH] windows build 9 --- .../Crafter.Build-Configuration.cpp | 10 ++-- implementations/Crafter.Build-Project.cpp | 60 ++++++++++++++++++- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/implementations/Crafter.Build-Configuration.cpp b/implementations/Crafter.Build-Configuration.cpp index cc748b7..d309472 100644 --- a/implementations/Crafter.Build-Configuration.cpp +++ b/implementations/Crafter.Build-Configuration.cpp @@ -252,11 +252,11 @@ namespace Crafter { name.replace_extension(); std::string depFolder = name.string() + "-" + configName; - if (it.contains("commit")) { - depFolder + it["commit"].get(); - } else if (it.contains("branch")) { - depFolder + it["branch"].get(); - } + // if (it.contains("commit")) { + // depFolder += it["commit"].get(); + // } else if (it.contains("branch")) { + // depFolder += it["branch"].get(); + // } if (!fs::exists(project.buildDir/depFolder)) { fs::create_directories(project.buildDir/depFolder); diff --git a/implementations/Crafter.Build-Project.cpp b/implementations/Crafter.Build-Project.cpp index e3591df..0c88b64 100644 --- a/implementations/Crafter.Build-Project.cpp +++ b/implementations/Crafter.Build-Project.cpp @@ -18,7 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ module; #include "../lib/json.hpp" +#ifndef PLATFORM_WINDOWS #include +#else +#include +#endif #include module Crafter.Build:Project_impl; import :Project; @@ -221,19 +225,27 @@ namespace Crafter { } } }); - + #ifndef PLATFORM_WINDOWS 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(); + #else + char path[MAX_PATH]; + DWORD count = GetModuleFileNameA(NULL, path, MAX_PATH); + if (count == 0) { + throw std::runtime_error("Failed to get executable path"); + } + path[count] = '\0'; // Null-terminate the string + #endif + 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={}/wasi-sysroot-28.0 -fno-exceptions -fno-c++-static-destructors", exeDir); + command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", exeDir/"wasi-sysroot-28.0"); } } if(!config.march.empty()) { @@ -276,6 +288,7 @@ namespace Crafter { } if(config.target != "wasm32-wasi") { + #ifndef PLATFORM_WINDOWS const std::string stdPcm = std::format("{}/std.pcm", exeDir); std::string gccVersion = RunCommand("g++ -dumpversion"); gccVersion.pop_back(); @@ -287,6 +300,43 @@ namespace Crafter { throw std::runtime_error(result); } } + #else + // Get the path of the Visual Studio Installer (vswhere.exe) + std::string vsPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"; + + // Set the command to get the installation path of Visual Studio + std::string command = vsPath + " -latest -property installationPath"; + + std::string directoryPath = RunCommand("C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe -latest -property installationPath") + "\\VC\\Tools\\MSVC"; + + std::vector folders; + + // Iterate through the directory and collect all subdirectories + for (const auto& entry : fs::directory_iterator(basePath)) { + 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 msvcVersion = folders.front(); + + std::string sourceFilePath = directoryPath + "\\" + latestVersionFolder + "\\modules\\std.ixx"; + std::string destinationFilePath = ".\\build\\std.cppm"; + + // Copy the file + try { + fs::copy(sourceFilePath, destinationFilePath, fs::copy_options::overwrite_existing); + std::cout << "File copied successfully!" << std::endl; + } catch (const std::exception& e) { + std::cerr << "Error copying file: " << e.what() << std::endl; + return 1; + } + #endif command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), exeDir); } else { const std::string stdPcm = std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.pcm", exeDir); @@ -471,6 +521,7 @@ namespace Crafter { } TestResult Project::RunTest(Test& test) const { + #ifndef PLATFORM_WINDOWS fs::path binDir = path/this->binDir/test.config.name; fs::path buildDir = path/this->buildDir/test.config.name; @@ -509,6 +560,9 @@ namespace Crafter { return {test.config.name, ""}; } return {test.config.name, ""}; + #else + return {test.config.name, "Tests are not supported on windows"}; + #endif } // void AddModule(std::string_view configuration, std::string_view filename);