Files
ericandClaude Opus 5.5 a77273f777 feat(plugins): run plugins compiled into the client, named by builtin
iOS will not load code from a file, and Android will not from anywhere an
app can write, so there a plugin is linked in at build time instead. It
is registered under a name with register_builtin_plugin, and a config
refers to it with `builtin`, in conf ([Plugin] builtin=) and JSON alike.

A registered builtin wins over path and url, which are then only the
fallback for a client without it: nothing is downloaded and no cache
directory is needed. A client with none of the three fails to start and
lists the builtins it has. A builtin's descriptor goes through the same
validation as a library's; only the file's checks -- path, permissions,
sha256 -- do not apply, since there is no file. Loaded plugins are now
keyed by source, so two outbounds on one builtin share it.

Only plugins written in other languages are linked in. Plugins exist for
protocols written in something other than Rust; one written in Rust
belongs in leaf as an outbound of its own. Linking a Rust plugin in would
also merge its dependencies' features with leaf's -- the TLS plugin's
rustls with ring on top of leaf's aws-lc-rs, for one, which leaves rustls
with no default provider and panics the DoH client. The in-tree Rust
plugins stay loadable libraries only.

For C, defining LEAF_PLUGIN_STATIC_NAME renames the descriptor function
to leaf_plugin_<name>_get_descriptor and drops its export, through the
canonical header, so the plugin's source does not change and any number
of C plugins can be linked into one binary.

leaf-ffi's plugin-socks5-c feature links the SOCKS5 C plugin into the
library (compiled by build.rs) and registers it as the builtin socks5-c
on the first call that reads a config. leaf_register_plugin registers one
the app links itself. Its unit tests load the linked-in plugin through
the host.

The builtin/ e2e cases register a fixture's descriptor function and show
that it carries TCP and UDP to a stock leaf server, wins over a path and
over a url (with no cache directory to fall back on), gives way to the
url on a client without it, fails clearly with nothing to fall back on,
and is held to the same descriptor validation as a library.

The READMEs describe builtins and how to link a plugin in, and
plugin-test and CI run the linked-in tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 01:03:00 +08:00
..