feat(toolchain): cross-compile Windows targets with MinGW and run tests under Wine
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 9s

This commit is contained in:
faumaray committed 2026-12-05 04:47:18 +03:00
1 parent 70483492aa
commit a808596462
8 files changed
+157 -31

No files matched your search

+10 -4
View File
@@ -8,6 +8,7 @@
#include <Void/Data/StrictJson.hpp>
#include <Void/System/Path.hpp>
#include <Void/System/Types.hpp>
#include <Void/Text/Str.hpp>
#include <algorithm>
#include <format>
@@ -488,9 +489,9 @@ expand_glob(const std::filesystem::path &project_root, std::string_view 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("..")) {
return std::unexpected{make_error(
std::format("expand_glob: pattern '{}' escapes project root '{}'", pattern,
canonical_root.string()))};
return std::unexpected{
make_error(std::format("expand_glob: pattern '{}' escapes project root '{}'",
pattern, canonical_root.string()))};
}
effective_pattern = rel_pattern.lexically_normal().generic_string();
}
@@ -2024,8 +2025,13 @@ lower_project_graph(const ProjectDescription &description,
graph.actions.push_back(std::move(act));
} else if (t.kind == TargetKind::Executable || t.kind == TargetKind::SharedLibrary ||
t.kind == TargetKind::Test) {
// Windows targets use PE conventions (.exe executables, .dll shared libraries).
const bool windows_target =
Void::Str::to_lower_ascii(description.profile.os) == "windows";
const auto out_name =
(t.kind == TargetKind::SharedLibrary) ? ("lib" + t.name + ".so") : t.name;
(t.kind == TargetKind::SharedLibrary)
? (windows_target ? (t.name + ".dll") : ("lib" + t.name + ".so"))
: (windows_target ? (t.name + ".exe") : t.name);
const auto bin_path =
(t.kind == TargetKind::SharedLibrary ? artifacts_root : (artifacts_root / "bin")) /
out_name;
+32 -7
View File
@@ -39,13 +39,13 @@
#include <Void/Log/Formatter.hpp>
#include <Void/Log/Log.hpp>
#include <Void/Log/LoggingAdapter.hpp>
#include <unistd.h>
#include <Void/System/SignalWatcher.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Text/Semver.hpp>
#include <Void/Text/Str.hpp>
#include <Void/Text/Url.hpp>
#include <Void/Time/Stopwatch.hpp>
#include <unistd.h>
#include <algorithm>
#include <array>
@@ -136,7 +136,8 @@ class ConsoleLogGuard {
}
logger_ = std::make_unique<Void::Logging::ConsoleLogger>();
if (color_enabled()) {
auto formatter = std::make_shared<Void::Logging::PatternFormatter>("[{level:,auto}] {message}");
auto formatter =
std::make_shared<Void::Logging::PatternFormatter>("[{level:,auto}] {message}");
formatter->set_color_policy(Void::Logging::ColorPolicy::defaults());
logger_->set_formatter(std::move(formatter));
}
@@ -373,6 +374,8 @@ struct BuildCmdOptions {
std::optional<std::filesystem::path> state_dir;
std::vector<std::string> trusted_public_keys;
std::vector<std::string> trusted_key_files;
std::optional<std::string> target_os_arg;
std::optional<std::string> target_arch_arg;
bool publish_editor_selection{true};
bool no_cache{false};
bool locked{false};
@@ -491,13 +494,19 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
return 1;
}
const std::string target_os = opts.target_os_arg.value_or(Toolchain::host_os_name());
const std::string target_arch =
opts.target_arch_arg.value_or(Toolchain::host_architecture_name());
const bool windows_cross_target =
Void::Str::to_lower_ascii(target_os) == "windows" &&
Void::Str::to_lower_ascii(Toolchain::host_os_name()) != "windows";
bool all_ok = true;
for (const auto &prof_name : opts.profiles) {
const auto prof_sw = Void::Time::Stopwatch::started();
ProfileContext ctx;
try {
ctx = profs->resolve(prof_name, compiler_override, Toolchain::host_os_name(),
Toolchain::host_architecture_name());
ctx = profs->resolve(prof_name, compiler_override, target_os, target_arch);
} catch (const std::exception &ex) {
std::cerr << "vbs: " << ex.what() << '\n';
return 2;
@@ -810,7 +819,19 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
Void::Log::info("Test", "[{}] Running test target '{}'...", prof_name, t.name);
const auto tsw = Void::Time::Stopwatch::started();
Platform::ProcessRequest treq;
treq.executable = t.primary_outputs.front();
if (windows_cross_target) {
// Cross-built Windows test binaries execute under Wine (Track C3 Wine-first).
auto wine = Platform::resolve_executable("wine");
if (!wine) {
std::cerr << "vbs test: Windows target tests require 'wine' in PATH\n";
all_ok = false;
continue;
}
treq.executable = *wine;
treq.arguments = {t.primary_outputs.front().string()};
} else {
treq.executable = t.primary_outputs.front();
}
treq.working_directory = project_root;
treq.timeout = std::chrono::seconds{300};
auto tres = Platform::run_supervised(treq);
@@ -1703,8 +1724,8 @@ int execute_install_command(const InstallCmdOptions &opts) {
iopts.export_native_metadata = !opts.no_native_export;
iopts.bundle_runtime_dependencies = opts.bundle_dependencies;
if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh") {
std::cerr << "vbs install: unsupported --archive-format '"
<< opts.archive_format_arg << "' (expected tar or sh)\n";
std::cerr << "vbs install: unsupported --archive-format '" << opts.archive_format_arg
<< "' (expected tar or sh)\n";
return 2;
}
if (opts.archive_arg && !opts.archive_arg->empty()) {
@@ -2729,6 +2750,10 @@ int main(int argc, char **argv) {
.option_many("--target", "-t", "Target to build/test", build_opts.targets)
.option("--compiler", "", "Override compiler family (gcc|clang)",
build_opts.compiler_arg)
.option("--target-os", "", "Target operating system (default: host, e.g. windows)",
build_opts.target_os_arg)
.option("--target-arch", "", "Target architecture (default: host, e.g. x86_64)",
build_opts.target_arch_arg)
.option("--editor-profile", "", "Editor profile for compile_commands.json",
build_opts.editor_profile)
.option_many("--build-source", "", "Additional build description source",
+29 -2
View File
@@ -260,12 +260,32 @@ std::string host_architecture_name() {
return "x86_64";
}
namespace {
// Cross toolchain prefix for a non-host target (Track C: Windows via MinGW-w64 under Wine).
std::string cross_compiler_prefix(const ProfileContext &context) {
const std::string target_os = Void::Str::to_lower_ascii(context.os);
if (target_os != "windows" || Void::Str::to_lower_ascii(host_os_name()) == "windows") {
return {};
}
if (context.architecture == "aarch64" || context.architecture == "arm64") {
return "aarch64-w64-mingw32-";
}
return "x86_64-w64-mingw32-";
}
} // namespace
Void::Result::Result<ToolchainCapabilities, Void::Result::Error>
discover_and_probe(const ProfileContext &context,
const std::optional<std::filesystem::path> &cache_dir) {
const std::string cross_prefix = cross_compiler_prefix(context);
std::filesystem::path requested_compiler;
if (!context.compiler_path.empty()) {
requested_compiler = context.compiler_path;
} else if (!cross_prefix.empty()) {
requested_compiler =
cross_prefix + (context.compiler == CompilerFamily::Gcc ? "g++" : "clang++");
} else if (context.compiler == CompilerFamily::Gcc) {
requested_compiler = "g++";
} else {
@@ -280,7 +300,11 @@ discover_and_probe(const ProfileContext &context,
}
std::filesystem::path requested_c_compiler =
context.compiler == CompilerFamily::Gcc ? "gcc" : "clang";
!cross_prefix.empty()
? std::filesystem::path{cross_prefix +
(context.compiler == CompilerFamily::Gcc ? "gcc" : "clang")}
: (context.compiler == CompilerFamily::Gcc ? std::filesystem::path{"gcc"}
: std::filesystem::path{"clang"});
if (!context.compiler_path.empty()) {
const std::filesystem::path cp_path{context.compiler_path};
const std::string fname = cp_path.filename().string();
@@ -307,7 +331,10 @@ discover_and_probe(const ProfileContext &context,
}
std::optional<std::filesystem::path> resolved_ar;
if (context.compiler == CompilerFamily::Clang) {
if (!cross_prefix.empty()) {
resolved_ar = Platform::resolve_executable(cross_prefix + "ar");
}
if (!resolved_ar && context.compiler == CompilerFamily::Clang) {
resolved_ar = Platform::resolve_executable("llvm-ar");
}
if (!resolved_ar) {