1 //! Infrastructure for compiler plugins.
3 //! Plugins are Rust libraries which extend the behavior of `rustc`
6 //! Plugin authors will use the `Registry` type re-exported by
7 //! this module, along with its methods. The rest of the module
8 //! is for use by `rustc` itself.
10 //! To define a plugin, build a dylib crate with a
11 //! `#[plugin_registrar]` function:
14 //! #![crate_name = "myplugin"]
15 //! #![crate_type = "dylib"]
16 //! #![feature(plugin_registrar)]
17 //! #![feature(rustc_private)]
19 //! extern crate rustc_driver;
20 //! extern crate syntax;
21 //! extern crate syntax_pos;
23 //! use rustc_driver::plugin::Registry;
24 //! use syntax_expand::base::{ExtCtxt, MacResult};
25 //! use syntax_pos::Span;
26 //! use syntax::tokenstream::TokenTree;
28 //! #[plugin_registrar]
29 //! pub fn plugin_registrar(reg: &mut Registry) {
30 //! reg.register_macro("mymacro", expand_mymacro);
33 //! fn expand_mymacro(cx: &mut ExtCtxt, span: Span, tt: &[TokenTree]) -> Box<MacResult> {
40 //! WARNING: We currently don't check that the registrar function
41 //! has the appropriate type!
43 //! To use a plugin while compiling another crate:
46 //! #![feature(plugin)]
47 //! #![plugin(myplugin)]
51 //! feature](https://doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html)
52 //! of the Unstable Book for more examples.
54 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
58 #![recursion_limit="256"]
60 pub use registry::Registry;