Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/worker/config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.h"
#include "protocol.h"
#include <algorithm>
#include <filesystem>
#include <iostream>

namespace suco::worker {
Expand Down Expand Up @@ -61,11 +62,21 @@ Config Config::parse(int argc, char** argv) {
if (hc_dir_env) {
config.header_cache_dir = hc_dir_env;
} else {
// HOME is normally unset on Windows (it uses USERPROFILE/LOCALAPPDATA), so the
// old "/tmp/..." fallback handed a Windows worker a path that cannot exist.
// Try the platform's own home variables, then the platform temp dir.
const char* home = std::getenv("HOME");
if (home) {
#ifdef _WIN32
if (!home) home = std::getenv("LOCALAPPDATA");
if (!home) home = std::getenv("USERPROFILE");
#endif
if (home && *home) {
config.header_cache_dir = std::string(home) + "/.cache/suco/headers";
} else {
config.header_cache_dir = "/tmp/.cache/suco/headers";
std::error_code ec;
const std::filesystem::path tdir = std::filesystem::temp_directory_path(ec);
config.header_cache_dir =
(ec ? std::string(".") : tdir.generic_string()) + "/.cache/suco/headers";
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/worker/toolchain_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ bool ToolchainManager::extract_toolchain(const std::string& hash, const std::str

SUCO_LOG_INFO("Extracting toolchain {} from {}...", hash, archive_path);

// `-I zstd` is GNU tar syntax. Windows 10/11 ship **bsdtar** (libarchive) as
// tar.exe, which rejects -I outright — so a Windows worker failed every toolchain
// extraction and could never run a dispatched job at all. bsdtar detects zstd from
// the stream itself, so plain -xf is both sufficient and correct there.
#ifdef _WIN32
std::string cmd = "tar -xf \"" + archive_path + "\" -C \"" + tmp_dir + "\"";
#else
std::string cmd = "tar -I zstd -xf \"" + archive_path + "\" -C \"" + tmp_dir + "\"";
#endif
std::string out_log;
if (!run_cmd_simple(cmd, out_log)) {
SUCO_LOG_ERROR("Failed to extract toolchain archive {}. Output: {}", archive_path, out_log);
Expand Down
10 changes: 9 additions & 1 deletion src/worker/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,15 @@ void Worker::run_worker_compile_loop() {
std::error_code ec;
std::filesystem::create_directories(std::filesystem::path(cache_dir).parent_path(), ec);

std::string temp_archive = "/tmp/suco_tc_recv_" + toolchain_hash + ".tar.zst";
// Use the platform temp dir: "/tmp" does not exist on a
// Windows worker, so this write failed and the toolchain
// was never received. Fall back next to the cache dir if
// the temp dir cannot be determined.
std::error_code tec;
std::filesystem::path tdir = std::filesystem::temp_directory_path(tec);
if (tec) { tec.clear(); tdir = std::filesystem::path(cache_dir).parent_path(); }
std::string temp_archive =
(tdir / ("suco_tc_recv_" + toolchain_hash + ".tar.zst")).string();
if (suco::receive_file(download_sock, temp_archive)) {
SUCO_LOG_INFO("Worker successfully received toolchain archive: {}", temp_archive);
ToolchainManager::extract_toolchain(toolchain_hash, temp_archive);
Expand Down
Loading