Skip to content

Commit

Permalink
Add a feature for linking to proc_macro.
Browse files Browse the repository at this point in the history
This feature is enabled by default for backwards compatibility, but
it can be disabled in order to break the runtime dependency on
the dynamic library libproc_macro in the rustc toolchain.
  • Loading branch information
staktrace committed Feb 22, 2018
1 parent 3bdfd71 commit 78c9adb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ rust:

script:
- cargo test
- cargo test --no-default-fatures
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ keywords = ["syn"]
include = ["Cargo.toml", "src/**/*.rs", "tests/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]

[dependencies]
proc-macro2 = "0.2"
proc-macro2 = { version = "0.2.3", default-features = false }

[features]
# Disabling the proc-macro feature removes the dynamic library dependency on
# libproc_macro in the rustc compiler.
proc-macro = []

default = ["proc-macro", "proc-macro2/proc-macro"]
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#![doc(html_root_url = "https://docs.rs/quote/0.4.2")]

extern crate proc_macro2;
#[cfg(feature = "proc-macro")]
extern crate proc_macro;

mod tokens;
Expand Down Expand Up @@ -169,16 +170,19 @@ pub mod __rt {
/// # Example
///
/// ```
/// # #[cfg(feature = "proc-macro")]
/// extern crate proc_macro;
///
/// #[macro_use]
/// extern crate quote;
///
/// # #[cfg(feature = "proc-macro")]
/// use proc_macro::TokenStream;
///
/// # const IGNORE_TOKENS: &'static str = stringify! {
/// #[proc_macro_derive(HeapSize)]
/// # };
/// # #[cfg(feature = "proc-macro")]
/// pub fn derive_heap_size(input: TokenStream) -> TokenStream {
/// // Parse the input and figure out what implementation to generate...
/// # const IGNORE_TOKENS: &'static str = stringify! {
Expand Down
2 changes: 2 additions & 0 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::ToTokens;
use std::fmt::{self, Debug, Display};
use std::hash::{Hash, Hasher};

#[cfg(feature = "proc-macro")]
use proc_macro;
use proc_macro2::{TokenStream, TokenTree};

Expand Down Expand Up @@ -108,6 +109,7 @@ impl From<Tokens> for TokenStream {
}
}

#[cfg(feature = "proc-macro")]
impl From<Tokens> for proc_macro::TokenStream {
fn from(tokens: Tokens) -> proc_macro::TokenStream {
TokenStream::from(tokens).into()
Expand Down

0 comments on commit 78c9adb

Please sign in to comment.