From 5a63dd81b85bdb7bc9a6372a297b65fa1de08fd7 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Sun, 1 Nov 2026 18:47:01 +0100 Subject: [PATCH] refactor: route an executable's outputs through ProgramDir() Build() put an executable and the files it reads at run time (its shaders, cfg.files, assets, and what its dependencies forward to it) in BinDir() directly, and ExpectedOutput(), -r and the wasm variant copies each spelled the same directory again. A Flatpak keeps its program in files/bin of the build directory instead, so those places now ask Configuration::ProgramDir(), which for every configuration is still its bin dir. Nothing moves yet. --- AGENTS.template.md | 2 +- implementations/Crafter.Build-Clang.cpp | 14 ++++++++------ interfaces/Crafter.Build-Clang.cppm | 6 ++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/AGENTS.template.md b/AGENTS.template.md index f275a93..3fe95de 100644 --- a/AGENTS.template.md +++ b/AGENTS.template.md @@ -118,7 +118,7 @@ Beyond the rules: - Comments explain why: the failure mode, the constraint, the rejected alternative. The codebase carries long comments on purpose. Do not strip them, and write them for new non-obvious code. Commit bodies follow the same rule. - There is no host-platform preprocessor split: the host is Linux. Target differences (mingw, wasm) branch on `cfg.target` strings at runtime, in the library as well as in `project.cpp` and tests. - A build step fails when its command exits nonzero, never because it printed. Use `RunBuildCommand` or `RunCommandChecked`; warnings go to `Progress::Diagnostic`. -- Every output path goes through `Configuration::BinDir()`, `BuildDir()` and `PcmDir()`. Hand-rolled `path / "bin" / ...` clobbered variants before; do not add new ones. +- Every output path goes through `Configuration::BinDir()`, `BuildDir()`, `PcmDir()` and `ProgramDir()`. Hand-rolled `path / "bin" / ...` clobbered variants before; do not add new ones. `ProgramDir()` is where an executable and the files it reads at run time land, and the directory `-r` runs a host executable in and serves a browser build from; `ExpectedOutput()` names the executable in it. - Anything that changes what gets compiled or bundled belongs in `VariantId()`. It already hashes type, debug, sysroot, defines, compile flags, the wasm baseline and variant flags, the std module the units import (`StdPcmKey`), uninterpreted project args and the toolchain (`Toolchain::Key()`). ## Design rules diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index a302ca9..1105f74 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -301,7 +301,7 @@ std::string Crafter::WasmCompileFlags(const Configuration& config) { } fs::path Crafter::ExpectedOutput(const Configuration& config) { - const fs::path dir = config.BinDir(); + const fs::path dir = config.ProgramDir(); const bool mingwTarget = config.target == "x86_64-w64-mingw32"; if (config.type == ConfigurationType::Executable) { if (config.target.starts_with("wasm32")) return dir / std::format("{}.wasm", config.outputName); @@ -630,7 +630,9 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map seen; std::function forwardDepArtifacts = [&](Configuration* dep) { if (!seen.insert(dep).second) return; - fs::path depBinDir = dep->BinDir(); + fs::path depBinDir = dep->ProgramDir(); for (const Shader& shader : dep->shaders) { fs::path src = depBinDir / shader.OutputName(); if (!fs::exists(src)) continue; @@ -1406,7 +1408,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map graph; @@ -1428,7 +1430,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_mapwasmVariantFlags = variant.flags; - fs::path variantBin = config.BinDir(); + fs::path variantBin = config.ProgramDir(); std::unordered_map> variantDeps; std::mutex variantMutex; @@ -2087,7 +2089,7 @@ std::int32_t Crafter::Run(std::int32_t argc, char** argv) { std::println(std::cerr, "-r: cannot run a library"); return 1; } - fs::path dir = config.BinDir(); + fs::path dir = config.ProgramDir(); fs::path artifact = fs::absolute(ExpectedOutput(config)); fs::path absDir = fs::absolute(dir); diff --git a/interfaces/Crafter.Build-Clang.cppm b/interfaces/Crafter.Build-Clang.cppm index 50903d6..38f99b3 100644 --- a/interfaces/Crafter.Build-Clang.cppm +++ b/interfaces/Crafter.Build-Clang.cppm @@ -660,6 +660,12 @@ export namespace Crafter { } fs::path BuildDir() const { return path / "build" / VariantId(); } fs::path BinDir() const { return path / "bin" / VariantId(); } + // Where an executable and the files it reads at run time land, and + // the directory `-r` runs a host executable in and serves a browser + // build from: its shaders, cfg.files and assets, and those its + // dependencies forward to it. For now that is the bin + // dir of every configuration. + fs::path ProgramDir() const { return BinDir(); } fs::path PcmDir() const { return type == ConfigurationType::Executable ? BuildDir() : BinDir(); }