This commit is contained in:
parent
7d877beb52
commit
a6354db5fc
3 changed files with 13 additions and 161 deletions
|
|
@ -18,11 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
module;
|
||||
#include "../lib/json.hpp"
|
||||
#ifndef PLATFORM_WINDOWS
|
||||
#include <dlfcn.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
module Crafter.Build:Project_impl;
|
||||
import :Project;
|
||||
|
|
@ -225,21 +221,12 @@ 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';
|
||||
#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()) {
|
||||
|
|
@ -277,6 +264,10 @@ namespace Crafter {
|
|||
pcmDir = buildDir;
|
||||
}
|
||||
|
||||
std::string editedTarget = config.target;
|
||||
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
|
||||
command += std::format(" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{}", editedTarget);
|
||||
|
||||
if(config.debug) {
|
||||
command += " -g -D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
||||
} else {
|
||||
|
|
@ -349,20 +340,22 @@ namespace Crafter {
|
|||
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"
|
||||
// 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();
|
||||
|
||||
// Copy the file
|
||||
fs::copy(entry.path(), dest_file, fs::copy_options::overwrite_existing);
|
||||
// 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 {
|
||||
#ifndef PLATFORM_WINDOWS
|
||||
fs::create_directories(exeDir/config.target);
|
||||
const std::string stdPcm = std::format("{}/{}/std.pcm", exeDir.string(), config.target);
|
||||
std::string gccVersion = RunCommand("g++ -dumpversion");
|
||||
|
|
@ -375,42 +368,6 @@ 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<std::string> folders;
|
||||
|
||||
// Iterate through the directory and collect all subdirectories
|
||||
for (const auto& entry : fs::directory_iterator(directoryPath)) {
|
||||
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 + "\\" + msvcVersion + "\\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;
|
||||
}
|
||||
#endif
|
||||
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), (exeDir/config.target).string());
|
||||
}
|
||||
|
||||
|
|
@ -423,6 +380,9 @@ namespace Crafter {
|
|||
|
||||
for(std::uint_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||
depThreads[i] = std::thread([i, &config, &libMutex, &depLibSet, &buildDir, &pcmDir, &libsString, &binDir, this, &buildResult, &resultsDep](){
|
||||
for(Configuration& config2 : std::get<0>(config.dependencies[i])->configurations) {
|
||||
config2.target = config.target;
|
||||
}
|
||||
std::string outputLib = std::get<0>(config.dependencies[i])->name+std::get<1>(config.dependencies[i]).name;
|
||||
BuildResult depResult = std::get<0>(config.dependencies[i])->Build(std::get<1>(config.dependencies[i]), pcmDir, binDir, buildDir/std::get<0>(config.dependencies[i])->name/std::get<0>(config.dependencies[i])->buildDir, outputLib);
|
||||
libMutex.lock();
|
||||
|
|
@ -566,7 +526,6 @@ 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;
|
||||
|
||||
|
|
@ -605,9 +564,6 @@ 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue