This commit is contained in:
parent
7d877beb52
commit
a6354db5fc
3 changed files with 13 additions and 161 deletions
70
build.ps1
70
build.ps1
|
|
@ -1,70 +0,0 @@
|
|||
mkdir build
|
||||
mkdir bin
|
||||
mkdir bin/executable
|
||||
|
||||
# Get the path of Visual Studio Installer
|
||||
$vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
|
||||
|
||||
# Set the directory path for MSVC tools
|
||||
$directoryPath = Join-Path -Path $vsPath -ChildPath "VC\Tools\MSVC"
|
||||
|
||||
# Get all folders (assumes version format like 14.50.35717)
|
||||
$folders = Get-ChildItem -Path $directoryPath -Directory
|
||||
|
||||
# Sort the folders by version and select the latest one
|
||||
$latestVersionFolder = $folders | Sort-Object { [Version]$_.Name } -Descending | Select-Object -First 1
|
||||
|
||||
# Store the latest version folder name
|
||||
$msvcVersion = $latestVersionFolder.Name
|
||||
|
||||
# Copy std.ixx to the build directory
|
||||
$sourceFilePath = Join-Path -Path $directoryPath -ChildPath "$msvcVersion\modules\std.ixx"
|
||||
$destinationFilePath = ".\build\std.cppm"
|
||||
Copy-Item -Path $sourceFilePath -Destination $destinationFilePath
|
||||
|
||||
$vulkanBasePath = "C:\VulkanSDK"
|
||||
|
||||
# Get all folders (assumes version format like 14.50.35717)
|
||||
$folders = Get-ChildItem -Path $vulkanBasePath -Directory
|
||||
|
||||
# Sort the folders by version and select the latest one
|
||||
$latestVulkanVersion = $folders | Sort-Object { [Version]$_.Name } -Descending | Select-Object -First 1
|
||||
|
||||
# Store the latest version folder name and combine it with the base path to get the full path to Include
|
||||
$vulkanSDKPath = Join-Path -Path $vulkanBasePath -ChildPath (Join-Path -Path $latestVulkanVersion.Name -ChildPath "Include")
|
||||
$vulkanSDKPathLib = Join-Path -Path $vulkanBasePath -ChildPath (Join-Path -Path $latestVulkanVersion.Name -ChildPath "Lib")
|
||||
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile .\build/std.cppm -o .\build/std.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-CompileStatus.cppm -o .\build\Crafter.Build-CompileStatus.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Command.cppm -o .\build\Crafter.Build-Command.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Shader.cppm -o .\build\Crafter.Build-Shader.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Module.cppm -o .\build\Crafter.Build-Module.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Implementation.cppm -o .\build\Crafter.Build-Implementation.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Configuration.cppm -o .\build\Crafter.Build-Configuration.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Test.cppm -o .\build\Crafter.Build-Test.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Project.cppm -o .\build\Crafter.Build-Project.pcm
|
||||
clang++ -std=c++26 -target x86_64-pc-windows-msvc -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.pcm
|
||||
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Command.pcm -o .\build\Crafter.Build-Command.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Shader.pcm -o .\build\Crafter.Build-Shader.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Module.pcm -o .\build\Crafter.Build-Module.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Implementation.pcm -o .\build\Crafter.Build-Implementation.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Configuration.pcm -o .\build\Crafter.Build-Configuration.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Project.pcm -o .\build\Crafter.Build-Project.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Test.pcm -o .\build\Crafter.Build-Test.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-CompileStatus.pcm -o .\build\Crafter.Build-CompileStatus.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build.pcm -o .\build\Crafter.Build.o
|
||||
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -D PLATFORM_WINDOWS -c .\implementations\Crafter.Build-Command.cpp -o .\build\Crafter.Build-Command_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Implementation.cpp -o .\build\Crafter.Build-Implementation_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Shader.cpp -o .\build\Crafter.Build-Shader_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Module.cpp -o .\build\Crafter.Build-Module_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Configuration.cpp -o .\build\Crafter.Build-Configuration_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -D PLATFORM_WINDOWS -c .\implementations\Crafter.Build-Project.cpp -o .\build\Crafter.Build-Project_impl.o
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\main.cpp -o .\build\main.o
|
||||
|
||||
clang++ -target x86_64-pc-windows-msvc -std=c++26 -O3 -L"$vulkanSDKPathLib" -lvulkan-1 -lMachineIndependent -lOSDependent -lGenericCodeGen -lglslang -lglslang-default-resource-limits -lSPIRV .\build\Crafter.Build-Command.o .\build\Crafter.Build-CompileStatus.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
|
||||
|
||||
Copy-Item -Path "binlib\*" -Destination "bin\" -Recurse
|
||||
Remove-Item -Path "build" -Recurse -Force
|
||||
|
|
@ -19,16 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
#include <stdio.h>
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
module Crafter.Build:Command_impl;
|
||||
import :Command;
|
||||
import std;
|
||||
|
||||
|
||||
namespace Crafter {
|
||||
#ifndef PLATFORM_WINDOWS
|
||||
std::string RunCommand(const std::string_view cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
|
|
@ -54,36 +50,6 @@ namespace Crafter {
|
|||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
pclose(pipe);
|
||||
}
|
||||
#else
|
||||
std::string RunCommand(const std::string_view cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::string command = "cmd.exe /C " + std::string(cmd) + " 2>&1"; // Redirect stderr to stdout
|
||||
|
||||
// Open pipe to file
|
||||
FILE* pipe = _popen(command.c_str(), "r");
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
|
||||
// Read till end of process:
|
||||
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
// Close pipe
|
||||
_pclose(pipe);
|
||||
return result;
|
||||
}
|
||||
|
||||
void RunCommandIgnore(const std::string_view cmd) {
|
||||
std::string command = "cmd.exe /C " + std::string(cmd) + " > NUL 2>&1"; // Redirect stdout and stderr to NUL
|
||||
|
||||
// Open pipe to file
|
||||
FILE* pipe = _popen(command.c_str(), "r");
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
_pclose(pipe);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// CompileException::CompileException(std::vector<CompileError>&& errors) : errors(std::move(errors)) {
|
||||
// for(CompileError error : errors) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -354,15 +345,17 @@ namespace Crafter {
|
|||
// Construct the destination file path
|
||||
fs::path dest_file = binDir / entry.path().filename();
|
||||
|
||||
// Copy the file
|
||||
// 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