/src/librustc_plugin/lib.rs

https://gitlab.com/alx741/rust · Rust · 80 lines · 23 code · 7 blank · 50 comment · 0 complexity · de74f29180261fb9b38b979d76cd5897 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/compiler-plugins.html) of the book
  50. //! for more examples.
  51. #![crate_name = "rustc_plugin"]
  52. #![unstable(feature = "rustc_private", issue = "27812")]
  53. #![crate_type = "dylib"]
  54. #![crate_type = "rlib"]
  55. #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
  56. html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
  57. html_root_url = "https://doc.rust-lang.org/nightly/")]
  58. #![cfg_attr(not(stage0), deny(warnings))]
  59. #![feature(staged_api)]
  60. #![feature(rustc_diagnostic_macros)]
  61. #![feature(rustc_private)]
  62. #[macro_use] extern crate log;
  63. #[macro_use] extern crate syntax;
  64. #[macro_use] #[no_link] extern crate rustc_bitflags;
  65. extern crate rustc;
  66. extern crate rustc_back;
  67. extern crate rustc_metadata;
  68. extern crate rustc_mir;
  69. pub use self::registry::Registry;
  70. pub mod diagnostics;
  71. pub mod registry;
  72. pub mod load;
  73. pub mod build;