]> git.proxmox.com Git - rustc.git/blob - src/librustc_plugin/lib.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / librustc_plugin / lib.rs
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.
4 //
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.
10
11 //! Infrastructure for compiler plugins.
12 //!
13 //! Plugins are Rust libraries which extend the behavior of `rustc`
14 //! in various ways.
15 //!
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.
19 //!
20 //! To define a plugin, build a dylib crate with a
21 //! `#[plugin_registrar]` function:
22 //!
23 //! ```rust,ignore
24 //! #![crate_name = "myplugin"]
25 //! #![crate_type = "dylib"]
26 //! #![feature(plugin_registrar)]
27 //!
28 //! extern crate rustc;
29 //!
30 //! use rustc_plugin::Registry;
31 //!
32 //! #[plugin_registrar]
33 //! pub fn plugin_registrar(reg: &mut Registry) {
34 //! reg.register_macro("mymacro", expand_mymacro);
35 //! }
36 //!
37 //! fn expand_mymacro(...) { // details elided
38 //! ```
39 //!
40 //! WARNING: We currently don't check that the registrar function
41 //! has the appropriate type!
42 //!
43 //! To use a plugin while compiling another crate:
44 //!
45 //! ```rust
46 //! #![feature(plugin)]
47 //! #![plugin(myplugin)]
48 //! ```
49 //!
50 //! See the [Plugins Chapter](../../book/compiler-plugins.html) of the book
51 //! for more examples.
52
53 #![crate_name = "rustc_plugin"]
54 #![unstable(feature = "rustc_private", issue = "27812")]
55 #![crate_type = "dylib"]
56 #![crate_type = "rlib"]
57 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
58 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
59 html_root_url = "https://doc.rust-lang.org/nightly/")]
60 #![cfg_attr(not(stage0), deny(warnings))]
61
62 #![feature(staged_api)]
63 #![feature(rustc_diagnostic_macros)]
64 #![feature(rustc_private)]
65
66 #[macro_use] extern crate log;
67 #[macro_use] extern crate syntax;
68 #[macro_use] #[no_link] extern crate rustc_bitflags;
69
70 extern crate rustc;
71 extern crate rustc_back;
72 extern crate rustc_metadata;
73 extern crate syntax_pos;
74 extern crate rustc_errors as errors;
75
76 pub use self::registry::Registry;
77
78 pub mod diagnostics;
79 pub mod registry;
80 pub mod load;
81 pub mod build;