Tool plugins
Every tool comes from a plugin: a WebAssembly component that knows one tool, how to invoke it and how to read what it wrote. doris embeds a plugin for each tool it ships with, and loads more from the directories the plugins.path setting names. Both kinds load the same way, so a tool written outside this repo, such as one for a commercial tool whose details can’t be published, is no different from one built in.
A plugin does what a tool module did before plugins: it builds plans from tool-neutral requests and reads the tool’s logs. The flows don’t change: tools::wasm implements the capability traits on a plugin, so a flow gets a dyn Linter or a dyn Simulator as before.
The interface
The interface is wit/plugin.wit, in the WIT language of the component model, package doris:plugin@0.1.0.
| Interface | What it is |
|---|---|
types | What a plugin hands back: an invocation and its parts, exit-codes, an outcome, a lint-message |
host | What doris lets a plugin do: read, list and write files while a step runs, and make a report page in doris’s style |
tool | What every plugin exports: its name and licence pools, a check of its options, how to find its version, its key-env, and its callbacks |
linter | The Linter capability |
simulator | The Simulator capability |
coverage-reporter | The CoverageReporter capability |
reference-model | The ReferenceModel capability |
sources | The Sources capability: a source manager, such as FuseSoC |
crossing-checker | A crossing checker: the CdcChecker or RdcChecker capability, by the kind its kind function says it checks |
- A plugin has the capabilities whose interfaces it exports. doris looks at what the component exports when it loads it. A plugin is built for one of the worlds
linter-plugin,simulator-plugin,coverage-reporter-plugin,reference-model-plugin,sources-pluginandcrossing-checker-plugin, or a world that includes two, as Verilator’s includeslinter-pluginandsimulator-plugin. - Every function is given the tool’s options: its
tools.<name>table of the flow config, as JSON, or{}if there is none. The plugin reads them into its own type, which denies unknown fields, socheck-optionsfinds a mistake when the config loads and doris has no type for any tool’s options. - Paths cross the interface as text. In a path that is not UTF-8, the bytes that are not are replaced with U+FFFD.
Plans, and callbacks
A plugin never starts a process and never sees the machine. Planning is a function from a request to a plan: an invocation doris runs, and what the flow needs to know about it. The rule that planning never runs a command or reads the environment is kept by the sandbox, not by review: a plugin has no way to do either.
What a plugin does itself when a step runs is a callback. Verilator’s instrument step rewrites sources, FuseSoC’s flatten step rewrites a file list, and the doris coverage reporter reads a coverage database. A plan names such work with a callback: data the plugin made when it planned the step, such as JSON. When the step runs, doris hands it back to the plugin’s tool.run, or to tool.judge to decide a step’s outcome.
- A callback is keyed by what it is. The step is keyed by the callback’s data and the plugin’s hash, as
Step::params. Everything that changes what the callback does is in its data, because that is all the plugin is given. - A callback can read files in its job’s directory, and write them in its step’s. A relative path is relative to the step’s directory. Paths are made absolute and lose their
..before they are checked, so../filelist/work/src/a.svfrom theinstrumentstep is read, and/etc/hostnameis not. While planning, a plugin has no files at all. - The check is of the path’s text, not of where it leads. Symlinks are not resolved, so a symlink in the job’s directory that points out of it, such as one a step stages, is followed. A callback can read, and write, what such a link reaches.
The sandbox, and what it does not do
A plugin is built for wasm32-unknown-unknown, with no WASI. Beyond computing, it can do only what host allows. That makes a plan repeatable, and keeps a plugin’s own file access to paths in its job, as above: not to the files those paths reach through a symlink.
It does not make a plugin safe to run. A plugin’s plans are commands doris runs, so a plugin can run anything a command can. Install a plugin as you would any tool: from someone you trust.
Loading
- The embedded plugins come first, then each
.wasmfile in theplugins.pathdirectories, in the order of the directories and then of the file names. The order is the order tools are listed in, such as the known linters in an error message, and the orderdefault_reporterlooks for a coverage reporter in. - A file whose tool has the name of an embedded one replaces it, so a site can ship a newer plugin for a tool doris has. Two files for one tool are an error.
- Plugins are loaded the first time a tool is asked for, compiled in parallel, and asked for their name and licence pools. A command that uses no tool, such as
doris gc, loads none, unless the settings give atools.NAME.path: every command checks that its tool exists, which loads them all. - Compiled code is cached in
plugins/in the per-user cache directory, named by the hash of the component and of the engine’s settings. Compiling all the embedded plugins takes under a second the first time, and loading them from the cache takes milliseconds after that. A cache that can’t be written only costs the compile.
A call instantiates the plugin afresh. Calls share nothing, so they can be made from any of the executor’s threads, and one can’t leave state for the next.
Cache keys and versions
A tool’s plugin is part of the key of every step that uses it. Tool::plugin gives the SHA-256 of the component, and the cache keys it with the tool’s version and key_env. A new plugin is a miss, as a new version of the tool is, so a plugin’s own behaviour needs no version bump.
The interface has a version, 0.1.0, in its package name. A plugin built for another version doesn’t link, and loading it is an error that names the file. The interface stays at 0.x, free to change, while every plugin is in this repo.
Building
build.rs builds the plugin crates in plugins/ for wasm32-unknown-unknown, with the plugin profile, makes each a component with wit-component, and embeds them. It needs the wasm32-unknown-unknown standard library and lld, which the dev shell has. A plugin crate is a library: build.rs asks for a cdylib with cargo rustc --crate-type cdylib, because a native cdylib can’t be linked with the component’s export names. So a plugin’s unit tests run natively, with cargo test --workspace.
Adding tools and flows says how to write a plugin.