feat(platform): build on native Windows hosts
VoidBuildSystem CI / 1 · Requirements (push) Successful in 6s
VoidBuildSystem CI / 2C · Windows native build (debug) (push) Failing after 1m32s
VoidBuildSystem CI / 2C · Windows native build (sanitizers) (push) Failing after 18s
VoidBuildSystem CI / 2C · Windows native build (relwithdebinfo) (push) Failing after 3m4s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 6m20s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 6m32s
VoidBuildSystem CI / 3C · Windows native test (debug) (push) Failing after 1m45s
VoidBuildSystem CI / 2B · Windows Wine build (sanitizers) (push) Successful in 6m55s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 6m59s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m59s
VoidBuildSystem CI / 3C · Windows native test (sanitizers) (push) Failing after 15s
VoidBuildSystem CI / 3C · Windows native test (relwithdebinfo) (push) Failing after 1m47s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m4s
VoidBuildSystem CI / 4B · Windows package (debug) (push) Successful in 1m6s
VoidBuildSystem CI / 4B · Windows package (sanitizers) (push) Successful in 12s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m2s
VoidBuildSystem CI / 4B · Windows package (relwithdebinfo) (push) Successful in 1m44s
VoidBuildSystem CI / 3B · Windows Wine test (sanitizers) (push) Successful in 3m16s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 3m21s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m45s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m54s
VoidBuildSystem CI / 4A · Linux package (debug) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (relwithdebinfo) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (sanitizers) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 3m42s

Bump VoidLibrary to 482a3ea (Windows target support: qualified
Configuration/Crypto/System/Archive, Windows DirectoryWatcher,
TempDir/TempFile, process pipes) and port VBS's own host backends:

