diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 2196795..9acf59e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -247,8 +247,10 @@ jobs: out=dist-installers prefix="$(mktemp -d)" mkdir -p "${out}" - # The first install builds the project with VBS (build.cpp); the rest reuse - # the shared build directory. + # Concurrent runs on the same runner share the repository workspace, so the + # self-hosted build directory is unique per run. The first install builds the + # project with VBS (build.cpp); the rest reuse it. + build_dir="build/selfhost-${GITHUB_RUN_ID}" for fmt in tar sh zip deb rpm wix dmg nuget; do case "${fmt}" in tar) ext=tar ;; @@ -256,7 +258,7 @@ jobs: nuget) ext=nupkg ;; *) ext="${fmt}" ;; esac - "${vbs}" install --project . --build-dir build/selfhost --profile release \ + "${vbs}" install --project . --build-dir "${build_dir}" --profile release \ --prefix "${prefix}" --package-name VoidBuildSystem \ --package-version "${version}" \ --archive "${out}/vbs-${label}-linux-x86_64-${fmt}.${ext}" \ diff --git a/build.cpp b/build.cpp index dac3768..45e0a7b 100644 --- a/build.cpp +++ b/build.cpp @@ -1,5 +1,22 @@ #include "build-support/Defaults.hpp" +#include +#include +#include + +namespace { + +// The profile context carries the target OS as written on the command line +// ("windows") or as the host name ("Windows"): compare case-insensitively. +bool targets_windows(const Void::Build::ProfileContext &ctx) { + std::string os = ctx.os; + std::ranges::transform(os, os.begin(), + [](unsigned char c) { return static_cast(std::tolower(c)); }); + return os == "windows"; +} + +} // namespace + void build(Void::Build::Project &project) { const auto &ctx = project.context(); @@ -48,7 +65,7 @@ void build(Void::Build::Project &project) { .link(library.target("Void::Crypto"), Void::Build::Visibility::Public) .link(library.target("Void::Archive"), Void::Build::Visibility::Public) .link(library.target("Void::Log"), Void::Build::Visibility::Public); - if (ctx.os == "Windows") { + if (targets_windows(ctx)) { // Winsock for the registry client and the native Windows HTTP fallbacks. core.link_option("-lws2_32"); } @@ -92,7 +109,7 @@ void build(Void::Build::Project &project) { BuildSupport::compiler_warnings(cli, ctx); // The registry service is POSIX-only until its Track C3 Windows port lands. - if (ctx.os != "Windows") { + if (!targets_windows(ctx)) { auto registry_lib = project.static_library("VoidBuildRegistry"); registry_lib.cxx_standard(Void::Build::CxxStandard::Cxx26) .sources(project.glob("registry/service/*.cpp")) diff --git a/src/Main.cpp b/src/Main.cpp index ea50a3e..2228f8d 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2552,6 +2552,8 @@ struct InstallCmdOptions { std::optional build_arg; std::string profile_name{"debug"}; std::optional compiler_arg; + std::optional target_os_arg; + std::optional target_arch_arg; std::optional prefix_arg; std::optional pkg_name_arg; std::string pkg_ver{"0.1.0"}; @@ -2636,8 +2638,9 @@ int execute_install_command(const InstallCmdOptions &opts) { } ProfileContext ctx; try { - ctx = profs->resolve(opts.profile_name, compiler_override, Toolchain::host_os_name(), - Toolchain::host_architecture_name()); + ctx = profs->resolve(opts.profile_name, compiler_override, + opts.target_os_arg.value_or(Toolchain::host_os_name()), + opts.target_arch_arg.value_or(Toolchain::host_architecture_name())); } catch (const std::exception &ex) { std::cerr << "vbs install: " << ex.what() << '\n'; return 2; @@ -2757,7 +2760,16 @@ int execute_install_command(const InstallCmdOptions &opts) { std::cerr << "vbs install: " << graph.error().message() << '\n'; return 1; } - auto exec = Execution::execute_graph(*graph, *state); + // Only the targets that are actually installed (plus their dependencies) + // need to be built: test executables and tools without install rules are + // not part of the package. + Execution::ExecutionOptions eopts; + for (const auto &target : desc->targets) { + if (target.install_rule) { + eopts.selected_targets.push_back(target.name); + } + } + auto exec = Execution::execute_graph(*graph, *state, eopts); if (!exec || !exec->succeeded) { std::cerr << "vbs install: build failed before staging\n"; if (!exec) { @@ -3890,6 +3902,10 @@ int main(int argc, char **argv) { .option("--build-dir", "-B", "Build output directory", install_opts.build_arg) .option_default("--profile", "-p", "Profile name", install_opts.profile_name, "debug") .option("--compiler", "", "Override compiler family (gcc|clang)", install_opts.compiler_arg) + .option("--target-os", "", "Target operating system (default: host, e.g. windows)", + install_opts.target_os_arg) + .option("--target-arch", "", "Target architecture (default: host, e.g. x86_64)", + install_opts.target_arch_arg) .option("--prefix", "", "Install destination prefix (required)", install_opts.prefix_arg) .option("--package-name", "", "Exported package name", install_opts.pkg_name_arg) .option_default("--package-version", "", "Exported package version", install_opts.pkg_ver,