diff --git a/build.ps1 b/build.ps1 index 552c808..a69b823 100644 --- a/build.ps1 +++ b/build.ps1 @@ -35,24 +35,24 @@ $vulkanSDKPath = Join-Path -Path $vulkanBasePath -ChildPath (Join-Path -Path $la clang++ -std=c++26 -I"$vulkanSDKPath" -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile .\build/std.cppm -o .\build/std.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-CompileStatus.cppm -o .\build\Crafter.Build-CompileStatus.pcm -clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Command.cppm -o .\build\Crafter.Build-Command.pcm +clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" -D PLATFORM_WINDOWS interfaces\Crafter.Build-Command.cppm -o .\build\Crafter.Build-Command.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Shader.cppm -o .\build\Crafter.Build-Shader.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Module.cppm -o .\build\Crafter.Build-Module.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Implementation.cppm -o .\build\Crafter.Build-Implementation.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Configuration.cppm -o .\build\Crafter.Build-Configuration.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Test.cppm -o .\build\Crafter.Build-Test.pcm clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Project.cppm -o .\build\Crafter.Build-Project.pcm -clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.pcm +clang++ -std=c++26 -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.pcm -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Command.pcm -o .\build\Crafter.Build-Command.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Shader.pcm -o .\build\Crafter.Build-Shader.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Module.pcm -o .\build\Crafter.Build-Module.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Implementation.pcm -o .\build\Crafter.Build-Implementation.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Configuration.pcm -o .\build\Crafter.Build-Configuration.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Project.pcm -o .\build\Crafter.Build-Project.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Test.pcm -o .\build\Crafter.Build-Test.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-CompileStatus.pcm -o .\build\Crafter.Build-CompileStatus.o -clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build.pcm -o .\build\Crafter.Build.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Command.pcm -o .\build\Crafter.Build-Command.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Shader.pcm -o .\build\Crafter.Build-Shader.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Module.pcm -o .\build\Crafter.Build-Module.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Implementation.pcm -o .\build\Crafter.Build-Implementation.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Configuration.pcm -o .\build\Crafter.Build-Configuration.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Project.pcm -o .\build\Crafter.Build-Project.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Test.pcm -o .\build\Crafter.Build-Test.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-CompileStatus.pcm -o .\build\Crafter.Build-CompileStatus.o +clang++ -std=c++26 -O3 -fprebuilt-module-path=".\build" -c .\build\Crafter.Build.pcm -o .\build\Crafter.Build.o clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Command.cpp -o .\build\Crafter.Build-Command_impl.o clang++ -std=c++26 -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.o diff --git a/implementations/Crafter.Build-Command.cpp b/implementations/Crafter.Build-Command.cpp index 18744ae..b890e6d 100644 --- a/implementations/Crafter.Build-Command.cpp +++ b/implementations/Crafter.Build-Command.cpp @@ -19,12 +19,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA module; #include +#ifdef PLATFORM_WINDOWS +#include +#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 buffer; std::string result; @@ -50,6 +54,36 @@ namespace Crafter { if (!pipe) throw std::runtime_error("popen() failed!"); pclose(pipe); } + #else + std::string RunCommand(const std::string_view cmd) { + std::array 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&& errors) : errors(std::move(errors)) { // for(CompileError error : errors) {