1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Infrastructure for compiler plugins.
13 //! Plugins are Rust libraries which extend the behavior of `rustc`
16 //! Plugin authors will use the `Registry` type re-exported by
17 //! this module, along with its methods. The rest of the module
18 //! is for use by `rustc` itself.
20 //! To define a plugin, build a dylib crate with a
21 //! `#[plugin_registrar]` function:
24 //! #![crate_name = "myplugin"]
25 //! #![crate_type = "dylib"]
26 //! #![feature(plugin_registrar)]
28 //! extern crate rustc;
30 //! use rustc::plugin::Registry;
32 //! #[plugin_registrar]
33 //! pub fn plugin_registrar(reg: &mut Registry) {
34 //! reg.register_macro("mymacro", expand_mymacro);
37 //! fn expand_mymacro(...) { // details elided
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)]
50 //! See the [Plugins Chapter](../../book/compiler-plugins.html) of the book
51 //! for more examples.
53 #![cfg_attr(stage0, feature(custom_attribute))]
54 #![crate_name = "rustc_plugin"]
55 #![unstable(feature = "rustc_private", issue = "27812")]
56 #![cfg_attr(stage0, staged_api)]
57 #![crate_type = "dylib"]
58 #![crate_type = "rlib"]
59 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
60 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
61 html_root_url = "https://doc.rust-lang.org/nightly/")]
63 #![feature(dynamic_lib)]
64 #![feature(staged_api)]
65 #![feature(rustc_diagnostic_macros)]
66 #![feature(rustc_private)]
68 #[macro_use] extern crate log;
69 #[macro_use] extern crate syntax;
70 #[macro_use] #[no_link] extern crate rustc_bitflags;
73 extern crate rustc_front;
74 extern crate rustc_metadata;
76 pub use self::registry::Registry;