Skip to content

Commit a0e8186

Browse files
committed
cli(build): make build heartbeat opt-in via VIX_BUILD_HEARTBEAT and document it in help
1 parent 76e7ec2 commit a0e8186

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

src/cmake/CMakeBuild.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ namespace vix::cli::build
244244

245245
const bool filterCMakeSummary = is_configure_cmd(argv) && !cmakeVerbose;
246246

247+
const bool heartbeatEnabled = [&]() -> bool
248+
{
249+
if (quiet)
250+
return false;
251+
const char *v = std::getenv("VIX_BUILD_HEARTBEAT");
252+
if (!v)
253+
return false;
254+
255+
std::string s(v);
256+
s = util::trim(s);
257+
for (char &c : s)
258+
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
259+
260+
return (s == "1" || s == "true" || s == "yes" || s == "on");
261+
}();
262+
247263
int pipefd[2];
248264
if (::pipe(pipefd) != 0)
249265
{
@@ -332,10 +348,11 @@ namespace vix::cli::build
332348

333349
std::string buf(16 * 1024, '\0');
334350

335-
// Heartbeat state
351+
// Heartbeat state (only used if enabled)
336352
const auto startTs = std::chrono::steady_clock::now();
337353
auto lastOutputTs = startTs;
338354
auto lastHeartbeatTs = startTs;
355+
bool heartbeatPrinted = false;
339356

340357
// poll loop
341358
while (true)
@@ -345,7 +362,7 @@ namespace vix::cli::build
345362
pfd.events = POLLIN | POLLHUP | POLLERR;
346363
pfd.revents = 0;
347364

348-
// 250ms tick -> lets us print heartbeat & not look frozen
365+
// 250ms tick -> lets us keep UI responsive (and optional heartbeat)
349366
const int pr = ::poll(&pfd, 1, 250);
350367

351368
if (pr < 0)
@@ -413,8 +430,7 @@ namespace vix::cli::build
413430
if (pr > 0 && (pfd.revents & (POLLHUP | POLLERR)))
414431
break;
415432

416-
// No output tick -> heartbeat (avoid "looks frozen")
417-
if (!quiet)
433+
if (heartbeatEnabled)
418434
{
419435
const auto now = std::chrono::steady_clock::now();
420436
const auto silenceMs =
@@ -430,8 +446,9 @@ namespace vix::cli::build
430446
std::chrono::duration_cast<std::chrono::milliseconds>(now - startTs).count();
431447

432448
std::string msg =
433-
"\r[building] still running (" + util::format_seconds(elapsedMs) + ") ";
449+
"\r[building] still running... (" + util::format_seconds(elapsedMs) + ") ";
434450
write_all_fd(STDOUT_FILENO, msg.data(), msg.size());
451+
heartbeatPrinted = true;
435452
}
436453
}
437454
}
@@ -456,17 +473,19 @@ namespace vix::cli::build
456473
return r;
457474
}
458475

459-
if (!quiet)
476+
// clear heartbeat line only if it was printed
477+
if (heartbeatEnabled && heartbeatPrinted)
460478
{
461-
// clear heartbeat line if any
462-
const std::string clear = "\r";
479+
// best-effort: overwrite the line then return carriage
480+
const std::string clear = "\r\033[2K\r";
463481
write_all_fd(STDOUT_FILENO, clear.data(), clear.size());
464482
}
465483

466484
r.exitCode = process::normalize_exit_code(status);
467485
r.capturedFirstLine = util::trim(firstLine);
468486
return r;
469487
}
488+
470489
#else // _WIN32
471490

472491
process::ExecResult run_process_capture(

src/commands/BuildCommand.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -919,43 +919,38 @@ namespace vix::commands::BuildCommand
919919

920920
out << "Options:\n";
921921
out << " --preset <name> Preset to use (dev, dev-ninja, release)\n";
922-
out << " --target <triple> Cross-compilation target triple (auto "
923-
"toolchain)\n";
922+
out << " --target <triple> Cross-compilation target triple (auto toolchain)\n";
924923
out << " --sysroot <path> Sysroot for cross toolchain (optional)\n";
925-
out << " --static Request static linking "
926-
"(VIX_LINK_STATIC=ON)\n";
927-
out << " -j, --jobs <n> Parallel build jobs (default: CPU count, "
928-
"clamped)\n";
924+
out << " --static Request static linking (VIX_LINK_STATIC=ON)\n";
925+
out << " -j, --jobs <n> Parallel build jobs (default: CPU count, clamped)\n";
929926
out << " --clean Force reconfigure (ignore cache/signature)\n";
930927
out << " --no-cache Disable signature cache shortcut\n";
931-
out << " --fast Fast loop: if Ninja says up-to-date, exit "
932-
"immediately\n";
933-
out << " --linker <mode> auto|default|mold|lld (auto prefers mold "
934-
"then lld)\n";
935-
out << " --launcher <mode> auto|none|sccache|ccache (auto prefers "
936-
"sccache)\n";
928+
out << " --fast Fast loop: if Ninja says up-to-date, exit immediately\n";
929+
out << " --linker <mode> auto|default|mold|lld (auto prefers mold then lld)\n";
930+
out << " --launcher <mode> auto|none|sccache|ccache (auto prefers sccache)\n";
937931
out << " --no-status Disable NINJA_STATUS progress format\n";
938932
out << " --no-up-to-date Disable Ninja dry-run up-to-date detection\n";
939-
out << " -d, --dir <path> Project directory (where CMakeLists.txt "
940-
"lives)\n";
933+
out << " -d, --dir <path> Project directory (where CMakeLists.txt lives)\n";
941934
out << " -q, --quiet Minimal output (still logs to files)\n";
942935
out << " --targets List detected cross toolchains on PATH\n";
943-
out << " --cmake-verbose Show raw CMake configure output (no summary "
944-
"filtering)\n";
945-
out << " --build-target <name> Build only a specific CMake target (ex: "
946-
"blog)\n";
936+
out << " --cmake-verbose Show raw CMake configure output (no summary filtering)\n";
937+
out << " --build-target <name> Build only a specific CMake target (ex: blog)\n";
947938
out << " -h, --help Show this help\n\n";
948939

940+
out << "Environment variables:\n";
941+
out << " VIX_BUILD_HEARTBEAT=1 Enable build heartbeat when no output is produced\n";
942+
out << " for several seconds (disabled by default)\n\n";
943+
949944
out << "Examples:\n";
950945
out << " vix build\n";
951946
out << " vix build --fast\n";
952947
out << " vix build --preset release\n";
953948
out << " vix build --preset release --static\n";
954949
out << " vix build --launcher sccache --linker mold\n";
955950
out << " vix build --target aarch64-linux-gnu\n";
956-
out << " vix build --preset release -target aarch64-linux-gnu\n";
951+
out << " vix build --preset release --target aarch64-linux-gnu\n";
957952
out << " vix build --linker lld -- -DVIX_SYNC_BUILD_TESTS=ON\n";
958-
953+
out << " VIX_BUILD_HEARTBEAT=1 vix build\n";
959954
out << " vix build -j 8\n\n";
960955

961956
out << "Logs:\n";
@@ -964,4 +959,5 @@ namespace vix::commands::BuildCommand
964959

965960
return 0;
966961
}
962+
967963
} // namespace vix::commands::BuildCommand

0 commit comments

Comments
 (0)