Adding tools and flows
A tool is a plugin: a WebAssembly component built from wit/plugin.wit, which doris embeds or loads from a plugin directory. A flow is compiled into doris. Read Flows and tools, Tool plugins and Code layout first.
Adding a tool
A tool can be added to doris, or kept outside it: the plugin is the same either way. A linter is the simplest case. To add one:
-
Make the crate,
plugins/<name>/, a library that depends ondoris-plugin(the SDK, insdk/),serdeandwit-bindgen. Useplugins/slangas the pattern. Bind the world of the capability, mapping the shared interfaces to the SDK’s, so its helpers work on your types:#![allow(unused)] fn main() { wit_bindgen::generate!({ world: "doris:plugin/linter-plugin", path: "../../wit", with: { "doris:plugin/types@0.1.0": doris_plugin::types, "doris:plugin/host@0.1.0": doris_plugin::host, }, }); } -
Implement
tool::Guest, which every plugin exports, andexport!the type.describegives the name config binds the tool by, which is also the name of itstools.<name>table, and the resource pools its commands hold, such as the site’s licences for it. Each pool it names gets the default size of a licence pool.probesays how doris finds the tool’s version, so a new version reruns the step: most are a command, such as["slang", "--version"], which doris runs once when it works out a cache key, never while planning.key-envnames any host variable that changes what the tool writes as a capability. Return none unless one does: a variable in it splits the cache between machines that set it differently.check-optionsreads the options into the tool’sOptionstype (see step 4), so a mistake in a config is found when it loads.runandjudgeare the plugin’s callbacks (see below). A tool with none returns an error.
-
Implement
linter::Guest.lintbuilds theInvocationfrom the request with the SDK’s builder, and calls.tool()on it. That is what puts the tool’s version, itskey-envand the plugin’s hash in the step’s cache key, and the version in the result file. A helper program the command runs, such as a compiler, is added as.program("gcc", &["-dumpfullversion"]).- Say what the tool holds while it runs, so the scheduler can count it:
.resource(POOL, 1)for a licence, naming a pooldescribenames, and.threads(...)if it uses more than one. A tool that takes a thread count gets it fromArg::threads(see Resource pools). - Declare what the tool needs of the machine on the invocation, with
.precheck(...), if it is more than the program being onPATH(see Prechecks). complete-onsays which exit codes mean it finished. A linter that exits non-zero for findings must not be reported as a step error.logsnames the filesparsereads. They become the step’s outputs, so a cached step still has them, and a step that passed keeps them.parseturns the log text intolint-messages. The lint flow calls it once, as the step’s parse function, and writes the messages tomessages.json, which the judge and the result file read.judgeis given the parsed messages, the exit code and the log to point at:doris_plugin::lint::verdictfor most linters, or more for one with more to say, such as Verilator’s, which makes an internal error a step error.backendnames thefilelist-formatit reads. The FuseSoC plugin, inplugins/fusesoc, asks FuseSoC for that tool’s files and flattens them into the linter’s argument file. A tool Edalize writes nothing for at setup is flattened from the EDAM file, as Verible and slang are. A format FuseSoC has no flattening for is a change to that plugin and to thefilelist-formatenum.
-
Give it options. Write an
Optionsstruct, withdeny_unknown_fieldsand adoris_plugin::StepOptionsfield for each step the tool is used in, named after the step, and read it withdoris_plugin::options. Put each step’sargsin that step’s command. -
Build it into doris, if it is to ship with doris: add the tool’s name and crate to
PLUGINSinbuild.rs. Where it goes in that list is where it is listed among the tools. A plugin kept outside doris is built withcargo rustc --crate-type cdylib --target wasm32-unknown-unknownand made a component withwasm-tools component new, and a site puts it in aplugins.pathdirectory.wasm-toolsis not in the dev shell: get it from nixpkgs’wasm-tools, or withcargo install wasm-tools. -
Test it. Test
parsenatively, in the crate, withcargo test --workspace, on real log text, including a clean run, a syntax error and a message with no rule. Test the command linelintgives, with and without options, and the judge, through the plugin, intools::wasm’s tests. -
Document it: the Lint page’s tables, and the flatten and lint step pages.
The other capabilities follow the same steps, each with its world and interface:
| Capability | World | Functions |
|---|---|---|
| Simulator | simulator-plugin | features, coverage-format, build, run |
| Reference model | reference-model-plugin | build, serve |
| Coverage reporter | coverage-reporter-plugin | reads, report, summary, files, parse |
| Linter | linter-plugin | backend, lint, logs, parse, judge |
| CDC or RDC checker | crossing-checker-plugin | kind, check, parse, judge |
- A simulator says what it can do.
featuresgives coverage, waves, DPI and UVM. Say only what the plugin’sbuildandrunreally handle, because the flow fails a job that asks for more when it plans it.coverage-formatnames the format of the databases its runs write, such asCadence. - A coverage reporter says what it reads, as
reads, a format a simulator names. A job whose config binds no reporter gets the first plugin’s that reads its simulator’s format. - A simulator that builds from sources it writes gives a
prepare-stepfor that in its build plan, as Verilator does withinstrument. - A coverage reporter is either a command or the plugin reading the database itself, as a callback. One that is the plugin reports the plugin’s version from
probe, asdorisdoes. - A tool with two capabilities is one plugin whose world includes both worlds, as Verilator’s does. Its
key-envis asked for each capability, and both share oneOptionsstruct. - Code two plugins share is a crate of its own, as
plugins/verilator-covis for Verilator and thedorisreporter: the names of the cover properties one writes are the names the other reads. Two tools that are one code are one crate that two thin plugin crates export, asplugins/meridianis forplugins/meridiancdcandplugins/meridianrdc: it binds its world withpub_export_macro: true, and each exports its type withplugin_meridian::export!(Cdc with_types_in plugin_meridian).
A callback is all data. What a plugin does itself when a step runs, such as instrument’s rewrite, is named by a callback: data the plugin makes when it plans the step, usually JSON of an enum of the plugin’s own. The step is keyed by it, so put everything that changes the result in it. When the step runs, tool.run is given it back with the step’s directory, and can read files in the job’s directory and write them in the step’s, with doris_plugin::fs. A judge that reads files, such as IMC’s, is a callback given to tool.judge.
Keep tool flags out of the flow. If a flow needs something new from a tool, add it to the request type in neutral terms, in the WIT and the capability trait, and let each tool turn it into its own arguments. If not every tool can do it, make it a feature so that asking for it is checked.
Keep the machine out of the plan. A library path, a port or a version is a host-env request, an Arg::Port or a tool’s probe. A plugin can’t read the environment or run a command while planning, so there is no other way.
Adding a flow
A flow touches more places, because the command line is a fixed list of flows:
- The flow module,
src/flows/<name>.rs:- the config type: a serde struct with
deny_unknown_fields, its schema name, such asdv/syn/1, atoolfield of typeconfig::RoleToolsand atoolsfield of typeconfig::ToolOptions; NAME, the flow’s name on the command line and in the project file’stooltable;ROLES, the roles the flow needs tools for, each with a name, a capability and whether it is optional. The first is the main role, whose tool is in the job’s ID;- a type that implements
Flow. Itsplantakes a design, the config and aBindings, gets each tool from its capability’s constructor withtools.tool(ROLE), and returns one job. Usetools.label()for what follows@in the job’s ID and directory; - a
validateon the config that callsflows::boundandToolOptions::check, so a bad binding is found when config loads; - a
planfunction for the command line that callsflows::plan_jobs, which makes a job for each combination of bound tools; - a job type that implements
Job; - the result type, with its own schema name such as
dv/syn-result/1, aversionsfield fromflows::tool_versions, andwrite_result.
- the config type: a serde struct with
- Discovery, in
src/repo.rs: load files with that schema, attach each to its design, call the config’svalidatewith the project file’s defaults for the flow, and add the flow’s name and roles where the project file’stooltable is checked. - The report,
src/flows/<name>/report.rs, made from the result type alone. Add the result toJobResultinsrc/flows/mod.rssodoris reportanddoris report viewcan read it. - The command line, in
src/main.rs: theFlowenum and the places that match on it. - Documentation: a page under Flows, a page for each new step, the schema in Configuration, and the flow’s roles in Tools and roles.
A flow that needs a new kind of tool adds a capability first: an interface for it in wit/plugin.wit, with its tool-neutral request and plan types, a world for its plugins, an export of it in the doris world, and a variant of the tool interface’s capability enum, which key-env is given; a Capability variant with its label, and a trait that is a subtrait of Tool, in src/tools/mod.rs; the interface’s indices on plugin::Plugin, which say whether a plugin exports it, with its entry in Plugin::capabilities and a Call method that loads it; and the trait’s implementation on a plugin, in tools::wasm.
When designing the steps:
- One command per step, so each is cached by itself.
- Read artefacts; don’t name dependencies. Take another step’s output with
step.artefact("name"), give itspathto whatever builds the command, and call.reads(&artefact)on the step that uses it. That is the dependency. A command that names a path in another step’s directory without it is refused byexec::validate.Step::afteris only for an order with nothing read. - Give an in-process step a
paramfor everything its closure captures that changes its result. The cache can’t see into a function, so a captured option that is not aparam, an input or an artefact the step reads is not in the key, and changing it gives a stale hit.Step::param(what, value)keys the value’sDebugtext. - Declare every output a later step or the result needs. Only declared outputs are cached, and only they are left in the directory of a step that passed.
write_resultmust work for a step that came from the cache, so anything it reads, such as a log it parses, is an output. - Declare a file that is only for looking into the step as a debug output, with
debug_output: a raw tool log, or an intermediate file. It is kept and cached in a run with--debugand deleted otherwise. Don’t declare scratch at all. Nothing downstream can rely on a debug output, because a plain run deletes it. - Parse a tool’s output once, with a parse function, when the judge and the result file both need what it reported:
Step::parsed(name, path, function). The judge is given the results, andwrite_resultreads them from the output, which a cached step has. Write paths in them relative to the job’s directory, so they are the same in every checkout. - Give the step that decides the result a judge, and say on its page what
passeddoes and does not mean. Use a pass pattern to tell a tool that finished from one that crashed with an accepted exit code, and a fail pattern for an error line no exit code shows.Pattern::textandPattern::regexname the output to look in, orSTDOUTorSTDERR. - Set
run_after_failon a step that reports on a run, if the report is wanted when the run failed. It then reads a failed step’s outputs, so they must be complete when the step fails. - Declare what the step needs of the machine as prechecks, so a run that can’t work stops before its first step. A program run by name needs nothing: it is checked already, and
Invocation::needsadds the programs a command runs itself. Put aPrecheckon the invocation, in the plugin, for what the tool needs whatever the flow, such asPrecheck::Envfor a variable. A licence is not a precheck: hold it with.resource(POOL, 1)and the scheduler waits for one. Put one on the step, in the flow, for what the flow knows, such asPrecheck::Filefor a directory the config names. - Start services with
Service::new, and change only what differs:readyfor a service that shows it is ready by a file or a log line,ready_timeout,stopandstop_timeout. Declare what a service writes on the service, with.output, so it is checked once the service has stopped;.portgives it more ports, and.inputkeys a file it reads. - Use a cache unit only for a step that needs one: a long step worth resuming part-way, or one whose raw output should not be cached because it has timestamps or paths in it, or is far larger than what is wanted from it. A unit, a composite step, a parse function and a service’s own outputs are all there for steps that need them; a step that doesn’t stays as simple as it can be. Make the tool one child and the reduction another, with
Step::unit, andexportonly what the rest of the job and the result read. Give a child the unit’s own directory when it needs its siblings’ working files, and one of its own otherwise. Give the unit the verdict: children can’t have a judge or fail patterns. A step whose outputs are already small and stable stays a leaf. See Cache units. - Use a composite step to group steps that are each cached by itself, with
Step::group, such as a list of commands. Name its children as siblings, andexportwhat the rest of the job reads. See Composite steps. - Reuse
tools::sources::stepsfor the sources. - Check what the config asks of a tool when the job is planned, as TestRIG does with
tools::check_featuresandtools::check_pairing, so a job that can’t work fails indoris plan.
The roadmap’s Tool capabilities page describes where these interfaces are going: a command line that works on any Flow, and options checked against the steps a tool is used in.
Changing a format
Config files, result files, cache entries and GC roots all carry a schema with a version.
- A change that old readers would misread needs a new version. Result files outlive the doris that wrote them:
doris report viewreads results kept in GC roots. - A changed cache key is safe. Old entries are simply never hit, and are collected when their roots go.
- A new field that defaults when absent needs no new version, as the
debuganddebug_outputsfields of a cache entry did not. - Bump
KEY_PROTOCOLinsrc/cache.rswhen doris’s own part in a result changes: how a key is made, how a verdict is reached from a step’s rules, or what a flow does around a plugin’s results. Every key holds it, so entries stored before are not used. A plugin needs no bump: its hash is in the key of every step that uses its tool.