- Toolchain: Windows/macOS host names and architectures without uname.
- Platform FileOps: Win32 stat metadata, CreateFileW+LockFileEx file
  locks (Void FileLock is POSIX-only, Void/Library#66), no-op
  directory fsync, GetModuleFileNameW executable path, mtime via
  std::filesystem, and a file-copy fallback for the compdb alias.
- ProcessSupervisor: Windows PATH/PATHEXT resolution and no POSIX
  waitpid reaping (job objects own descendants).
- Snapshot: directory listing through std::filesystem on Windows.
- Remote cache/registry client/CDash: curl or Winsock-based HTTP on
  Windows (Void::Net is not qualified there yet).
- Daemon: explicit unsupported errors on Windows (named-pipe
  transport is Track C3); the registry service stays POSIX-only and
  is excluded from the Windows build.
- StateStore/Sbom/Main/Graph: portable stat, time and path handling.

Verified: MinGW-w64 GCC 16.2 builds vbs, vbs_describe, vbs_benchmarks
and the sdk/core/v1/selfhost test executables; vbs runs under Wine
and the SDK suite passes 17/17. The Linux suite stays green (8/8).
This commit is contained in:
faumaray committed 2026-12-06 02:01:24 +03:00
1 parent 8768720e54
commit e333bbe84b
23 files changed
+715 -127

No files matched your search

+56 -10
View File
@@ -40,25 +40,25 @@
#include <fstream>
#include <limits>
#include <optional>
#include <poll.h>
#include <string>
#include <string_view>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <system_error>
#include <unistd.h>
#include <utility>
#include <variant>
// The daemon control socket is a POSIX Unix-domain socket (Linux/macOS). Windows support is
// planned (Track C3) and would need a named-pipe transport instead.
#if defined(_WIN32)
#error \
"The vbs daemon Unix-socket transport requires a POSIX host (Track C3 Windows port is planned)."
#endif
// The daemon control socket is a POSIX Unix-domain socket (Linux/macOS); the
// Windows named-pipe transport is planned for Track C3.
#include <vector>
#if !defined(_WIN32)
#include <poll.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#endif
#if !defined(_WIN32)
namespace Void::Build::Daemon {
namespace {
@@ -3099,3 +3099,49 @@ request(const std::filesystem::path &socket_path, std::string_view request_json,
}
} // namespace Void::Build::Daemon
#else
namespace Void::Build::Daemon {
struct DaemonServer::Impl {};
DaemonServer::~DaemonServer() = default;
DaemonServer::DaemonServer(DaemonServer &&) noexcept = default;
DaemonServer &DaemonServer::operator=(DaemonServer &&) noexcept = default;
DaemonServer::DaemonServer(std::unique_ptr<Impl> impl) noexcept : impl_{std::move(impl)} {}
Void::Result::Result<DaemonServer, Void::Result::Error>
DaemonServer::create(DaemonOptions options) {
(void)options;
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::unsupported,
"vbs daemon: the Windows named-pipe transport is not implemented (Track C3)")};
}
Void::Result::Result<void, Void::Result::Error> DaemonServer::run(std::stop_token stop) {
(void)stop;
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::unsupported,
"vbs daemon: the Windows named-pipe transport is not implemented (Track C3)")};
}
const std::filesystem::path &DaemonServer::socket_path() const noexcept {
static const std::filesystem::path empty;
return empty;
}
DaemonStatus DaemonServer::status() const { return {}; }
Void::Result::Result<std::string, Void::Result::Error>
request(const std::filesystem::path &socket_path, std::string_view request_json,
std::chrono::milliseconds timeout) {
(void)socket_path;
(void)request_json;
(void)timeout;
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::unsupported,
"vbs daemon: the Windows named-pipe transport is not implemented (Track C3)")};
}
} // namespace Void::Build::Daemon
#endif
+1 -1
View File
@@ -530,7 +530,7 @@ expand_glob(const std::filesystem::path &project_root, std::string_view pattern)
const std::filesystem::path raw_pattern{std::string{pattern}};
if (raw_pattern.is_absolute()) {
const auto rel_pattern = raw_pattern.lexically_relative(canonical_root);
if (!rel_pattern.empty() && rel_pattern.native().starts_with("..")) {
if (!rel_pattern.empty() && rel_pattern.generic_string().starts_with("..")) {
return std::unexpected{
make_error(std::format("expand_glob: pattern '{}' escapes project root '{}'",
pattern, canonical_root.string()))};
+5 -1
View File
@@ -1225,7 +1225,11 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
const std::time_t now =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm tm{};
#if defined(_WIN32)
::gmtime_s(&tm, &now);
#else
::gmtime_r(&now, &tm);
#endif
cdash.build_stamp =
std::format("{:04d}{:02d}{:02d}-{:02d}{:02d}-Experimental", tm.tm_year + 1900,
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
@@ -1301,7 +1305,7 @@ int execute_workspace(BuildCmdOptions opts, bool run_tests) {
member_dirs[member.name] = canonical;
const std::string env_name = "VBS_WORKSPACE_MEMBER_" + member.name;
#if defined(_WIN32)
(void)_putenv_s(env_name.c_str(), canonical.c_str());
(void)_putenv_s(env_name.c_str(), canonical.string().c_str());
#else
(void)::setenv(env_name.c_str(), canonical.c_str(), 1);
#endif
+61 -8
View File
@@ -18,16 +18,22 @@
#endif
#include <algorithm>
#include <arpa/inet.h>
#include <array>
#include <cerrno>
#include <cstring>
#include <format>
#include <map>
#include <mutex>
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
namespace Void::Build::Package {
namespace {
@@ -93,12 +99,49 @@ struct RawHttpReply {
std::string body;
};
bool send_all(int fd, std::string_view data) {
#if defined(_WIN32)
using SocketHandle = SOCKET;
inline constexpr SocketHandle kInvalidSocket = INVALID_SOCKET;
void ensure_socket_runtime() {
static std::once_flag once;
std::call_once(once, [] {
WSADATA data{};
(void)::WSAStartup(MAKEWORD(2, 2), &data);
});
}
struct SocketGuard {
SocketHandle handle{kInvalidSocket};
~SocketGuard() {
if (handle != kInvalidSocket) {
::closesocket(handle);
}
}
};
bool interrupted() { return ::WSAGetLastError() == WSAEINTR; }
#else
using SocketHandle = int;
inline constexpr SocketHandle kInvalidSocket = -1;
void ensure_socket_runtime() {}
using SocketGuard = Void::System::OwnedFd;
bool interrupted() { return errno == EINTR; }
#endif
bool send_all(SocketHandle fd, std::string_view data) {
std::size_t off = 0;
while (off < data.size()) {
#if defined(_WIN32)
const int n = ::send(fd, data.data() + off, static_cast<int>(data.size() - off), 0);
#else
const ssize_t n = ::send(fd, data.data() + off, data.size() - off, MSG_NOSIGNAL);
#endif
if (n < 0) {
if (errno == EINTR) {
if (interrupted()) {
continue;
}
return false;
@@ -154,6 +197,7 @@ send_http_request(const ParsedHttpUrl &parsed, std::string_view method, std::str
#else
// Plain TCP HTTP/1.1 client for http:// (loopback/local registry without external deps).
if (parsed.scheme == "http") {
ensure_socket_runtime();
struct addrinfo hints{};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
@@ -166,18 +210,27 @@ send_http_request(const ParsedHttpUrl &parsed, std::string_view method, std::str
}
auto free_ai = Void::Scope::on_exit([&] { ::freeaddrinfo(res); });
const int fd = ::socket(res->ai_family, res->ai_socktype | SOCK_CLOEXEC, res->ai_protocol);
if (fd < 0) {
const SocketHandle fd =
::socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (fd == kInvalidSocket) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"registry client: socket() failed")};
}
Void::System::OwnedFd guard{fd};
SocketGuard guard{fd};
#if defined(_WIN32)
DWORD timeout_ms = 30000;
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<const char *>(&timeout_ms), sizeof(timeout_ms));
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO,
reinterpret_cast<const char *>(&timeout_ms), sizeof(timeout_ms));
#else
struct timeval tv{30, 0};
(void)::setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
(void)::setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
#endif
if (::connect(fd, res->ai_addr, res->ai_addrlen) != 0) {
if (::connect(fd, res->ai_addr, static_cast<int>(res->ai_addrlen)) != 0) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("registry client: connect to {}:{} failed", parsed.host, parsed.port))};
@@ -204,7 +257,7 @@ send_http_request(const ParsedHttpUrl &parsed, std::string_view method, std::str
raw.append(buf.data(), static_cast<std::size_t>(n));
} else if (n == 0) {
break;
} else if (errno != EINTR) {
} else if (!interrupted()) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"registry client: recv() failed")};
}
+189 -6
View File
@@ -3,16 +3,23 @@
#include <Void/System/Types.hpp>
#include <cerrno>
#include <fcntl.h>
#include <chrono>
#include <format>
#include <set>
#include <sys/stat.h>
#include <unistd.h>
#include <system_error>
#include <utility>
#if !defined(__linux__)
#if defined(_WIN32)
#include <windows.h>
#else
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#if !defined(__linux__) && !defined(_WIN32)
#error \
"VoidBuildSystem's process and file backends currently support Linux hosts only (Track C2/C3 ports are planned)"
"VoidBuildSystem's process and file backends currently support Linux and Windows hosts only (Track C2/C3 ports are planned)"
#endif
namespace Void::Build::Platform {
@@ -36,6 +43,44 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
lock_path.string(), ec.message()))};
}
}
#if defined(_WIN32)
// Void::FileSystem::FileLock is POSIX-only (Void/Library issue #66).
const HANDLE raw = ::CreateFileW(lock_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (raw == INVALID_HANDLE_VALUE) {
const DWORD err = ::GetLastError();
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::io_error,
std::format("FileLock: cannot open '{}' (error {})", lock_path.string(), err),
static_cast<int>(err))};
}
OVERLAPPED overlapped{};
DWORD flags = mode == LockMode::Exclusive ? LOCKFILE_EXCLUSIVE_LOCK : 0;
if (non_blocking) {
flags |= LOCKFILE_FAIL_IMMEDIATELY;
}
if (::LockFileEx(raw, flags, 0, MAXDWORD, MAXDWORD, &overlapped) == 0) {
const DWORD err = ::GetLastError();
::CloseHandle(raw);
if (non_blocking && (err == ERROR_LOCK_VIOLATION || err == ERROR_IO_PENDING)) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::busy,
std::format("FileLock: '{}' is already locked", lock_path.string()), EAGAIN)};
}
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::io_error,
std::format("FileLock: locking '{}' failed (error {})", lock_path.string(), err),
static_cast<int>(err))};
}
auto handle = std::shared_ptr<void>{raw, [](void *h) {
OVERLAPPED unlock{};
(void)::UnlockFileEx(static_cast<HANDLE>(h), 0, MAXDWORD,
MAXDWORD, &unlock);
(void)::CloseHandle(static_cast<HANDLE>(h));
}};
return FileLock{std::move(handle)};
#else
const auto vl_mode = (mode == LockMode::Exclusive) ? Void::FileSystem::LockMode::Exclusive
: Void::FileSystem::LockMode::Shared;
if (non_blocking) {
@@ -46,7 +91,7 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
if (!res->has_value()) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::busy,
std::format("FileLock: '{}' is already locked", lock_path.string()), EWOULDBLOCK)};
std::format("FileLock: '{}' is already locked", lock_path.string()), EAGAIN)};
}
return FileLock{std::move(**res)};
}
@@ -55,10 +100,78 @@ FileLock::acquire(const std::filesystem::path &lock_path, LockMode mode, bool no
return std::unexpected{std::move(res.error())};
}
return FileLock{std::move(*res)};
#endif
}
Void::Result::Result<FileMetadata, Void::Result::Error>
stat_lstat(const std::filesystem::path &path) {
#if defined(_WIN32)
std::error_code ec;
const auto status = std::filesystem::symlink_status(path, ec);
if (ec) {
if (ec == std::errc::no_such_file_or_directory || ec == std::errc::not_a_directory) {
FileMetadata missing;
return missing;
}
return std::unexpected{sys_err(
ec.value(), std::format("stat_lstat: symlink_status failed for '{}': {}",
path.string(), ec.message()))};
}
if (!std::filesystem::exists(status)) {
FileMetadata missing;
return missing;
}
FileMetadata meta;
meta.exists = true;
meta.is_regular = std::filesystem::is_regular_file(status);
meta.is_directory = std::filesystem::is_directory(status);
meta.is_symlink = std::filesystem::is_symlink(status);
if (meta.is_symlink) {
std::error_code target_ec;
const auto target = std::filesystem::read_symlink(path, target_ec);
if (!target_ec) {
meta.symlink_target = target.string();
}
}
const auto followed = std::filesystem::status(path, ec);
if (!ec) {
if (std::filesystem::is_regular_file(followed)) {
const auto size = std::filesystem::file_size(path, ec);
if (!ec) {
meta.size = static_cast<std::uint64_t>(size);
}
ec.clear();
}
const auto mtime = std::filesystem::last_write_time(path, ec);
if (!ec) {
const auto sys = std::chrono::file_clock::to_sys(mtime);
const auto secs = std::chrono::floor<std::chrono::seconds>(sys);
meta.mtime_sec = static_cast<std::int64_t>(secs.time_since_epoch().count());
meta.mtime_nsec = static_cast<std::int64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(sys - secs).count());
}
}
// Identity through a Win32 handle (volume serial, file index, link count).
const HANDLE handle = ::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
nullptr);
if (handle != INVALID_HANDLE_VALUE) {
BY_HANDLE_FILE_INFORMATION info{};
if (::GetFileInformationByHandle(handle, &info) != 0) {
meta.dev = info.dwVolumeSerialNumber;
meta.ino = (static_cast<std::uint64_t>(info.nFileIndexHigh) << 32) |
static_cast<std::uint64_t>(info.nFileIndexLow);
meta.nlink = info.nNumberOfLinks;
}
::CloseHandle(handle);
}
meta.mode = meta.is_directory ? 0755u : 0644u;
return meta;
#else
struct stat st{};
if (::lstat(path.c_str(), &st) != 0) {
const int err = errno;
@@ -104,6 +217,7 @@ stat_lstat(const std::filesystem::path &path) {
}
}
return meta;
#endif
}
Void::Result::Result<bool, Void::Result::Error>
@@ -125,17 +239,47 @@ copy_isolated(const std::filesystem::path &src, const std::filesystem::path &dst
auto res = Void::FileSystem::reflink_copy_file(src, dst, opts);
if (!res) {
#if defined(_WIN32)
// No reflink support on this filesystem/host: fall back to a plain copy.
std::filesystem::copy_file(src, dst, std::filesystem::copy_options::overwrite_existing,
ec);
if (ec) {
return std::unexpected{sys_err(
ec.value(), std::format("copy_isolated: copy_file failed for '{}': {}",
dst.string(), ec.message()))};
}
return false;
#else
return std::unexpected{std::move(res.error())};
#endif
}
#if defined(_WIN32)
(void)mode_override;
#else
if (mode_override) {
(void)::chmod(dst.c_str(), static_cast<mode_t>(*mode_override));
}
#endif
return res->method == Void::FileSystem::CopyMethod::Reflink;
}
Void::Result::Result<void, Void::Result::Error>
set_canonical_mtime(const std::filesystem::path &path, std::int64_t epoch_seconds) {
#if defined(_WIN32)
// Void::FileSystem::set_canonical_mtime is POSIX-only (Void/Library issue #66).
std::error_code ec;
const auto stamp = std::chrono::file_clock::from_sys(
std::chrono::system_clock::time_point{std::chrono::seconds{epoch_seconds}});
std::filesystem::last_write_time(path, stamp, ec);
if (ec) {
return std::unexpected{
sys_err(ec.value(), std::format("set_canonical_mtime: failed for '{}': {}",
path.string(), ec.message()))};
}
return {};
#else
return Void::FileSystem::set_canonical_mtime(path, epoch_seconds, 0);
#endif
}
Void::Result::Result<void, Void::Result::Error>
@@ -172,6 +316,11 @@ Void::Result::Result<void, Void::Result::Error> atomic_write_file(const std::fil
Void::Result::Result<void, Void::Result::Error>
fsync_directory(const std::filesystem::path &dir_path) {
#if defined(_WIN32)
// Windows has no directory fsync; MoveFileEx visibility is the durability guarantee.
(void)dir_path;
return {};
#else
const int fd = ::open(dir_path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (fd < 0) {
const int err = errno;
@@ -193,6 +342,7 @@ fsync_directory(const std::filesystem::path &dir_path) {
return std::unexpected{
sys_err(err, std::format("fsync_directory: fsync failed for '{}'", dir_path.string()))};
}
#endif
}
Void::Result::Result<void, Void::Result::Error>
@@ -206,8 +356,27 @@ atomic_swap_symlink(const std::filesystem::path &link_path, const std::filesyste
ec.value(), std::format("atomic_swap_symlink: create_directories failed for '{}'",
parent.string()))};
}
#if defined(_WIN32)
// Void::FileSystem::atomic_symlink_swap is POSIX-only (Void/Library issue #66).
// Windows symlink creation needs privileges, so the alias becomes a regular
// file copy of the target: consumers read the same content at link_path.
std::error_code target_ec;
if (!std::filesystem::is_regular_file(target, target_ec)) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::unsupported,
std::format("atomic_swap_symlink: cannot alias '{}' to '{}' on Windows",
link_path.string(), target.string()))};
}
const auto bytes = Void::FileSystem::read_file(target);
if (!bytes) {
return std::unexpected{std::move(bytes.error())};
}
return atomic_write_bytes(link_path, std::as_bytes(std::span<const char>{*bytes}),
/*durable_sync=*/true);
#else
return Void::FileSystem::atomic_symlink_swap(link_path, target,
Void::FileSystem::ReplaceDurability::durable_sync);
#endif
}
bool path_is_within(const std::filesystem::path &root, const std::filesystem::path &path) {
@@ -316,6 +485,19 @@ resolve_confined_path(const std::filesystem::path &root, const std::filesystem::
}
Void::Result::Result<std::filesystem::path, Void::Result::Error> current_executable_path() {
#if defined(_WIN32)
std::wstring buffer(32768, L'\0');
const DWORD length =
::GetModuleFileNameW(nullptr, buffer.data(), static_cast<DWORD>(buffer.size()));
if (length == 0 || length >= buffer.size()) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::io_error,
std::format("current_executable_path: GetModuleFileNameW failed ({})",
::GetLastError()))};
}
buffer.resize(length);
return std::filesystem::path{buffer};
#else
std::error_code ec;
const auto path = std::filesystem::read_symlink("/proc/self/exe", ec);
if (ec || path.empty()) {
@@ -326,6 +508,7 @@ Void::Result::Result<std::filesystem::path, Void::Result::Error> current_executa
ec.value())};
}
return path;
#endif
}
} // namespace Void::Build::Platform
+72 -16
View File
@@ -4,32 +4,77 @@
#include <Void/System/Process.hpp>
#include <Void/System/Types.hpp>
#include <algorithm>
#include <chrono>
#include <mutex>
#include <thread>
#if defined(_WIN32)
#include <cwctype>
#else
#include <sys/stat.h>
#include <sys/wait.h>
#include <thread>
#include <unistd.h>
#endif
#if !defined(__linux__)
#if !defined(__linux__) && !defined(_WIN32)
#error \
"VoidBuildSystem's process and file backends currently support Linux hosts only (Track C2/C3 ports are planned)"
"VoidBuildSystem's process and file backends currently support Linux and Windows hosts only (Track C2/C3 ports are planned)"
#endif
namespace Void::Build::Platform {
namespace {
#if defined(_WIN32)
constexpr char kPathSeparator = ';';
#else
constexpr char kPathSeparator = ':';
#endif
bool is_executable_file(const std::filesystem::path &p) {
#if defined(_WIN32)
std::error_code ec;
if (!std::filesystem::is_regular_file(p, ec)) {
return false;
}
std::string ext = p.extension().string();
std::ranges::transform(ext, ext.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return ext.empty() || ext == ".exe" || ext == ".com" || ext == ".bat" || ext == ".cmd";
#else
struct stat st{};
if (::stat(p.c_str(), &st) != 0) {
return false;
}
return S_ISREG(st.st_mode) && ::access(p.c_str(), X_OK) == 0;
#endif
}
std::optional<std::filesystem::path> resolve_candidate(const std::filesystem::path &candidate) {
std::vector<std::filesystem::path> names{candidate};
#if defined(_WIN32)
if (!candidate.has_extension()) {
for (const char *ext : {".exe", ".cmd", ".bat", ".com"}) {
names.push_back(candidate.string() + ext);
}
}
#endif
for (const auto &name : names) {
if (is_executable_file(name)) {
std::error_code ec;
auto abs = std::filesystem::absolute(name, ec);
return ec ? name : abs.lexically_normal();
}
}
return std::nullopt;
}
void ensure_subreaper() noexcept {
#if !defined(_WIN32)
static std::once_flag once;
std::call_once(once, [] { (void)Void::Process::enable_subreaper(); });
#endif
}
} // namespace
@@ -40,11 +85,14 @@ resolve_executable(const std::filesystem::path &executable,
if (executable.empty()) {
return std::nullopt;
}
if (executable.is_absolute() || executable.string().find('/') != std::string::npos) {
if (executable.is_absolute() ||
executable.string().find_first_of(std::string_view{"/\\"}) != std::string::npos) {
std::error_code ec;
const auto abs = std::filesystem::absolute(executable, ec);
if (!ec && is_executable_file(abs)) {
return abs.lexically_normal();
if (!ec) {
if (auto resolved = resolve_candidate(abs); resolved) {
return resolved;
}
}
return std::nullopt;
}
@@ -58,21 +106,23 @@ resolve_executable(const std::filesystem::path &executable,
}
std::size_t start = 0;
while (start <= path_env.size()) {
const auto colon = path_env.find(':', start);
const auto segment = path_env.substr(
start, colon == std::string_view::npos ? std::string_view::npos : colon - start);
const auto separator = path_env.find(kPathSeparator, start);
auto segment = path_env.substr(
start, separator == std::string_view::npos ? std::string_view::npos : separator - start);
// Windows PATH entries may be quoted.
if (segment.size() >= 2 && segment.front() == '"' && segment.back() == '"') {
segment.remove_prefix(1);
segment.remove_suffix(1);
}
const std::filesystem::path dir =
segment.empty() ? std::filesystem::path{"."} : std::filesystem::path{segment};
const auto candidate = dir / executable;
if (is_executable_file(candidate)) {
std::error_code ec;
auto abs = std::filesystem::absolute(candidate, ec);
return ec ? candidate : abs.lexically_normal();
if (auto resolved = resolve_candidate(dir / executable); resolved) {
return resolved;
}
if (colon == std::string_view::npos) {
if (separator == std::string_view::npos) {
break;
}
start = colon + 1;
start = separator + 1;
}
return std::nullopt;
}
@@ -159,15 +209,19 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
bool group_timed_out = comm->timed_out;
bool group_cancelled = comm->cancelled;
bool descendants_terminated = false;
#if !defined(_WIN32)
const pid_t pgid = static_cast<pid_t>(child->pgid());
#endif
if (!group_timed_out && !group_cancelled && !comm->overflowed) {
const auto descendant_deadline =
std::chrono::steady_clock::now() + request.descendant_grace;
while (child->process_group_alive()) {
#if !defined(_WIN32)
// Reap any adopted descendants in this process group (subreaper) so zombies clear.
int wstatus = 0;
while (pgid > 0 && ::waitpid(-pgid, &wstatus, WNOHANG) > 0) {
}
#endif
if (!child->process_group_alive()) {
break;
}
@@ -192,6 +246,7 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
if (group_cancelled || group_timed_out || descendants_terminated || comm->overflowed ||
child->process_group_alive()) {
(void)child->terminate(request.kill_grace);
#if !defined(_WIN32)
// Reap the whole group until it is really gone (bounded), so no zombie or orphan is
// left behind after test supervision.
const auto reap_deadline =
@@ -210,6 +265,7 @@ run_supervised(const ProcessRequest &request, std::stop_token stop) {
continue;
}
}
#endif
}
ProcessResult result;
+4
View File
@@ -18,7 +18,11 @@ using Util::json_quote;
std::string iso8601(std::int64_t epoch) {
const auto time = static_cast<std::time_t>(epoch);
std::tm tm{};
#if defined(_WIN32)
::gmtime_s(&tm, &time);
#else
::gmtime_r(&time, &tm);
#endif
char buffer[32];
(void)std::strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", &tm);
return buffer;
+57
View File
@@ -1,5 +1,6 @@
#include <Void/Build/Report/Cdash.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Core/Scope.hpp>
#include <Void/System/Types.hpp>
#include <Void/Text/Str.hpp>
@@ -11,9 +12,13 @@
#include <cstdio>
#include <ctime>
#include <format>
#if defined(_WIN32)
#include <windows.h>
#else
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#if defined(VBS_HAS_VOID_NET)
#include <Void/Net/Http.hpp>
@@ -61,17 +66,30 @@ std::string utc_timestamp() {
const auto now = std::chrono::system_clock::now();
const std::time_t seconds = std::chrono::system_clock::to_time_t(now);
std::tm tm{};
#if defined(_WIN32)
::gmtime_s(&tm, &seconds);
#else
::gmtime_r(&seconds, &tm);
#endif
return std::format("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}", tm.tm_year + 1900,
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}
std::string host_name() {
#if defined(_WIN32)
char buffer[256]{};
DWORD size = static_cast<DWORD>(sizeof(buffer) - 1);
if (::GetComputerNameA(buffer, &size) != 0) {
return buffer;
}
return "localhost";
#else
char buffer[256]{};
if (::gethostname(buffer, sizeof(buffer) - 1) == 0) {
return buffer;
}
return "localhost";
#endif
}
} // namespace
@@ -186,6 +204,44 @@ submit_cdash_report(std::string_view cdash_url, std::string_view project,
response->body.substr(0, 200)))};
}
return {};
#else
#if defined(_WIN32)
// Windows: curl performs the submission for http and https (Void::Net not linked).
auto curl = Platform::resolve_executable("curl");
if (!curl) {
return std::unexpected{make_error(
"CDash submission on Windows requires curl (Void::Net not linked)")};
}
Platform::ProcessRequest req;
req.executable = *curl;
req.arguments = {"--silent",
"--show-error",
"-X",
"POST",
"-H",
"Content-Type: " + submission.content_type,
"--data-binary",
"@-",
"-w",
"\n%{http_code}",
std::format("{}://{}:{}{}", scheme, host, port, path)};
req.stdin_data = submission.body;
req.timeout = std::chrono::seconds{60};
auto proc = Platform::run_supervised(req);
if (!proc || !proc->succeeded()) {
return std::unexpected{make_error(std::format(
"CDash submission failed: {}",
proc ? proc->stderr_data : proc.error().message()))};
}
int status = 0;
if (const auto nl = proc->stdout_data.rfind('\n'); nl != std::string::npos) {
(void)Void::Str::to_int(Void::Str::trim_ascii(proc->stdout_data.substr(nl + 1)), status);
}
if (status < 200 || status >= 300) {
return std::unexpected{
make_error(std::format("CDash submission rejected with HTTP {}", status))};
}
return {};
#else
// Plain TCP HTTP/1.1 POST for http:// (Void::Net server transport not linked).
if (scheme != "http") {
@@ -252,6 +308,7 @@ submit_cdash_report(std::string_view cdash_url, std::string_view project,
}
return {};
#endif
#endif
}
} // namespace Void::Build::Report
+22
View File
@@ -76,6 +76,27 @@ bool path_has_excluded_component(const std::filesystem::path &rel_path,
Void::Result::Result<std::vector<std::string>, Void::Result::Error>
read_sorted_dir_entries(const std::filesystem::path &dir_path,
const std::vector<std::string> &excluded) {
#if defined(_WIN32)
std::error_code ec;
std::vector<std::string> names;
for (std::filesystem::directory_iterator it{dir_path, ec}, end; !ec && it != end;
it.increment(ec)) {
const auto name = it->path().filename().string();
if (is_excluded_name(name, excluded)) {
continue;
}
names.push_back(name);
}
if (ec) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("snapshot: cannot read directory '{}': {}", dir_path.string(),
ec.message()),
ec.value())};
}
std::ranges::sort(names);
return names;
#else
const int fd = ::open(dir_path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if (fd < 0) {
const int err = errno;
@@ -112,6 +133,7 @@ read_sorted_dir_entries(const std::filesystem::path &dir_path,
}
std::ranges::sort(names);
return names;
#endif
}
std::string normalize_logical(const std::filesystem::path &rel) {
+10 -4
View File
@@ -15,9 +15,11 @@
#include <chrono>
#include <format>
#include <map>
#if !defined(_WIN32)
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
namespace Void::Build::State {
namespace {
@@ -87,6 +89,7 @@ struct HttpReply {
std::string body;
};
#if !defined(_WIN32)
bool send_all(int fd, std::string_view data) {
std::size_t off = 0;
while (off < data.size()) {
@@ -101,6 +104,7 @@ bool send_all(int fd, std::string_view data) {
}
return true;
}
#endif
Void::Result::Result<HttpReply, Void::Result::Error>
http_exchange(const ParsedUrl &parsed, std::string_view method, std::string_view path,
@@ -139,6 +143,7 @@ http_exchange(const ParsedUrl &parsed, std::string_view method, std::string_view
}
return HttpReply{response->status, std::move(response->body)};
#else
#if !defined(_WIN32)
if (parsed.scheme == "http") {
struct addrinfo hints{};
hints.ai_family = AF_INET;
@@ -215,19 +220,20 @@ http_exchange(const ParsedUrl &parsed, std::string_view method, std::string_view
reply.body = raw.substr(hdr_end + 4);
return reply;
}
#endif
// HTTPS via curl preserves TLS certificate verification (never disables TLS).
// http/https via curl preserve TLS certificate verification (never disable TLS).
auto curl = Platform::resolve_executable("curl");
if (!curl) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::not_found,
"HTTPS remote cache requires curl (Void::Net not linked)")};
"remote cache requires curl (Void::Net not linked)")};
}
const std::string full_url =
std::format("https://{}:{}{}", parsed.host, parsed.port, full_path);
std::format("{}://{}:{}{}", parsed.scheme, parsed.host, parsed.port, full_path);
Platform::ProcessRequest req;
req.executable = *curl;
req.arguments = {"--silent", "--show-error", "--proto", "=https",
req.arguments = {"--silent", "--show-error", "--proto", "=" + parsed.scheme,
"-X", std::string{method}, "-w", "\n%{http_code}"};
for (const auto &[k, v] : headers) {
req.arguments.push_back("-H");
+49 -5
View File
@@ -18,6 +18,10 @@
#include <unistd.h>
#include <utility>
#if defined(_WIN32)
#include <windows.h>
#endif
namespace Void::Build::State {
namespace {
@@ -39,10 +43,39 @@ bool pid_is_alive(pid_t pid) noexcept {
if (pid <= 0) {
return false;
}
#if defined(_WIN32)
const HANDLE handle =
::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, static_cast<DWORD>(pid));
if (handle == nullptr) {
return false;
}
DWORD exit_code = 0;
const bool alive = ::GetExitCodeProcess(handle, &exit_code) != 0 && exit_code == STILL_ACTIVE;
::CloseHandle(handle);
return alive;
#else
if (::kill(pid, 0) == 0) {
return true;
}
return errno != ESRCH;
#endif
}
void apply_posix_mode(const std::filesystem::path &p, unsigned mode) noexcept {
#if defined(_WIN32)
using Perms = std::filesystem::perms;
Perms perms = Perms::owner_read | Perms::group_read | Perms::others_read;
if ((mode & 0200u) != 0) {
perms |= Perms::owner_write;
}
if ((mode & 0100u) != 0) {
perms |= Perms::owner_exec;
}
std::error_code ec;
std::filesystem::permissions(p, perms, std::filesystem::perm_options::replace, ec);
#else
(void)::chmod(p.c_str(), static_cast<mode_t>(mode));
#endif
}
std::string serialize_action(const ActionSuccessRecord &rec) {
@@ -155,6 +188,16 @@ struct StateStore::CacheState {
};
static std::optional<StatFingerprint> stat_file(const std::filesystem::path &p) noexcept {
#if defined(_WIN32)
struct _stat64 st{};
if (::_wstat64(p.c_str(), &st) != 0) {
return std::nullopt;
}
return StatFingerprint{static_cast<std::uint64_t>(st.st_dev),
static_cast<std::uint64_t>(st.st_ino),
static_cast<std::uint64_t>(st.st_size),
static_cast<std::int64_t>(st.st_mtime), 0};
#else
struct stat st{};
if (::stat(p.c_str(), &st) != 0) {
return std::nullopt;
@@ -163,6 +206,7 @@ struct StateStore::CacheState {
static_cast<std::uint64_t>(st.st_dev), static_cast<std::uint64_t>(st.st_ino),
static_cast<std::uint64_t>(st.st_size), static_cast<std::int64_t>(st.st_mtim.tv_sec),
static_cast<std::int64_t>(st.st_mtim.tv_nsec)};
#endif
}
std::mutex mutex;
@@ -703,12 +747,12 @@ StateStore::store_blob_from_file(const std::filesystem::path &file_path) {
if (existing_ok && *existing_ok) {
std::filesystem::remove(stage_path, ec);
} else {
(void)::chmod(final_path.c_str(), 0644);
apply_posix_mode(final_path, 0644);
std::filesystem::rename(stage_path, final_path, ec);
(void)::chmod(final_path.c_str(), 0444);
apply_posix_mode(final_path, 0444);
}
} else {
(void)::chmod(stage_path.c_str(), 0444);
apply_posix_mode(stage_path, 0444);
std::filesystem::rename(stage_path, final_path, ec);
if (ec) {
std::filesystem::remove(stage_path, ec);
@@ -848,7 +892,7 @@ StateStore::ensure_remote_blob(std::string_view sha256) {
if (!wrote) {
return std::unexpected{wrote.error()};
}
(void)::chmod(stage_path.c_str(), 0444);
apply_posix_mode(stage_path, 0444);
std::filesystem::rename(stage_path, final_path, ec);
if (ec) {
std::filesystem::remove(stage_path, ec);
@@ -1141,7 +1185,7 @@ Void::Result::Result<GcStats, Void::Result::Error> StateStore::gc(std::uint64_t
const std::string sha = entry.path().filename().string();
const auto fsize = entry.file_size(ec);
if (!pinned.contains(sha)) {
(void)::chmod(entry.path().c_str(), 0644);
apply_posix_mode(entry.path(), 0644);
std::filesystem::remove(entry.path(), ec);
if (!ec) {
++stats.removed_blobs;
+14
View File
@@ -14,7 +14,9 @@
#include <algorithm>
#include <cstdlib>
#include <format>
#if !defined(_WIN32)
#include <sys/utsname.h>
#endif
namespace Void::Build::Toolchain {
namespace {
@@ -260,19 +262,31 @@ void attach_shader_tools(ToolchainCapabilities &cap) {
} // namespace
std::string host_os_name() {
#if defined(_WIN32)
return "Windows";
#elif defined(__APPLE__)
return "macOS";
#else
struct utsname u{};
if (::uname(&u) == 0) {
return std::string{u.sysname};
}
return "Linux";
#endif
}
std::string host_architecture_name() {
#if defined(__aarch64__) || defined(_M_ARM64)
return "aarch64";
#elif defined(_WIN32)
return "x86_64";
#else
struct utsname u{};
if (::uname(&u) == 0) {
return std::string{u.machine};
}
return "x86_64";
#endif
}
namespace {
+4 -2
View File
@@ -7,9 +7,11 @@
#include <format>
#include <set>
#if !defined(__linux__)
// The watcher delegates to Void::FileSystem::DirectoryWatcher, which has Linux
// (inotify) and Windows backends.
#if !defined(__linux__) && !defined(_WIN32)
#error \
"VoidBuildSystem's inotify watcher currently supports Linux hosts only (Track C2/C3 ports are planned)"
"VoidBuildSystem's watcher currently supports Linux and Windows hosts only (Track C2/C3 ports are planned)"
#endif
namespace Void::Build::Watch {