This commit is contained in:
parent
be1986ca08
commit
4d09eaac2a
10 changed files with 276 additions and 7 deletions
|
|
@ -34,7 +34,7 @@ jobs:
|
||||||
pacman-key --populate archlinux
|
pacman-key --populate archlinux
|
||||||
pacman -Sy --noconfirm --needed archlinux-keyring
|
pacman -Sy --noconfirm --needed archlinux-keyring
|
||||||
pacman -Syu --noconfirm --needed \
|
pacman -Syu --noconfirm --needed \
|
||||||
base-devel git zip tar \
|
base-devel git zip tar jq \
|
||||||
clang lld libc++ cmake \
|
clang lld libc++ cmake \
|
||||||
mingw-w64-gcc \
|
mingw-w64-gcc \
|
||||||
wasi-libc wasi-libc++ wasi-libc++abi wasi-compiler-rt \
|
wasi-libc wasi-libc++ wasi-libc++abi wasi-compiler-rt \
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ copy /Y interfaces\Crafter.Build-Implementation.cppm share\crafter-build\
|
||||||
copy /Y interfaces\Crafter.Build-External.cppm share\crafter-build\
|
copy /Y interfaces\Crafter.Build-External.cppm share\crafter-build\
|
||||||
copy /Y interfaces\Crafter.Build-Clang.cppm share\crafter-build\
|
copy /Y interfaces\Crafter.Build-Clang.cppm share\crafter-build\
|
||||||
copy /Y interfaces\Crafter.Build-Test.cppm share\crafter-build\
|
copy /Y interfaces\Crafter.Build-Test.cppm share\crafter-build\
|
||||||
|
copy /Y interfaces\Crafter.Build-Progress.cppm share\crafter-build\
|
||||||
copy /Y interfaces\Crafter.Build-Api.h share\crafter-build\
|
copy /Y interfaces\Crafter.Build-Api.h share\crafter-build\
|
||||||
|
|
||||||
if not exist .\build\glslang\NUL git clone https://github.com/KhronosGroup/glslang.git .\build\glslang
|
if not exist .\build\glslang\NUL git clone https://github.com/KhronosGroup/glslang.git .\build\glslang
|
||||||
|
|
@ -53,6 +54,7 @@ clang++ %common_options% -fmodule-output interfaces\Crafter.Build-Implementation
|
||||||
clang++ %common_options% -fmodule-output interfaces\Crafter.Build-External.cppm -o .\build\Crafter.Build-External.o
|
clang++ %common_options% -fmodule-output interfaces\Crafter.Build-External.cppm -o .\build\Crafter.Build-External.o
|
||||||
clang++ %common_options% -fmodule-output interfaces\Crafter.Build-Clang.cppm -o .\build\Crafter.Build-Clang.o
|
clang++ %common_options% -fmodule-output interfaces\Crafter.Build-Clang.cppm -o .\build\Crafter.Build-Clang.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-Test.cppm -o .\build\Crafter.Build-Test.o
|
||||||
|
clang++ %common_options% -fmodule-output interfaces\Crafter.Build-Progress.cppm -o .\build\Crafter.Build-Progress.o
|
||||||
clang++ %common_options% -fmodule-output interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.o
|
clang++ %common_options% -fmodule-output interfaces\Crafter.Build.cppm -o .\build\Crafter.Build.o
|
||||||
|
|
||||||
clang++ %common_options% .\implementations\Crafter.Build-Shader.cpp -o .\build\Crafter.Build-Shader_impl.o
|
clang++ %common_options% .\implementations\Crafter.Build-Shader.cpp -o .\build\Crafter.Build-Shader_impl.o
|
||||||
|
|
@ -62,6 +64,7 @@ clang++ %common_options% .\implementations\Crafter.Build-Implementation.cpp -o .
|
||||||
clang++ %common_options% .\implementations\Crafter.Build-External.cpp -o .\build\Crafter.Build-External_impl.o
|
clang++ %common_options% .\implementations\Crafter.Build-External.cpp -o .\build\Crafter.Build-External_impl.o
|
||||||
clang++ %common_options% .\implementations\Crafter.Build-Clang.cpp -o .\build\Crafter.Build-Clang_impl.o
|
clang++ %common_options% .\implementations\Crafter.Build-Clang.cpp -o .\build\Crafter.Build-Clang_impl.o
|
||||||
clang++ %common_options% .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.o
|
clang++ %common_options% .\implementations\Crafter.Build-Test.cpp -o .\build\Crafter.Build-Test_impl.o
|
||||||
|
clang++ %common_options% .\implementations\Crafter.Build-Progress.cpp -o .\build\Crafter.Build-Progress_impl.o
|
||||||
clang++ %common_options% .\implementations\main.cpp -o .\build\main.o
|
clang++ %common_options% .\implementations\main.cpp -o .\build\main.o
|
||||||
|
|
||||||
REM Step 1: link all impl .o files into crafter-build.dll, generating crafter-build.lib import lib
|
REM Step 1: link all impl .o files into crafter-build.dll, generating crafter-build.lib import lib
|
||||||
|
|
@ -75,6 +78,7 @@ clang++ %useLibcLinker% -shared -std=c++26 -O3 -march=%CRAFTER_BUILD_MARCH% -mtu
|
||||||
.\build\Crafter.Build-External.o ^
|
.\build\Crafter.Build-External.o ^
|
||||||
.\build\Crafter.Build-Clang.o ^
|
.\build\Crafter.Build-Clang.o ^
|
||||||
.\build\Crafter.Build-Test.o ^
|
.\build\Crafter.Build-Test.o ^
|
||||||
|
.\build\Crafter.Build-Progress.o ^
|
||||||
.\build\Crafter.Build.o ^
|
.\build\Crafter.Build.o ^
|
||||||
.\build\Crafter.Build-Shader_impl.o ^
|
.\build\Crafter.Build-Shader_impl.o ^
|
||||||
.\build\Crafter.Build-Platform_impl.o ^
|
.\build\Crafter.Build-Platform_impl.o ^
|
||||||
|
|
@ -83,6 +87,7 @@ clang++ %useLibcLinker% -shared -std=c++26 -O3 -march=%CRAFTER_BUILD_MARCH% -mtu
|
||||||
.\build\Crafter.Build-External_impl.o ^
|
.\build\Crafter.Build-External_impl.o ^
|
||||||
.\build\Crafter.Build-Clang_impl.o ^
|
.\build\Crafter.Build-Clang_impl.o ^
|
||||||
.\build\Crafter.Build-Test_impl.o ^
|
.\build\Crafter.Build-Test_impl.o ^
|
||||||
|
.\build\Crafter.Build-Progress_impl.o ^
|
||||||
-o .\bin\crafter-build.dll
|
-o .\bin\crafter-build.dll
|
||||||
|
|
||||||
REM Step 2: link the launcher exe against crafter-build.lib
|
REM Step 2: link the launcher exe against crafter-build.lib
|
||||||
|
|
@ -100,6 +105,7 @@ llvm-lib.exe /OUT:.\lib\crafter-build-static.lib ^
|
||||||
.\build\Crafter.Build-External.o ^
|
.\build\Crafter.Build-External.o ^
|
||||||
.\build\Crafter.Build-Clang.o ^
|
.\build\Crafter.Build-Clang.o ^
|
||||||
.\build\Crafter.Build-Test.o ^
|
.\build\Crafter.Build-Test.o ^
|
||||||
|
.\build\Crafter.Build-Progress.o ^
|
||||||
.\build\Crafter.Build.o ^
|
.\build\Crafter.Build.o ^
|
||||||
.\build\Crafter.Build-Shader_impl.o ^
|
.\build\Crafter.Build-Shader_impl.o ^
|
||||||
.\build\Crafter.Build-Platform_impl.o ^
|
.\build\Crafter.Build-Platform_impl.o ^
|
||||||
|
|
@ -107,6 +113,7 @@ llvm-lib.exe /OUT:.\lib\crafter-build-static.lib ^
|
||||||
.\build\Crafter.Build-Implementation_impl.o ^
|
.\build\Crafter.Build-Implementation_impl.o ^
|
||||||
.\build\Crafter.Build-External_impl.o ^
|
.\build\Crafter.Build-External_impl.o ^
|
||||||
.\build\Crafter.Build-Clang_impl.o ^
|
.\build\Crafter.Build-Clang_impl.o ^
|
||||||
.\build\Crafter.Build-Test_impl.o
|
.\build\Crafter.Build-Test_impl.o ^
|
||||||
|
.\build\Crafter.Build-Progress_impl.o
|
||||||
|
|
||||||
copy /Y "%LIBCXX_DIR%\lib\c++.dll" ".\bin\c++.dll"
|
copy /Y "%LIBCXX_DIR%\lib\c++.dll" ".\bin\c++.dll"
|
||||||
|
|
|
||||||
9
build.sh
9
build.sh
|
|
@ -15,6 +15,7 @@ cp interfaces/Crafter.Build-Implementation.cppm share/crafter-build/
|
||||||
cp interfaces/Crafter.Build-External.cppm share/crafter-build/
|
cp interfaces/Crafter.Build-External.cppm share/crafter-build/
|
||||||
cp interfaces/Crafter.Build-Clang.cppm share/crafter-build/
|
cp interfaces/Crafter.Build-Clang.cppm share/crafter-build/
|
||||||
cp interfaces/Crafter.Build-Test.cppm share/crafter-build/
|
cp interfaces/Crafter.Build-Test.cppm share/crafter-build/
|
||||||
|
cp interfaces/Crafter.Build-Progress.cppm share/crafter-build/
|
||||||
cp interfaces/Crafter.Build-Api.h share/crafter-build/
|
cp interfaces/Crafter.Build-Api.h share/crafter-build/
|
||||||
|
|
||||||
git clone https://github.com/KhronosGroup/glslang.git ./build/glslang
|
git clone https://github.com/KhronosGroup/glslang.git ./build/glslang
|
||||||
|
|
@ -50,6 +51,7 @@ clang++ $common_options -fmodule-output interfaces/Crafter.Build-Implementation.
|
||||||
clang++ $common_options -fmodule-output interfaces/Crafter.Build-External.cppm -o ./build/Crafter.Build-External.o
|
clang++ $common_options -fmodule-output interfaces/Crafter.Build-External.cppm -o ./build/Crafter.Build-External.o
|
||||||
clang++ $common_options -fmodule-output interfaces/Crafter.Build-Clang.cppm -o ./build/Crafter.Build-Clang.o
|
clang++ $common_options -fmodule-output interfaces/Crafter.Build-Clang.cppm -o ./build/Crafter.Build-Clang.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-Test.cppm -o ./build/Crafter.Build-Test.o
|
||||||
|
clang++ $common_options -fmodule-output interfaces/Crafter.Build-Progress.cppm -o ./build/Crafter.Build-Progress.o
|
||||||
clang++ $common_options -fmodule-output interfaces/Crafter.Build.cppm -o ./build/Crafter.Build.o
|
clang++ $common_options -fmodule-output interfaces/Crafter.Build.cppm -o ./build/Crafter.Build.o
|
||||||
|
|
||||||
clang++ $common_options ./implementations/Crafter.Build-Shader.cpp -o ./build/Crafter.Build-Shader_impl.o
|
clang++ $common_options ./implementations/Crafter.Build-Shader.cpp -o ./build/Crafter.Build-Shader_impl.o
|
||||||
|
|
@ -59,6 +61,7 @@ clang++ $common_options ./implementations/Crafter.Build-Implementation.cpp -o ./
|
||||||
clang++ $common_options ./implementations/Crafter.Build-External.cpp -o ./build/Crafter.Build-External_impl.o
|
clang++ $common_options ./implementations/Crafter.Build-External.cpp -o ./build/Crafter.Build-External_impl.o
|
||||||
clang++ $common_options ./implementations/Crafter.Build-Clang.cpp -o ./build/Crafter.Build-Clang_impl.o
|
clang++ $common_options ./implementations/Crafter.Build-Clang.cpp -o ./build/Crafter.Build-Clang_impl.o
|
||||||
clang++ $common_options ./implementations/Crafter.Build-Test.cpp -o ./build/Crafter.Build-Test_impl.o
|
clang++ $common_options ./implementations/Crafter.Build-Test.cpp -o ./build/Crafter.Build-Test_impl.o
|
||||||
|
clang++ $common_options ./implementations/Crafter.Build-Progress.cpp -o ./build/Crafter.Build-Progress_impl.o
|
||||||
clang++ $common_options ./implementations/main.cpp -o ./build/main.o
|
clang++ $common_options ./implementations/main.cpp -o ./build/main.o
|
||||||
|
|
||||||
ar rcs ./lib/libcrafter-build.a \
|
ar rcs ./lib/libcrafter-build.a \
|
||||||
|
|
@ -69,6 +72,7 @@ ar rcs ./lib/libcrafter-build.a \
|
||||||
./build/Crafter.Build-External.o \
|
./build/Crafter.Build-External.o \
|
||||||
./build/Crafter.Build-Clang.o \
|
./build/Crafter.Build-Clang.o \
|
||||||
./build/Crafter.Build-Test.o \
|
./build/Crafter.Build-Test.o \
|
||||||
|
./build/Crafter.Build-Progress.o \
|
||||||
./build/Crafter.Build.o \
|
./build/Crafter.Build.o \
|
||||||
./build/Crafter.Build-Shader_impl.o \
|
./build/Crafter.Build-Shader_impl.o \
|
||||||
./build/Crafter.Build-Platform_impl.o \
|
./build/Crafter.Build-Platform_impl.o \
|
||||||
|
|
@ -76,7 +80,8 @@ ar rcs ./lib/libcrafter-build.a \
|
||||||
./build/Crafter.Build-Implementation_impl.o \
|
./build/Crafter.Build-Implementation_impl.o \
|
||||||
./build/Crafter.Build-External_impl.o \
|
./build/Crafter.Build-External_impl.o \
|
||||||
./build/Crafter.Build-Clang_impl.o \
|
./build/Crafter.Build-Clang_impl.o \
|
||||||
./build/Crafter.Build-Test_impl.o
|
./build/Crafter.Build-Test_impl.o \
|
||||||
|
./build/Crafter.Build-Progress_impl.o
|
||||||
|
|
||||||
clang++ -std=c++26 -stdlib=libc++ -O3 -march=$MARCH -mtune=$MTUNE -fuse-ld=lld \
|
clang++ -std=c++26 -stdlib=libc++ -O3 -march=$MARCH -mtune=$MTUNE -fuse-ld=lld \
|
||||||
-Wl,--export-dynamic \
|
-Wl,--export-dynamic \
|
||||||
|
|
@ -88,6 +93,7 @@ clang++ -std=c++26 -stdlib=libc++ -O3 -march=$MARCH -mtune=$MTUNE -fuse-ld=lld \
|
||||||
./build/Crafter.Build-External.o \
|
./build/Crafter.Build-External.o \
|
||||||
./build/Crafter.Build-Clang.o \
|
./build/Crafter.Build-Clang.o \
|
||||||
./build/Crafter.Build-Test.o \
|
./build/Crafter.Build-Test.o \
|
||||||
|
./build/Crafter.Build-Progress.o \
|
||||||
./build/Crafter.Build.o \
|
./build/Crafter.Build.o \
|
||||||
./build/Crafter.Build-Shader_impl.o \
|
./build/Crafter.Build-Shader_impl.o \
|
||||||
./build/Crafter.Build-Platform_impl.o \
|
./build/Crafter.Build-Platform_impl.o \
|
||||||
|
|
@ -96,6 +102,7 @@ clang++ -std=c++26 -stdlib=libc++ -O3 -march=$MARCH -mtune=$MTUNE -fuse-ld=lld \
|
||||||
./build/Crafter.Build-External_impl.o \
|
./build/Crafter.Build-External_impl.o \
|
||||||
./build/Crafter.Build-Clang_impl.o \
|
./build/Crafter.Build-Clang_impl.o \
|
||||||
./build/Crafter.Build-Test_impl.o \
|
./build/Crafter.Build-Test_impl.o \
|
||||||
|
./build/Crafter.Build-Progress_impl.o \
|
||||||
./build/main.o \
|
./build/main.o \
|
||||||
-lSPIRV -lGenericCodeGen -lglslang -lOSDependent -lMachineIndependent -lglslang-default-resource-limits \
|
-lSPIRV -lGenericCodeGen -lglslang -lOSDependent -lMachineIndependent -lglslang-default-resource-limits \
|
||||||
-ldl \
|
-ldl \
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import std;
|
||||||
import :Clang;
|
import :Clang;
|
||||||
import :Platform;
|
import :Platform;
|
||||||
import :Test;
|
import :Test;
|
||||||
|
import :Progress;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace Crafter;
|
using namespace Crafter;
|
||||||
|
|
||||||
|
|
@ -252,6 +253,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
for (const Shader& shader : config.shaders) {
|
for (const Shader& shader : config.shaders) {
|
||||||
if (shader.Check(outputDir)) continue;
|
if (shader.Check(outputDir)) continue;
|
||||||
threads.emplace_back([&shader, &outputDir, &buildError, &buildCancelled]() {
|
threads.emplace_back([&shader, &outputDir, &buildError, &buildCancelled]() {
|
||||||
|
Progress::Task task(std::format("Compiling shader {}", shader.path.filename().string()));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
|
|
||||||
std::string result = shader.Compile(outputDir);
|
std::string result = shader.Compile(outputDir);
|
||||||
|
|
@ -265,6 +267,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
}
|
}
|
||||||
|
|
||||||
threads.emplace_back([&config, &outputDir, &buildCancelled, &buildError]() {
|
threads.emplace_back([&config, &outputDir, &buildCancelled, &buildError]() {
|
||||||
|
Progress::Task task(std::format("Copying files for {}", config.name));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
try {
|
try {
|
||||||
for (const fs::path& additionalFile : config.files) {
|
for (const fs::path& additionalFile : config.files) {
|
||||||
|
|
@ -320,6 +323,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
externalThreads.reserve(config.externalDependencies.size());
|
externalThreads.reserve(config.externalDependencies.size());
|
||||||
for (std::size_t i = 0; i < config.externalDependencies.size(); ++i) {
|
for (std::size_t i = 0; i < config.externalDependencies.size(); ++i) {
|
||||||
externalThreads.emplace_back([&, i]() {
|
externalThreads.emplace_back([&, i]() {
|
||||||
|
Progress::Task task(std::format("Building external dep {}", config.externalDependencies[i].name));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
externalResults[i] = BuildExternal(config.externalDependencies[i], config.target, buildCancelled);
|
externalResults[i] = BuildExternal(config.externalDependencies[i], config.target, buildCancelled);
|
||||||
if (!externalResults[i].error.empty()) {
|
if (!externalResults[i].error.empty()) {
|
||||||
|
|
@ -337,7 +341,11 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
fs::create_directories(stdPcmDir);
|
fs::create_directories(stdPcmDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stdPcmResult = BuildStdPcm(config, stdPcmDir/"std.pcm");
|
std::string stdPcmResult;
|
||||||
|
{
|
||||||
|
Progress::Task task(std::format("Building std PCM ({}-{})", config.target, config.march));
|
||||||
|
stdPcmResult = BuildStdPcm(config, stdPcmDir/"std.pcm");
|
||||||
|
}
|
||||||
if(!stdPcmResult.empty()) {
|
if(!stdPcmResult.empty()) {
|
||||||
buildCancelled.store(true);
|
buildCancelled.store(true);
|
||||||
for(std::thread& thread : threads) thread.join();
|
for(std::thread& thread : threads) thread.join();
|
||||||
|
|
@ -514,6 +522,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
const std::string srcPath = cFile.string() + ".c";
|
const std::string srcPath = cFile.string() + ".c";
|
||||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled, &config]() {
|
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled, &config]() {
|
||||||
|
Progress::Task task(std::format("Compiling {}.c", cFile.filename().string()));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
|
|
||||||
std::string result = RunCommand(std::format("clang {}.c --target={} -march={} -mtune={} -O3 -c -o {}_source.o", cFile.string(), config.target, config.march, config.mtune, (buildDir / cFile.filename()).string()));
|
std::string result = RunCommand(std::format("clang {}.c --target={} -march={} -mtune={} -O3 -c -o {}_source.o", cFile.string(), config.target, config.march, config.mtune, (buildDir / cFile.filename()).string()));
|
||||||
|
|
@ -533,6 +542,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
const std::string srcPath = cFile.string() + ".cu";
|
const std::string srcPath = cFile.string() + ".cu";
|
||||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled]() {
|
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled]() {
|
||||||
|
Progress::Task task(std::format("Compiling {}.cu", cFile.filename().string()));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
|
|
||||||
std::string result = RunCommand(std::format("nvcc {}.cu -c -o {}_source.o -O3 -arch=sm_89", cFile.string(), (buildDir / cFile.filename()).string()));
|
std::string result = RunCommand(std::format("nvcc {}.cu -c -o {}_source.o -O3 -arch=sm_89", cFile.string(), (buildDir / cFile.filename()).string()));
|
||||||
|
|
@ -580,6 +590,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
if(interface->Check(pcmDir, externalFloor)) {
|
if(interface->Check(pcmDir, externalFloor)) {
|
||||||
Module* mod = interface.get();
|
Module* mod = interface.get();
|
||||||
threads.emplace_back([mod, &command, &pcmDir, &buildDir, &buildCancelled, &buildError]() {
|
threads.emplace_back([mod, &command, &pcmDir, &buildDir, &buildCancelled, &buildError]() {
|
||||||
|
Progress::Task task(std::format("Compiling interface {}", mod->path.filename().string()));
|
||||||
try {
|
try {
|
||||||
mod->Compile(command, pcmDir, buildDir, buildCancelled, buildError);
|
mod->Compile(command, pcmDir, buildDir, buildCancelled, buildError);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
|
@ -602,6 +613,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
buildResult.repack = true;
|
buildResult.repack = true;
|
||||||
Implementation* impl = &implementation;
|
Implementation* impl = &implementation;
|
||||||
threads.emplace_back([impl, &command, &buildDir, &buildCancelled, &buildError]() {
|
threads.emplace_back([impl, &command, &buildDir, &buildCancelled, &buildError]() {
|
||||||
|
Progress::Task task(std::format("Compiling {}.cpp", impl->path.filename().string()));
|
||||||
try {
|
try {
|
||||||
impl->Compile(command, buildDir, buildCancelled, buildError);
|
impl->Compile(command, buildDir, buildCancelled, buildError);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
|
@ -694,6 +706,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buildResult.repack) {
|
if(buildResult.repack) {
|
||||||
|
Progress::Task task(std::format("Linking {}", config.outputName));
|
||||||
if(config.type == ConfigurationType::Executable) {
|
if(config.type == ConfigurationType::Executable) {
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||||
if(config.target == "x86_64-w64-mingw32") {
|
if(config.target == "x86_64-w64-mingw32") {
|
||||||
|
|
@ -848,6 +861,7 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
bool runTests = false;
|
bool runTests = false;
|
||||||
bool runAfterBuild = false;
|
bool runAfterBuild = false;
|
||||||
RunTestsOptions testOpts;
|
RunTestsOptions testOpts;
|
||||||
|
Progress::Verbosity verbosity = Progress::Verbosity::Default;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
std::string_view arg = argv[i];
|
std::string_view arg = argv[i];
|
||||||
|
|
@ -855,6 +869,10 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
runTests = true;
|
runTests = true;
|
||||||
} else if (arg == "-r") {
|
} else if (arg == "-r") {
|
||||||
runAfterBuild = true;
|
runAfterBuild = true;
|
||||||
|
} else if (arg == "-v" || arg == "--verbose") {
|
||||||
|
verbosity = Progress::Verbosity::Verbose;
|
||||||
|
} else if (arg == "-q" || arg == "--quiet") {
|
||||||
|
verbosity = Progress::Verbosity::Quiet;
|
||||||
} else if (arg.starts_with("--project=")) {
|
} else if (arg.starts_with("--project=")) {
|
||||||
projectFile = arg.substr(std::string_view("--project=").size());
|
projectFile = arg.substr(std::string_view("--project=").size());
|
||||||
} else if (runTests && arg.starts_with("--jobs=")) {
|
} else if (runTests && arg.starts_with("--jobs=")) {
|
||||||
|
|
@ -872,6 +890,8 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Progress::SetVerbosity(verbosity);
|
||||||
|
|
||||||
// The test run is target-scoped: only tests whose cfg.target equals
|
// The test run is target-scoped: only tests whose cfg.target equals
|
||||||
// testOpts.targetFilter are included. Default = host triple, so a
|
// testOpts.targetFilter are included. Default = host triple, so a
|
||||||
// bare `crafter-build test` runs everything that targets host.
|
// bare `crafter-build test` runs everything that targets host.
|
||||||
|
|
@ -899,10 +919,13 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
BuildResult result = Build(config, depResults, depMutex);
|
BuildResult result = Build(config, depResults, depMutex);
|
||||||
|
|
||||||
if (!result.result.empty()) {
|
if (!result.result.empty()) {
|
||||||
|
Progress::Clear();
|
||||||
std::println(std::cerr, "{}", result.result);
|
std::println(std::cerr, "{}", result.result);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Progress::Finalize();
|
||||||
|
|
||||||
if (runAfterBuild) {
|
if (runAfterBuild) {
|
||||||
if (config.type != ConfigurationType::Executable) {
|
if (config.type != ConfigurationType::Executable) {
|
||||||
std::println(std::cerr, "-r: cannot run a library");
|
std::println(std::cerr, "-r: cannot run a library");
|
||||||
|
|
@ -925,6 +948,7 @@ int Crafter::Run(int argc, char** argv) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
Progress::Clear();
|
||||||
std::println(std::cerr, "{}", e.what());
|
std::println(std::cerr, "{}", e.what());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ module Crafter.Build:Platform_impl;
|
||||||
import std;
|
import std;
|
||||||
import :Platform;
|
import :Platform;
|
||||||
import :Clang;
|
import :Clang;
|
||||||
|
import :Progress;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace Crafter;
|
using namespace Crafter;
|
||||||
|
|
||||||
|
|
@ -79,6 +80,7 @@ fs::path Crafter::GetCrafterBuildHome() {
|
||||||
|
|
||||||
#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)
|
||||||
std::string Crafter::RunCommand(const std::string_view cmd) {
|
std::string Crafter::RunCommand(const std::string_view cmd) {
|
||||||
|
Progress::EchoCommand(cmd);
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
|
|
@ -555,6 +557,7 @@ Configuration Crafter::LoadProject(const fs::path& projectFile, std::span<const
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||||
|
|
||||||
std::string Crafter::RunCommand(const std::string_view cmd) {
|
std::string Crafter::RunCommand(const std::string_view cmd) {
|
||||||
|
Progress::EchoCommand(cmd);
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
|
|
|
||||||
165
implementations/Crafter.Build-Progress.cpp
Normal file
165
implementations/Crafter.Build-Progress.cpp
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
Crafter® Build
|
||||||
|
Copyright (C) 2026 Catcrafts®
|
||||||
|
Catcrafts.net
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License version 3.0 as published by the Free Software Foundation;
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
module;
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <io.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#ifndef STDOUT_FILENO
|
||||||
|
#define STDOUT_FILENO _fileno(stdout)
|
||||||
|
#endif
|
||||||
|
#define CRAFTER_PROGRESS_ISATTY _isatty
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#define CRAFTER_PROGRESS_ISATTY isatty
|
||||||
|
#endif
|
||||||
|
|
||||||
|
export module Crafter.Build:Progress_impl;
|
||||||
|
import std;
|
||||||
|
import :Progress;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::mutex g_mutex;
|
||||||
|
std::atomic<int> g_total{0};
|
||||||
|
std::atomic<int> g_done{0};
|
||||||
|
Crafter::Progress::Verbosity g_verbosity = Crafter::Progress::Verbosity::Default;
|
||||||
|
bool g_isTty = false;
|
||||||
|
bool g_lineDirty = false; // status line has uncleared content
|
||||||
|
bool g_finalized = false;
|
||||||
|
std::chrono::steady_clock::time_point g_startTime = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
int TerminalWidth() {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||||
|
if (h != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(h, &info)) {
|
||||||
|
int w = info.srWindow.Right - info.srWindow.Left + 1;
|
||||||
|
if (w > 0) return w;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
winsize ws{};
|
||||||
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 0) {
|
||||||
|
return ws.ws_col;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (const char* col = std::getenv("COLUMNS")) {
|
||||||
|
try { int c = std::stoi(col); if (c > 0) return c; } catch (...) {}
|
||||||
|
}
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caller holds g_mutex.
|
||||||
|
void RenderStatus(std::string_view label) {
|
||||||
|
if (g_verbosity != Crafter::Progress::Verbosity::Default || !g_isTty) return;
|
||||||
|
int done = g_done.load(std::memory_order_relaxed);
|
||||||
|
int total = g_total.load(std::memory_order_relaxed);
|
||||||
|
std::string prefix = std::format("[{}/{}] ", done, total);
|
||||||
|
int width = TerminalWidth();
|
||||||
|
int avail = width - static_cast<int>(prefix.size()) - 1;
|
||||||
|
std::string trimmed{label};
|
||||||
|
if (avail > 0 && static_cast<int>(trimmed.size()) > avail) {
|
||||||
|
trimmed.resize(static_cast<std::size_t>(avail));
|
||||||
|
}
|
||||||
|
// \r returns to col 0, \033[2K erases the whole line. No newline.
|
||||||
|
std::fputs("\r\033[2K", stdout);
|
||||||
|
std::fputs(prefix.c_str(), stdout);
|
||||||
|
std::fputs(trimmed.c_str(), stdout);
|
||||||
|
std::fflush(stdout);
|
||||||
|
g_lineDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caller holds g_mutex.
|
||||||
|
void ClearLineLocked() {
|
||||||
|
if (g_lineDirty) {
|
||||||
|
std::fputs("\r\033[2K", stdout);
|
||||||
|
std::fflush(stdout);
|
||||||
|
g_lineDirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Crafter::Progress {
|
||||||
|
|
||||||
|
void SetVerbosity(Verbosity v) {
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
g_verbosity = v;
|
||||||
|
g_isTty = CRAFTER_PROGRESS_ISATTY(STDOUT_FILENO) != 0;
|
||||||
|
g_startTime = std::chrono::steady_clock::now();
|
||||||
|
g_total.store(0);
|
||||||
|
g_done.store(0);
|
||||||
|
g_finalized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Verbosity GetVerbosity() {
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
return g_verbosity;
|
||||||
|
}
|
||||||
|
|
||||||
|
Task::Task(std::string label) : label_(std::move(label)) {
|
||||||
|
g_total.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_verbosity == Verbosity::Default && g_isTty) {
|
||||||
|
RenderStatus(label_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Task::~Task() {
|
||||||
|
int done = g_done.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_verbosity == Verbosity::Default) {
|
||||||
|
if (g_isTty) {
|
||||||
|
RenderStatus(label_);
|
||||||
|
} else {
|
||||||
|
// Non-TTY: one append-only line per completed task (ninja-style).
|
||||||
|
int total = g_total.load(std::memory_order_relaxed);
|
||||||
|
std::println("[{}/{}] {}", done, total, label_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EchoCommand(std::string_view command) {
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_verbosity == Verbosity::Verbose) {
|
||||||
|
std::println("$ {}", command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
ClearLineLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Finalize() {
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_finalized) return;
|
||||||
|
g_finalized = true;
|
||||||
|
ClearLineLocked();
|
||||||
|
if (g_verbosity == Verbosity::Quiet) return;
|
||||||
|
int done = g_done.load();
|
||||||
|
if (done == 0) return; // Nothing happened (cached build); stay silent.
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
std::chrono::steady_clock::now() - g_startTime);
|
||||||
|
std::println("Built {} step{} in {}ms",
|
||||||
|
done, done == 1 ? "" : "s", elapsed.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Crafter::Progress
|
||||||
|
|
@ -22,6 +22,7 @@ import std;
|
||||||
import :Test;
|
import :Test;
|
||||||
import :Clang;
|
import :Clang;
|
||||||
import :Platform;
|
import :Platform;
|
||||||
|
import :Progress;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using namespace Crafter;
|
using namespace Crafter;
|
||||||
|
|
||||||
|
|
@ -161,6 +162,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintResult(const TestResult& r, std::string_view runnerName) {
|
void PrintResult(const TestResult& r, std::string_view runnerName) {
|
||||||
|
Progress::Clear();
|
||||||
auto ms = r.duration.count();
|
auto ms = r.duration.count();
|
||||||
std::string runnerSuffix = (runnerName.empty() || runnerName == "local")
|
std::string runnerSuffix = (runnerName.empty() || runnerName == "local")
|
||||||
? std::string()
|
? std::string()
|
||||||
|
|
@ -719,6 +721,7 @@ TestSummary Crafter::RunTests(Configuration& projectCfg, const RunTestsOptions&
|
||||||
}
|
}
|
||||||
summary.results = std::move(results);
|
summary.results = std::move(results);
|
||||||
|
|
||||||
|
Progress::Clear();
|
||||||
std::print("\n");
|
std::print("\n");
|
||||||
std::vector<std::string> parts;
|
std::vector<std::string> parts;
|
||||||
if (summary.passed) parts.push_back(std::format("{} passed", summary.passed));
|
if (summary.passed) parts.push_back(std::format("{} passed", summary.passed));
|
||||||
|
|
|
||||||
57
interfaces/Crafter.Build-Progress.cppm
Normal file
57
interfaces/Crafter.Build-Progress.cppm
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Crafter® Build
|
||||||
|
Copyright (C) 2026 Catcrafts®
|
||||||
|
Catcrafts.net
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License version 3.0 as published by the Free Software Foundation;
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
module;
|
||||||
|
#include "Crafter.Build-Api.h"
|
||||||
|
export module Crafter.Build:Progress;
|
||||||
|
import std;
|
||||||
|
|
||||||
|
export namespace Crafter::Progress {
|
||||||
|
enum class Verbosity { Quiet, Default, Verbose };
|
||||||
|
|
||||||
|
CRAFTER_API void SetVerbosity(Verbosity v);
|
||||||
|
CRAFTER_API Verbosity GetVerbosity();
|
||||||
|
|
||||||
|
// RAII work-unit marker. Construction inflates the running total; destruction
|
||||||
|
// increments completed and (on Default + TTY) redraws the status line. Move
|
||||||
|
// semantics are disabled — keep these as plain stack locals inside the worker
|
||||||
|
// lambda so the destructor fires when that thread's work ends.
|
||||||
|
class CRAFTER_API Task {
|
||||||
|
public:
|
||||||
|
explicit Task(std::string label);
|
||||||
|
~Task();
|
||||||
|
Task(const Task&) = delete;
|
||||||
|
Task& operator=(const Task&) = delete;
|
||||||
|
Task(Task&&) = delete;
|
||||||
|
Task& operator=(Task&&) = delete;
|
||||||
|
private:
|
||||||
|
std::string label_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Verbose-mode command echo. No-op outside Verbose.
|
||||||
|
CRAFTER_API void EchoCommand(std::string_view command);
|
||||||
|
|
||||||
|
// Erase the in-place status line so subsequent stderr writes (errors,
|
||||||
|
// banners) don't collide with it. No-op when not in TTY-redraw mode.
|
||||||
|
CRAFTER_API void Clear();
|
||||||
|
|
||||||
|
// Print "Built N targets in Xms" (or equivalent) and clear in-place state.
|
||||||
|
// Safe to call multiple times; subsequent calls are no-ops.
|
||||||
|
CRAFTER_API void Finalize();
|
||||||
|
}
|
||||||
|
|
@ -24,3 +24,4 @@ export import :Implementation;
|
||||||
export import :Shader;
|
export import :Shader;
|
||||||
export import :External;
|
export import :External;
|
||||||
export import :Test;
|
export import :Test;
|
||||||
|
export import :Progress;
|
||||||
|
|
@ -35,7 +35,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
||||||
: ConfigurationType::LibraryStatic;
|
: ConfigurationType::LibraryStatic;
|
||||||
crafterBuildLib->debug = debug;
|
crafterBuildLib->debug = debug;
|
||||||
{
|
{
|
||||||
std::array<fs::path, 8> interfaces = {
|
std::array<fs::path, 9> interfaces = {
|
||||||
"interfaces/Crafter.Build",
|
"interfaces/Crafter.Build",
|
||||||
"interfaces/Crafter.Build-Shader",
|
"interfaces/Crafter.Build-Shader",
|
||||||
"interfaces/Crafter.Build-Platform",
|
"interfaces/Crafter.Build-Platform",
|
||||||
|
|
@ -44,8 +44,9 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
||||||
"interfaces/Crafter.Build-External",
|
"interfaces/Crafter.Build-External",
|
||||||
"interfaces/Crafter.Build-Clang",
|
"interfaces/Crafter.Build-Clang",
|
||||||
"interfaces/Crafter.Build-Test",
|
"interfaces/Crafter.Build-Test",
|
||||||
|
"interfaces/Crafter.Build-Progress",
|
||||||
};
|
};
|
||||||
std::array<fs::path, 7> implementations = {
|
std::array<fs::path, 8> implementations = {
|
||||||
"implementations/Crafter.Build-Shader",
|
"implementations/Crafter.Build-Shader",
|
||||||
"implementations/Crafter.Build-Platform",
|
"implementations/Crafter.Build-Platform",
|
||||||
"implementations/Crafter.Build-Interface",
|
"implementations/Crafter.Build-Interface",
|
||||||
|
|
@ -53,6 +54,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
||||||
"implementations/Crafter.Build-External",
|
"implementations/Crafter.Build-External",
|
||||||
"implementations/Crafter.Build-Clang",
|
"implementations/Crafter.Build-Clang",
|
||||||
"implementations/Crafter.Build-Test",
|
"implementations/Crafter.Build-Test",
|
||||||
|
"implementations/Crafter.Build-Progress",
|
||||||
};
|
};
|
||||||
crafterBuildLib->GetInterfacesAndImplementations(interfaces, implementations);
|
crafterBuildLib->GetInterfacesAndImplementations(interfaces, implementations);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue