From e684882cb8483528ee832e5f40852ac9a4b24235 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Sun, 1 Mar 2026 07:42:04 +0100 Subject: [PATCH] windows build --- build.ps1 | 70 ++++++ build.sh | 54 ++-- implementations/Crafter.Build-Command.cpp | 232 ++++++++++++++++++ .../Crafter.Build-Configuration.cpp | 12 +- implementations/Crafter.Build-Project.cpp | 147 ++--------- interfaces/Crafter.Build-Command.cppm | 4 + project.json | 14 +- 7 files changed, 367 insertions(+), 166 deletions(-) create mode 100644 build.ps1 diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..63fe4cf --- /dev/null +++ b/build.ps1 @@ -0,0 +1,70 @@ +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++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile .\build\std.cppm -o .\build\std.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-CompileStatus.cppm -o .\build\Crafter.Build-CompileStatus.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Command.cppm -o .\build\Crafter.Build-Command.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Shader.cppm -o .\build\Crafter.Build-Shader.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Module.cppm -o .\build\Crafter.Build-Module.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Implementation.cppm -o .\build\Crafter.Build-Implementation.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Configuration.cppm -o .\build\Crafter.Build-Configuration.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Test.cppm -o .\build\Crafter.Build-Test.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\build" interfaces\Crafter.Build-Project.cppm -o .\build\Crafter.Build-Project.pcm +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Command.cpp -o .\build\Crafter.Build-Command_impl.o +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" -O3 -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Project.cpp -o .\build\Crafter.Build-Project_impl.o +clang++ -target x86_64-pc-windows-msvc -std=c++26 -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -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 -march=native -mtune=native -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 \ No newline at end of file diff --git a/build.sh b/build.sh index 836dd85..f8731f3 100755 --- a/build.sh +++ b/build.sh @@ -10,36 +10,36 @@ if [ ! -f "$STD_HEADER" ]; then fi cp "$STD_HEADER" ./build/std.cppm clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile ./build/std.cppm -o ./build/std.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-CompileStatus.cppm -o ./build/Crafter.Build-CompileStatus.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Command.cppm -o ./build/Crafter.Build-Command.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Shader.cppm -o ./build/Crafter.Build-Shader.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Module.cppm -o ./build/Crafter.Build-Module.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Implementation.cppm -o ./build/Crafter.Build-Implementation.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Configuration.cppm -o ./build/Crafter.Build-Configuration.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Test.cppm -o ./build/Crafter.Build-Test.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build interfaces/Crafter.Build-Project.cppm -o ./build/Crafter.Build-Project.pcm -clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build.cppm -o ./build/Crafter.Build.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-CompileStatus.cppm -o ./build/Crafter.Build-CompileStatus.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Command.cppm -o ./build/Crafter.Build-Command.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Shader.cppm -o ./build/Crafter.Build-Shader.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Module.cppm -o ./build/Crafter.Build-Module.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Implementation.cppm -o ./build/Crafter.Build-Implementation.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Configuration.cppm -o ./build/Crafter.Build-Configuration.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Test.cppm -o ./build/Crafter.Build-Test.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build-Project.cppm -o ./build/Crafter.Build-Project.pcm +clang++ -std=c++26 --precompile -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE interfaces/Crafter.Build.cppm -o ./build/Crafter.Build.pcm -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 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Command.pcm -o ./build/Crafter.Build-Command.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Shader.pcm -o ./build/Crafter.Build-Shader.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Module.pcm -o ./build/Crafter.Build-Module.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Implementation.pcm -o ./build/Crafter.Build-Implementation.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Configuration.pcm -o ./build/Crafter.Build-Configuration.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Project.pcm -o ./build/Crafter.Build-Project.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-Test.pcm -o ./build/Crafter.Build-Test.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build-CompileStatus.pcm -o ./build/Crafter.Build-CompileStatus.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./build/Crafter.Build.pcm -o ./build/Crafter.Build.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Command.cpp -o ./build/Crafter.Build-Command_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Test.cpp -o ./build/Crafter.Build-Test_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Implementation.cpp -o ./build/Crafter.Build-Implementation_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Shader.cpp -o ./build/Crafter.Build-Shader_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Module.cpp -o ./build/Crafter.Build-Module_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Configuration.cpp -o ./build/Crafter.Build-Configuration_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/Crafter.Build-Project.cpp -o ./build/Crafter.Build-Project_impl.o -clang++ -std=c++26 -O3 -fprebuilt-module-path=./build -c ./implementations/main.cpp -o ./build/main.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Command.cpp -o ./build/Crafter.Build-Command_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Test.cpp -o ./build/Crafter.Build-Test_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Implementation.cpp -o ./build/Crafter.Build-Implementation_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Shader.cpp -o ./build/Crafter.Build-Shader_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Module.cpp -o ./build/Crafter.Build-Module_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Configuration.cpp -o ./build/Crafter.Build-Configuration_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/Crafter.Build-Project.cpp -o ./build/Crafter.Build-Project_impl.o +clang++ -std=c++26 -O3 -march=native -mtune=native -fprebuilt-module-path=./build -D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -c ./implementations/main.cpp -o ./build/main.o -clang++ -std=c++26 -O3 -L/usr/local/lib -L/usr/lib/ -lvulkan -lMachineIndependent -lOSDependent -lGenericCodeGen -lglslang -lglslang-default-resource-limits -lSPIRV -ltbb -fuse-ld=lld ./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 +clang++ -std=c++26 -O3 -march=native -mtune=native -L/usr/local/lib -L/usr/lib/ -lvulkan -lMachineIndependent -lOSDependent -lGenericCodeGen -lglslang -lglslang-default-resource-limits -lSPIRV -ltbb -fuse-ld=lld ./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 cp -r binlib/* bin/ diff --git a/implementations/Crafter.Build-Command.cpp b/implementations/Crafter.Build-Command.cpp index 18744ae..0e4b62c 100644 --- a/implementations/Crafter.Build-Command.cpp +++ b/implementations/Crafter.Build-Command.cpp @@ -18,13 +18,148 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ module; +#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32) +#include +#endif #include +#include +#include +#include module Crafter.Build:Command_impl; import :Command; +import :Project; import std; +namespace fs = std::filesystem; namespace Crafter { + std::string RunCommand(const std::string_view cmd); + std::filesystem::path GetPath(); + + void BuildWasmStdPcm(const Project& project, const Configuration& config) { + fs::path exeDir = GetPath(); + fs::create_directories(exeDir/config.target); + + 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); + } + } + + const fs::path indexPath = std::format("{}/index.html", exeDir.string()); + const fs::path indexDstPath = project.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 = project.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); + } + } + + #if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32) + std::string RunCommand(const std::string_view cmd) { + std::array buffer; + std::string result; + + // Use cmd.exe to interpret redirection + std::string with = "cmd /C \"" + std::string(cmd) + " 2>&1\""; + + FILE* pipe = _popen(with.c_str(), "r"); + if (!pipe) { + throw std::runtime_error("_popen() failed!"); + } + + while (fgets(buffer.data(), static_cast(buffer.size()), pipe) != nullptr) { + result += buffer.data(); + } + + _pclose(pipe); + return result; + } + + void RunCommandIgnore(const std::string_view cmd) { + std::string with = "cmd /C \"" + std::string(cmd) + " > NUL 2>&1\""; + + FILE* pipe = _popen(with.c_str(), "r"); + if (!pipe) { + throw std::runtime_error("_popen() failed!"); + } + + _pclose(pipe); + } + + std::filesystem::path GetPath() { + char path[MAX_PATH]; + DWORD length = GetModuleFileNameA(NULL, path, MAX_PATH); + if (length == 0) { + throw std::runtime_error("Failed to get executable path"); + } + path[length] = '\0'; + return fs::path(path).parent_path().parent_path(); + } + + void BuildGnuStdPcm(const Project& project, const Configuration& config) { + throw std::runtime_error("target x86_64-pc-linux-gnu is not supported"); + } + + void BuildMingwStdPcm(const Project& project, const Configuration& config) { + throw std::runtime_error("target x86_64-w64-mingw32 is not supported"); + } + + void BuildMsvcStdPcm(const Project& project, const Configuration& config) { + fs::path exeDir = GetPath(); + fs::create_directories(exeDir/config.target); + std::string stdPcm = std::format("{}\\{}\\std.pcm", exeDir.string(), config.target); + + + std::string vsPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"; + + 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(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"; + + fs::copy(sourceFilePath, stdPcm, fs::copy_options::overwrite_existing); + + if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(sourceFilePath)) { + std::string result = RunCommand(std::format("clang++ -std=c++26 -target x86_64-pc-windows-msvc -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}\\{}\\std.cppm -o {}", exeDir.string(), config.target, stdPcm)); + if(result != "") { + throw std::runtime_error(result); + } + } + } + + #else + std::string RunCommand(const std::string_view cmd) { std::array buffer; std::string result; @@ -51,6 +186,89 @@ namespace Crafter { pclose(pipe); } + std::filesystem::path GetPath() { + 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'; + return fs::path(path).parent_path().parent_path(); + } + + void BuildGnuStdPcm(const Project& project, const Configuration& config) { + fs::path exeDir = GetPath(); + 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); + } + } + } + + void BuildMingwStdPcm(const Project& project, const Configuration& config) { + fs::path exeDir = GetPath(); + fs::create_directories(exeDir/config.target); + + const std::string stdPcm = std::format("{}/{}/std.pcm", exeDir.string(), config.target); + std::vector 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); + } + } + + 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 = project.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; + } + } + + void BuildMsvcStdPcm(const Project& project, const Configuration& config) { + throw std::runtime_error("target x86_64-pc-windows-msvc is not supported"); + } + + #endif + // CompileException::CompileException(std::vector&& errors) : errors(std::move(errors)) { // for(CompileError error : errors) { // message += std::format("File: {}:{}\nMessage: {}\nCode: {}", error.filename, error.line, error.message, error.code); @@ -60,6 +278,20 @@ namespace Crafter { // return message.c_str(); // } + void BuildStdPcm(const Project& project, const Configuration& config) { + if(config.target == "x86_64-pc-linux-gnu") { + BuildGnuStdPcm(project, config); + } else if(config.target == "x86_64-w64-mingw32") { + BuildMingwStdPcm(project, config); + } else if(config.target == "x86_64-pc-windows-msvc") { + BuildMsvcStdPcm(project, config); + } else if(config.target == "wasm32-wasi") { + BuildWasmStdPcm(project, config); + } else { + throw std::runtime_error(std::format("Unkown target: {}", config.target)); + } + } + std::string RunClang(const std::string_view cmd) { // std::string result = RunCommand(cmd); // // std::vector errors; diff --git a/implementations/Crafter.Build-Configuration.cpp b/implementations/Crafter.Build-Configuration.cpp index 94fab7b..08b3dc8 100644 --- a/implementations/Crafter.Build-Configuration.cpp +++ b/implementations/Crafter.Build-Configuration.cpp @@ -57,6 +57,8 @@ namespace Crafter { } if(config.contains("standard")) { standard = config["standard"].get(); + } else { + standard = "c++26"; } if(config.contains("target")) { target = config["target"].get(); @@ -81,6 +83,8 @@ namespace Crafter { } if(config.contains("march")) { march = config["march"].get(); + } else { + march = "native"; } if(config.contains("libs")) { for (auto it : config["libs"]) { @@ -263,13 +267,7 @@ namespace Crafter { // depFolder += it["branch"].get(); // } - char self[PATH_MAX]; - ssize_t count = readlink("/proc/self/exe", self, PATH_MAX); - if (count == -1) { - throw std::runtime_error("Failed to get executable path"); - } - self[count] = '\0'; - const fs::path cacheDir = (fs::path(self).parent_path().parent_path() / "cloneCache").string(); + const fs::path cacheDir = GetPath() / "cloneCache"; if (!fs::exists(cacheDir)) { fs::create_directories(cacheDir); diff --git a/implementations/Crafter.Build-Project.cpp b/implementations/Crafter.Build-Project.cpp index 9551456..0f8dfbe 100644 --- a/implementations/Crafter.Build-Project.cpp +++ b/implementations/Crafter.Build-Project.cpp @@ -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 +#endif #include 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() == 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 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 depLibSet; std::vector depThreads = std::vector(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; } diff --git a/interfaces/Crafter.Build-Command.cppm b/interfaces/Crafter.Build-Command.cppm index 2422748..bc127d0 100644 --- a/interfaces/Crafter.Build-Command.cppm +++ b/interfaces/Crafter.Build-Command.cppm @@ -36,7 +36,11 @@ namespace Crafter { // const char* what() const noexcept override; // }; + export class Project; + export class Configuration; export std::string RunCommand(const std::string_view cmd); export void RunCommandIgnore(const std::string_view cmd); export std::string RunClang(const std::string_view cmd); + export std::filesystem::path GetPath(); + export void BuildStdPcm(const Project& project, const Configuration& configuration); } \ No newline at end of file diff --git a/project.json b/project.json index 52827c2..28985be 100644 --- a/project.json +++ b/project.json @@ -7,30 +7,34 @@ "implementations": ["implementations/Crafter.Build-Command", "implementations/Crafter.Build-Configuration", "implementations/Crafter.Build-Module", "implementations/Crafter.Build-Project", "implementations/Crafter.Build-Shader", "implementations/Crafter.Build-Implementation", "implementations/Crafter.Build-Test"], "libs": ["vulkan", "MachineIndependent", "OSDependent", "GenericCodeGen", "glslang", "glslang-default-resource-limits", "SPIRV", "tbb"] }, + { + "name": "libs-gnu", + "libs": ["vulkan", "MachineIndependent", "OSDependent", "GenericCodeGen", "glslang", "glslang-default-resource-limits", "SPIRV", "tbb"] + }, { "name": "executable", - "extends": ["base"], + "extends": ["base", "libs-gnu"], "type":"executable", "implementations": ["implementations/main"] }, { "name": "executable-debug", - "extends": ["executable"], + "extends": ["executable", "libs-gnu"], "debug": true }, { "name": "lib", - "extends": ["base"], + "extends": ["base", "libs-gnu"], "type":"library" }, { "name": "lib-shared", - "extends": ["base"], + "extends": ["base", "libs-gnu"], "type":"shared-library" }, { "name": "lib-debug", - "extends": ["lib"], + "extends": ["lib", "libs-gnu"], "debug": true } ],