daukle-logic-layer
A daukle.lua beside daukle.toml, computing a toolchain's block that a static manifest could not state. The toolchain is a local plugin, plugins/banner.lua, that generates one header from its block.
$ daukle sync
daukle: updated
$ cat build/daukle/banner/banner.h
#define BUILD_MODE "release"
#define FEATURE_COUNT 2
#define FEATURE_METRICS 1
$ DAUKLE_EXAMPLE_DEV=1 daukle sync
daukle: updated
$ cat build/daukle/banner/banner.h
#define BUILD_MODE "debug"
What to look at
daukle.toml holds no [toolchains.banner] table. daukle.lua writes it into daukle.config after the TOML is read, so the manifest daukle acts on is the TOML plus whatever the script set.
The features are named once. The header carries a count and one flag per feature, both derived from the one list, so adding a feature cannot leave the count behind.
The same checkout builds two ways. DAUKLE_EXAMPLE_DEV=1 turns the release banner into a debug one with no second manifest. daukle check run without the variable after a debug sync reports the header out of date, which is correct: the manifest it reads is a release one.
What this example cannot show
Anything the sandbox withholds. The script sees literals, daukle.host and daukle.env; it cannot read files or start a process, so it cannot discover the features from the source tree.
Every file in it
daukle.lua
local FEATURES = { "logging", "metrics" }
local mode = daukle.env("DAUKLE_EXAMPLE_DEV") == "1" and "debug" or "release"
daukle.config.toolchains = {
banner = { mode = mode, features = FEATURES },
}
daukle.log("generating a " .. mode .. " banner with " .. #FEATURES .. " features for "
.. daukle.host.os .. "/" .. daukle.host.arch)
daukle.toml
schema = 1
project = "daukle/example-logic-layer"
version = "1.0.0"
[modules]
# [toolchains.banner] is written by daukle.lua, because it depends on the checkout.
[plugins]
banner = "./plugins/banner.lua"
plugins/banner.lua
daukle.plugin{ api = 1, uses = {} }
daukle.toolchain{
name = "banner",
generate = function(context)
local config = context.config
local features = config.features or {}
local lines = {
"/* Generated by the banner toolchain. Do not edit. */",
'#define BUILD_MODE "' .. (config.mode or "release") .. '"',
"#define FEATURE_COUNT " .. #features,
}
for index = 1, #features do
lines[#lines + 1] = "#define FEATURE_" .. string.upper(features[index]) .. " 1"
end
return { ["banner.h"] = table.concat(lines, "\n") .. "\n" }
end,
}