003: Hybrid Task Runner and Execution¶
- Status: Developed
- Date: 2026-12-02
- Author(s): João V. Farias
- Traces to: ADR-006 Categories 4 and 6
Context¶
Windows builds on Linux rarely involve a single executable call. Projects combine Wine compilation (dotnet build, python.exe, ISCC.exe), Linux host commands (cleaning directories, patching downloaded tools, installing mods), active-process safety checks before modifying locked game files, and multi-target Windows builds.
Benchmark¶
General host task runners (just, Taskfile, GNU Make) handle host shell pipelines cleanly, yet require custom wrapper scripts for Wine PATH merging, batch escaping, Z:\ drive translation, headless display suppression, and wineserver persistence. CoopCourier previously combined scripts/neorune.nu and a Makefile to orchestrate Proton .NET builds and mod installation. That older setup suffered from batch-file collisions whenever two commands reused the same static .bat path.
Interaction flow¶
Execution proceeds through DAG ordering, guard inspection, runtime preparation, and per-step invocation:
- Parse CLI arguments for
winesmith run <task> [KEY=VALUE ...],winesmith exec [flags] -- <cmd...>, orwinesmith shell. - Resolve the active target profile (
[windows],--target <name>, or--all-targets) and merge positionalKEY=VALUEvariables. - Topologically sort the
dependsgraph (reporting cyclic chains cleanly) and skip runner download and prefix creation when the resolved graph contains onlyhoststeps. - Before running each task, scan Linux
/proc/<pid>/cmdlineand/proc/<pid>/commfor anyforbid_runningregex match, aborting with exit code4if found. - Render MiniJinja templates (
{{ var }},{{ winpath(path) }},{{ prefix_drive_c }},{% if ... %}) and write a unique batch wrapperC:\winesmith\tmp\wine-<pid>-<seq>.cmdcontaining mergedPATHand[env]. Execute Wine with the selected display adapter (none,xvfb, orhost), keepwineserver -p<secs>alive if configured, and delete the wrapper file on drop. - Run
hoststeps via/bin/sh -eu -cin the rendered task working directory withWINESMITH_PROJECT_ROOT,WINESMITH_PREFIX_DIR,WINESMITH_PREFIX_DRIVE_C, and optionalWINESMITH_TARGETexported.
Visual design¶
The sequence diagram below traces winesmith run across Wine compilation, process guard checks, and Linux host steps:
sequenceDiagram
actor User
participant CLI as winesmith
participant Guard as Process Guard
participant Wine as Runner (Wine / Proton)
participant Host as Linux Host Shell
User->>CLI: winesmith run install config=Release
CLI->>CLI: Sort depends DAG and render MiniJinja + winpath()
CLI->>Wine: Execute build step via unique C:\winesmith\tmp\wine-PID-1.cmd
Wine-->>CLI: Exit code 0
CLI->>Guard: Scan /proc for forbid_running regexes
Guard-->>CLI: No conflicting process
CLI->>Host: Execute install host step via /bin/sh -eu -c
Host-->>CLI: Exit code 0
CLI-->>User: Exit code 0
Implementation¶
Safe path translation rules¶
Two translation rules keep mixed Linux paths and Windows slash switches intact:
winpath("relative/or/abs/path")normalizes the path relative toproject_root. When the path sits inside a configured[mounts]directory (such asw = "."), it emitsW:\...; otherwise it falls back toZ:\....- Inside
winesmith exec, slash-prefixed flags (/p:Configuration=Release,/c,/VERYSILENT,/DVersion=1.0) pass through untouched unless the token names an existing Linux file or directory. Tokens starting explicitly with./,../, or~/also trigger translation.
Validated parity manifest (CoopCourier/winesmith.toml)¶
This manifest replaced CoopCourier's Makefile and scripts/neorune.nu while keeping local Steam game paths in gitignored winesmith.local.toml:
[project]
name = "CoopCourier"
[windows]
version = "win10"
arch = "win64"
display = "none"
[runner]
kind = "proton"
version = "Proton 9.0"
[prefix]
mode = "shared"
name = "neorune-net10"
[mounts]
w = "."
[vars]
config = "Debug"
profile = false
mod_name = "CoopCourier"
project = "source/CoopCourier.csproj"
out = "Release"
game_dir = ""
game_compat_data = ""
[symlinks]
"users/steamuser/AppData/Local/Dungeons2/Saved/SaveGames" = "{% if game_compat_data %}{{ game_compat_data }}/pfx/drive_c/users/steamuser/AppData/Local/Dungeons2/Saved/SaveGames{% endif %}"
[toolchains.dotnet]
version = "10.0.403"
shared_nuget_cache = true
templates = ["NeoRune.Templates"]
tools = ["NeoRune.Tool"]
post_install = [
{ host = "python3 scripts/patch-neorune.py '{{ prefix_drive_c }}/users/steamuser/.dotnet/tools/.store/neorune.tool/1.0.0/neorune.tool/1.0.0/tools/net10.0/any/neorune.dll'" }
]
[tasks.build]
description = "Build CoopCourier mod with .NET 10 inside Proton"
run = "dotnet build {{ winpath(project) }} -c {{ config }} -p:NeoRuneInstall=false -p:AllowMissingPrunePackageData=true{% if profile %} -p:NeoRuneProfile=true{% endif %}"
[tasks.test]
description = "Run NeoRune test suite for CoopCourier"
run = "neorune test --project {{ winpath(project) }}"
[tasks.install]
description = "Install compiled .pak files into Minecraft Dungeons II ~mods"
forbid_running = ["(?i)Dungeons.*\\.exe"]
host = """
if [ -z '{{ game_dir }}' ]; then
echo 'Set `game_dir` in winesmith.local.toml or pass `game_dir=/path/to/game`.' >&2
exit 2
fi
mkdir -p '{{ game_dir }}/Dungeons/Content/Paks/~mods/{{ mod_name }}'
cp -r source/bin/NeoRune/Pak/. '{{ game_dir }}/Dungeons/Content/Paks/~mods/{{ mod_name }}'
"""
[tasks.clean]
description = "Remove local build outputs (bin and obj)"
host = "rm -rf source/bin source/obj"
Edge cases and constraints¶
Ad-hoc runs and signal interruption rely on strict cleanup invariants:
- Zero-config invocations (
winesmith exec --win win7 --arch win32 --toolchain python@3.8.10 -- python --version) build an in-memory target spec and reuse the spec-hashed shared prefix without requiringwinesmith.toml. WrapperGuarddeletes each temporarywine-<pid>-<seq>.cmdscript inDrop, including after non-zero child exits orSIGINT/SIGTERMforwarding.- Across
--all-targets, targets execute sequentially and abort immediately with the failing target's exact exit code.