This commit is contained in:
parent
9bd12660eb
commit
d98738fe68
4 changed files with 88 additions and 146 deletions
110
build.ps1
110
build.ps1
|
|
@ -1,77 +1,59 @@
|
||||||
mkdir build
|
mkdir build
|
||||||
mkdir bin
|
mkdir bin
|
||||||
mkdir bin/executable
|
mkdir bin\executable-windows-msvc
|
||||||
|
|
||||||
# Get the path of Visual Studio Installer
|
git clone https:\\github.com\KhronosGroup\glslang.git .\build\glslang
|
||||||
$vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
|
|
||||||
|
|
||||||
# Set the directory path for MSVC tools
|
cd .\build\glslang
|
||||||
$directoryPath = Join-Path -Path $vsPath -ChildPath "VC\Tools\MSVC"
|
|
||||||
|
|
||||||
$directoryPath2 = Join-Path -Path $vsPath -ChildPath "VC\Redist\MSVC"
|
$buildDir = "$($PWD.Path)\build"
|
||||||
|
cmake -B build `
|
||||||
|
-DCMAKE_C_COMPILER=clang `
|
||||||
|
-DCMAKE_CXX_COMPILER=clang++ `
|
||||||
|
-DCMAKE_CXX_FLAGS="-stdlib=libc++" `
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++" `
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS="-stdlib=libc++" `
|
||||||
|
-DCMAKE_BUILD_TYPE=Release `
|
||||||
|
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$buildDir" `
|
||||||
|
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$buildDir" `
|
||||||
|
-DENABLE_OPT=OFF
|
||||||
|
|
||||||
# Get all folders (assumes version format like 14.50.35717)
|
cmake --build build --config Release
|
||||||
$folders = Get-ChildItem -Path $directoryPath -Directory
|
cd ..\..\
|
||||||
|
|
||||||
# Sort the folders by version and select the latest one
|
$common_options = @(
|
||||||
$latestVersionFolder = $folders | Sort-Object { [Version]$_.Name } -Descending | Select-Object -First 1
|
"-stdlib=libc++"
|
||||||
|
"-I.\build"
|
||||||
|
"-std=c++26"
|
||||||
|
"-O3"
|
||||||
|
"-march=native"
|
||||||
|
"-mtune=native"
|
||||||
|
"-fprebuilt-module-path=.\build"
|
||||||
|
"-DCRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu"
|
||||||
|
"-DCRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE"
|
||||||
|
"-c"
|
||||||
|
)
|
||||||
|
clang++ -std=c++26 -stdlib=libc++ -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile \usr\share\libc++\v1\std.cppm -o .\build\std.pcm
|
||||||
|
|
||||||
# Store the latest version folder name
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-CompileStatus.cppm -o .\build\Crafter.Build-CompileStatus.o
|
||||||
$msvcVersion = $latestVersionFolder.Name
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Command.cppm -o .\build\Crafter.Build-Command.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Shader.cppm -o .\build\Crafter.Build-Shader.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Module.cppm -o .\build\Crafter.Build-Module.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Implementation.cppm -o .\build\Crafter.Build-Implementation.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Configuration.cppm -o .\build\Crafter.Build-Configuration.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Test.cppm -o .\build\Crafter.Build-Test.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build-Project.cppm -o .\build\Crafter.Build-Project.o
|
||||||
|
clang++ @common_options -fmodule-output interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.o
|
||||||
|
|
||||||
# Copy std.ixx to the build directory
|
clang++ @common_options .\implementations\Crafter.Build-Command.cpp -o .\build\Crafter.Build-Command_impl.o
|
||||||
$sourceFilePath = Join-Path -Path $directoryPath -ChildPath "$msvcVersion\modules\std.ixx"
|
clang++ @common_options .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.o
|
||||||
$destinationFilePath = ".\build\std.cppm"
|
clang++ @common_options .\implementations\Crafter.Build-Implementation.cpp -o .\build\Crafter.Build-Implementation_impl.o
|
||||||
Copy-Item -Path $sourceFilePath -Destination $destinationFilePath
|
clang++ @common_options .\implementations\Crafter.Build-Shader.cpp -o .\build\Crafter.Build-Shader_impl.o
|
||||||
|
clang++ @common_options .\implementations\Crafter.Build-Module.cpp -o .\build\Crafter.Build-Module_impl.o
|
||||||
|
clang++ @common_options .\implementations\Crafter.Build-Configuration.cpp -o .\build\Crafter.Build-Configuration_impl.o
|
||||||
|
clang++ @common_options .\implementations\Crafter.Build-Project.cpp -o .\build\Crafter.Build
|
||||||
|
|
||||||
$msvcRtPath = Join-Path -Path $directoryPath2 -ChildPath "$msvcVersion\x64\Microsoft.VC145.CRT"
|
clang++ -std=c++26 -stdlib=libc++ -O3 -march=native -mtune=native -L.\build -fuse-ld=lld -lSPIRV -GenericCodeGen -lglslang -lOSDependent -lMachineIndependent -lglslang-default-resource-limits .\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-linux-gnu\crafter-build
|
||||||
|
|
||||||
$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")
|
|
||||||
|
|
||||||
cd build
|
|
||||||
cl /std:c++latest /EHsc /nologo /W4 /MD /c "$sourceFilePath"
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -Wno-include-angled-in-module-purview -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile .\std.cppm -o .\std.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-CompileStatus.cppm -o Crafter.Build-CompileStatus.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Command.cppm -o Crafter.Build-Command.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Shader.cppm -o Crafter.Build-Shader.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Module.cppm -o Crafter.Build-Module.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Implementation.cppm -o Crafter.Build-Implementation.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Configuration.cppm -o Crafter.Build-Configuration.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Test.cppm -o Crafter.Build-Test.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build-Project.cppm -o Crafter.Build-Project.pcm
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -I"$vulkanSDKPath" --precompile -fprebuilt-module-path=".\" ..\interfaces\Crafter.Build.cppm -o Crafter.Build.pcm
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Command.pcm -o .\build\Crafter.Build-Command.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Shader.pcm -o .\build\Crafter.Build-Shader.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Module.pcm -o .\build\Crafter.Build-Module.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Implementation.pcm -o .\build\Crafter.Build-Implementation.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Configuration.pcm -o .\build\Crafter.Build-Configuration.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Project.pcm -o .\build\Crafter.Build-Project.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-Test.pcm -o .\build\Crafter.Build-Test.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build-CompileStatus.pcm -o .\build\Crafter.Build-CompileStatus.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD -march=native -mtune=native /Ot -fprebuilt-module-path=".\build" -c .\build\Crafter.Build.pcm -o .\build\Crafter.Build.obj
|
|
||||||
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Command.cpp -o .\build\Crafter.Build-Command_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Implementation.cpp -o .\build\Crafter.Build-Implementation_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Shader.cpp -o .\build\Crafter.Build-Shader_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Module.cpp -o .\build\Crafter.Build-Module_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Configuration.cpp -o .\build\Crafter.Build-Configuration_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\Crafter.Build-Project.cpp -o .\build\Crafter.Build-Project_impl.obj
|
|
||||||
clang-cl --target=x86_64-pc-windows-msvc /std:c++latest /EHsc /MD /D CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE -march=native -mtune=native -I"$vulkanSDKPath" /Ot -fprebuilt-module-path=".\build" -c .\implementations\main.cpp -o .\build\main.obj
|
|
||||||
|
|
||||||
link /LIBPATH:"$vulkanSDKPathLib" msvcrt.lib kernel32.lib user32.lib SPIRV-Tools.lib SPIRV-Tools-opt.lib vulkan-1.lib MachineIndependent.lib OSDependent.lib GenericCodeGen.lib glslang.lib glslang-default-resource-limits.lib SPIRV.lib .\build\Crafter.Build-Command.obj .\build\Crafter.Build-CompileStatus.obj .\build\Crafter.Build-Shader.obj .\build\Crafter.Build-Module.obj .\build\Crafter.Build-Configuration.obj .\build\Crafter.Build-Project.obj .\build\Crafter.Build.obj .\build\Crafter.Build-Command_impl.obj .\build\Crafter.Build-Shader_impl.obj .\build\Crafter.Build-Module_impl.obj .\build\Crafter.Build-Configuration_impl.obj .\build\Crafter.Build-Project_impl.obj .\build\Crafter.Build-Implementation.obj .\build\Crafter.Build-Implementation_impl.obj .\build\Crafter.Build-Test_impl.obj .\build\Crafter.Build-Test.obj .\build\main.obj .\build\std.obj /OUT:.\bin\executable\Crafter-build.exe
|
|
||||||
|
|
||||||
Copy-Item -Path "binlib\*" -Destination "bin\" -Recurse
|
Copy-Item -Path "binlib\*" -Destination "bin\" -Recurse
|
||||||
Remove-Item -Path "build" -Recurse -Force
|
Remove-Item -Path "build" -Recurse -Force
|
||||||
|
|
@ -67,14 +67,7 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
result += RunClang(std::format("cd {} && {} {}.cppm --precompile -o {}.pcm", pcmDir.string(), clang, path.string(), path.filename().string()));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
result += RunClang(std::format("{} -Wno-unused-command-line-argument {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
|
||||||
if(result.empty()) {
|
if(result.empty()) {
|
||||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||||
compiled.notify_all();
|
compiled.notify_all();
|
||||||
|
|
@ -84,6 +77,13 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModulePartition::CompileSource(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result) {
|
||||||
|
this->compiled.wait(CRAFTER_COMPILE_STATUS_WAITING);
|
||||||
|
if(this->compiled.load() != CRAFTER_COMPILE_STATUS_ERROR) {
|
||||||
|
result += RunClang(std::format("{} -Wno-unused-command-line-argument {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Module::Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions) : name(std::move(name)), path(std::move(path)), partitions(std::move(partitions)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
Module::Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions) : name(std::move(name)), path(std::move(path)), partitions(std::move(partitions)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
||||||
|
|
||||||
Module::Module(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
Module::Module(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
||||||
|
|
@ -151,13 +151,7 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result.empty()) {
|
if(result.empty()) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
result += RunClang(std::format("cd {} && {} {}.cppm --precompile -o {}.pcm", pcmDir.string(), clang, path.string(), path.filename().string()));
|
|
||||||
#endif
|
|
||||||
result += RunClang(std::format("{} -Wno-unused-command-line-argument {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
|
||||||
if(result.empty()) {
|
if(result.empty()) {
|
||||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||||
compiled.notify_all();
|
compiled.notify_all();
|
||||||
|
|
@ -170,4 +164,26 @@ namespace Crafter {
|
||||||
compiled.notify_all();
|
compiled.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Module::CompileSource(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result) {
|
||||||
|
this->compiled.wait(CRAFTER_COMPILE_STATUS_WAITING);
|
||||||
|
if(this->compiled.load() != CRAFTER_COMPILE_STATUS_ERROR) {
|
||||||
|
result += RunClang(std::format("{} -Wno-unused-command-line-argument {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||||
|
std::vector<std::thread> threads;
|
||||||
|
std::vector<std::string> results(partitions.size());
|
||||||
|
for(std::uint_fast32_t i = 0; i < partitions.size(); i++) {
|
||||||
|
if( partitions[i]->needsRecompiling) {
|
||||||
|
threads.emplace_back(&ModulePartition::CompileSource, partitions[i].get(), clang, pcmDir, buildDir, std::ref(results[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::thread& thread : threads){
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const std::string& result2 : results) {
|
||||||
|
result += result2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,32 +245,18 @@ namespace Crafter {
|
||||||
std::string editedTarget = config.target;
|
std::string editedTarget = config.target;
|
||||||
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
|
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
|
||||||
|
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
std::string command = std::format("clang++ -stdlib=libc++ --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={} -I{} -I{}", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string(), buildDir.string(), (exeDir/"cloneCache").string());
|
std::string command = std::format("clang++ -stdlib=libc++ --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={} -I{} -I{}", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string(), buildDir.string(), (exeDir/"cloneCache").string());
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
std::string command = std::format("clang-cl.exe /EHsc --target={} -march={} -mtune={} /std:{} /D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={} -Wno-unused-command-line-argument", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(config.target == "wasm32-wasi") {
|
if(config.target == "wasm32-wasi") {
|
||||||
command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", (exeDir/"wasi-sysroot-28.0").string());
|
command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", (exeDir/"wasi-sysroot-28.0").string());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const Define& define : config.defines) {
|
for(const Define& define : config.defines) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
if(define.value.empty()) {
|
if(define.value.empty()) {
|
||||||
command += std::format(" -D {}", define.name);
|
command += std::format(" -D {}", define.name);
|
||||||
} else {
|
} else {
|
||||||
command += std::format(" -D {}={}", define.name, define.value);
|
command += std::format(" -D {}={}", define.name, define.value);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
if(define.value.empty()) {
|
|
||||||
command += std::format(" /D {}", define.name);
|
|
||||||
} else {
|
|
||||||
command += std::format(" /D {}={}", define.name, define.value);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path pcmDir;
|
fs::path pcmDir;
|
||||||
|
|
@ -280,24 +266,14 @@ namespace Crafter {
|
||||||
command += " -fPIC -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
command += " -fPIC -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||||
#endif
|
#endif
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||||
#endif
|
#endif
|
||||||
pcmDir = binDir;
|
pcmDir = binDir;
|
||||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
|
||||||
#endif
|
|
||||||
pcmDir = binDir;
|
pcmDir = binDir;
|
||||||
} else {
|
} else {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
|
||||||
#endif
|
|
||||||
pcmDir = buildDir;
|
pcmDir = buildDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,20 +283,10 @@ namespace Crafter {
|
||||||
|
|
||||||
if(config.debug) {
|
if(config.debug) {
|
||||||
cmakeBuildType = "Debug";
|
cmakeBuildType = "Debug";
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
command += " -g -D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
command += " -g -D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
command += " -g /MDd /D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
cmakeBuildType = "Release";
|
cmakeBuildType = "Release";
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
command += " -O3";
|
command += " -O3";
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
command += " /Ot";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const std::string& dir : config.includeDirs) {
|
for(const std::string& dir : config.includeDirs) {
|
||||||
|
|
@ -380,12 +346,7 @@ namespace Crafter {
|
||||||
for(const fs::path& cFile: config.c_files) {
|
for(const fs::path& cFile: config.c_files) {
|
||||||
files+=std::format(" {}_source.o ",(buildDir/cFile.filename()).string());
|
files+=std::format(" {}_source.o ",(buildDir/cFile.filename()).string());
|
||||||
if(!fs::exists((buildDir/cFile.filename()).string()+"_source.o") || fs::last_write_time(cFile.string()+".c") > fs::last_write_time((buildDir/cFile.filename()).string()+"_source.o")) {
|
if(!fs::exists((buildDir/cFile.filename()).string()+"_source.o") || fs::last_write_time(cFile.string()+".c") > fs::last_write_time((buildDir/cFile.filename()).string()+"_source.o")) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
threads.emplace_back(&RunClang, std::format("clang {}.c -c -o {}_source.o", cFile.string(), (buildDir/cFile.filename()).string()));
|
threads.emplace_back(&RunClang, std::format("clang {}.c -c -o {}_source.o", cFile.string(), (buildDir/cFile.filename()).string()));
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
threads.emplace_back(&RunClang, std::format("{} {}.c -c -o {}_source.o", command, cFile.string(), (buildDir/cFile.filename()).string()));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -396,11 +357,12 @@ namespace Crafter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> resultInterfaces(config.interfaces.size());
|
std::vector<std::string> resultInterfaces(config.interfaces.size()*2);
|
||||||
|
|
||||||
for(uint_fast32_t i = 0; i < config.interfaces.size(); i++) {
|
for(uint_fast32_t i = 0; i < config.interfaces.size(); i++) {
|
||||||
if(config.interfaces[i]->Check(pcmDir)) {
|
if(config.interfaces[i]->Check(pcmDir)) {
|
||||||
threads.emplace_back(&Module::Compile, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[i]));
|
threads.emplace_back(&Module::Compile, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[i]));
|
||||||
|
threads.emplace_back(&Module::CompileSource, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[config.interfaces.size()+i]));
|
||||||
buildResult.repack = true;
|
buildResult.repack = true;
|
||||||
}
|
}
|
||||||
files += std::format(" {}/{}.o", buildDir.string(), config.interfaces[i]->path.filename().string());
|
files += std::format(" {}/{}.o", buildDir.string(), config.interfaces[i]->path.filename().string());
|
||||||
|
|
@ -441,15 +403,9 @@ namespace Crafter {
|
||||||
command += std::format(" -L{}", buildDir.string());
|
command += std::format(" -L{}", buildDir.string());
|
||||||
|
|
||||||
if(config.type != CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
if(config.type != CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
command += libsString;
|
command += libsString;
|
||||||
#endif
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
files += libsString;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
for(const std::string& lib : config.libs) {
|
for(const std::string& lib : config.libs) {
|
||||||
depLibSet.insert(lib);
|
depLibSet.insert(lib);
|
||||||
command += std::format(" -l{}", lib);
|
command += std::format(" -l{}", lib);
|
||||||
|
|
@ -458,7 +414,6 @@ namespace Crafter {
|
||||||
for(const std::string& dir : config.libDirs) {
|
for(const std::string& dir : config.libDirs) {
|
||||||
command += std::format(" -L{}", dir);
|
command += std::format(" -L{}", dir);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
fileThread.join();
|
fileThread.join();
|
||||||
|
|
||||||
|
|
@ -468,21 +423,10 @@ namespace Crafter {
|
||||||
|
|
||||||
if(buildResult.repack) {
|
if(buildResult.repack) {
|
||||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE) {
|
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
if(config.target == "wasm32-wasi") {
|
if(config.target == "wasm32-wasi") {
|
||||||
outputName += ".wasm";
|
outputName += ".wasm";
|
||||||
}
|
}
|
||||||
buildResult.errors = RunClang(std::format("{}{} -o {} -fuse-ld=lld ", command, files, (binDir/outputName).string()));
|
buildResult.errors = RunClang(std::format("{}{} -o {} -fuse-ld=lld ", command, files, (binDir/outputName).string()));
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
|
||||||
std::string libPath = "";
|
|
||||||
for(const std::string_view lib : config.libDirs) {
|
|
||||||
libPath += std::format(" /LIBPATH:{}", lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
buildResult.errors = RunClang(std::format("{} && link.exe /NODEFAULTLIB:libcmt.lib {} {} {}\\{}\\std.obj msvcrt.lib kernel32.lib user32.lib /OUT:{}.exe", vsVars, libPath, files, exeDir.string(), config.target, (binDir/outputName).string()));
|
|
||||||
#endif
|
|
||||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||||
RunClang(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
RunClang(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
||||||
|
|
@ -492,9 +436,7 @@ namespace Crafter {
|
||||||
RunClang(std::format("{} && lib.exe {} /OUT:{}.lib", vsVars, files, (binDir/fs::path(outputName)).string()));
|
RunClang(std::format("{} && lib.exe {} /OUT:{}.lib", vsVars, files, (binDir/fs::path(outputName)).string()));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
|
||||||
buildResult.errors = RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
buildResult.errors = RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ namespace Crafter {
|
||||||
ModulePartition(std::string&& name, fs::path&& path);
|
ModulePartition(std::string&& name, fs::path&& path);
|
||||||
bool Check(const fs::path& pcmDir);
|
bool Check(const fs::path& pcmDir);
|
||||||
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
||||||
|
void CompileSource(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Module {
|
export class Module {
|
||||||
|
|
@ -51,5 +52,6 @@ namespace Crafter {
|
||||||
Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions);
|
Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions);
|
||||||
bool Check(const fs::path& pcmDir);
|
bool Check(const fs::path& pcmDir);
|
||||||
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
||||||
|
void CompileSource(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue