Skip to content

Reference | Engine

olegz edited this page Mar 16, 2026 · 1 revision

XakeEngine

XakeEngine provides a long-lived build engine for scenarios like watch mode or editor integrations. Unlike xakeScript which runs to completion, an engine stays alive and accepts on-demand build requests.

Starting an engine

Use the start operation inside xakeEngine:

let engine = xakeEngine {
    rules [
        command "build" {
            do! sh "dotnet build src/core" {}
        }
        command "test" {
            do! sh "dotnet test src/tests" {}
        }
    ]
    start
}

Or start from an assembled XakeScript:

let engine = XakeEngine.Start(XakeScript(options, rules))

xakeEngine has IgnoreCommandLine = true, NoPersist = true, and silent logging by default.

Demanding targets

Call Demand to build a target. It returns a Task:

do! engine.Demand("build") |> Async.AwaitTask
do! engine.Demand("test") |> Async.AwaitTask

Pass extra variables per demand:

do! engine.Demand("build", vars = ["Config", "Release"]) |> Async.AwaitTask

Concurrent demands for the same target are serialized — if a build is already in flight, subsequent callers wait for it to finish and then re-evaluate.

Stopping the engine

StopAsync waits for in-flight tasks to complete, runs any teardown targets, then releases resources:

do! engine.StopAsync() |> Async.AwaitTask

Teardown targets

Register targets to run during shutdown:

let engine = xakeEngine {
    teardown ["cleanup"]
    rules [
        command "cleanup" {
            do! trace Info "Cleaning up..."
        }
    ]
    start
}

IAsyncDisposable

On .NET 5+ and netstandard2.1+, XakeEngine implements IAsyncDisposable:

use engine = xakeEngine {
    rules [ ... ]
    start
}
// engine.DisposeAsync() calls StopAsync()

Clone this wiki locally