/src/librustc/plugin/mod.rs

https://gitlab.com/pranith/rust · Rust · 57 lines · 4 code · 3 blank · 50 comment · 0 complexity · fe59f7d7c3b65081851a9c6b26027acb MD5 · raw file

  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. //! Infrastructure for compiler plugins.
  11. //!
  12. //! Plugins are Rust libraries which extend the behavior of `rustc`
  13. //! in various ways.
  14. //!
  15. //! Plugin authors will use the `Registry` type re-exported by
  16. //! this module, along with its methods. The rest of the module
  17. //! is for use by `rustc` itself.
  18. //!
  19. //! To define a plugin, build a dylib crate with a
  20. //! `#[plugin_registrar]` function:
  21. //!
  22. //! ```rust,ignore
  23. //! #![crate_name = "myplugin"]
  24. //! #![crate_type = "dylib"]
  25. //! #![feature(plugin_registrar)]
  26. //!
  27. //! extern crate rustc;
  28. //!
  29. //! use rustc::plugin::Registry;
  30. //!
  31. //! #[plugin_registrar]
  32. //! pub fn plugin_registrar(reg: &mut Registry) {
  33. //! reg.register_macro("mymacro", expand_mymacro);
  34. //! }
  35. //!
  36. //! fn expand_mymacro(...) { // details elided
  37. //! ```
  38. //!
  39. //! WARNING: We currently don't check that the registrar function
  40. //! has the appropriate type!
  41. //!
  42. //! To use a plugin while compiling another crate:
  43. //!
  44. //! ```rust
  45. //! #![feature(plugin)]
  46. //! #![plugin(myplugin)]
  47. //! ```
  48. //!
  49. //! See the [Plugins Chapter](../../book/plugins.html) of the book
  50. //! for more examples.
  51. pub use self::registry::Registry;
  52. pub mod registry;
  53. pub mod load;
  54. pub mod build;