Skip to content

Commit

Permalink
Merge pull request #8 from kardeiz/with-syntex-feature
Browse files Browse the repository at this point in the history
With syntex feature
  • Loading branch information
mikedilger committed Mar 25, 2016
2 parents ad544df + f317c9a commit 89e8809
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "textnonce"
version = "0.2.4"
version = "0.2.5"
description = "Text based random nonce generator"
authors = [
"Mike Dilger <[email protected]>",
Expand All @@ -13,13 +13,18 @@ license = "MIT OR Apache-2.0"
keywords = [ "nonce", "random" ]
build = "build.rs"

[features]
default = ["with-syntex"]
with-syntex = ["syntex", "serde_codegen"]

[build-dependencies]
serde_codegen = "^0"
syntex = "^0"
serde_codegen = { version = "^0", optional = true }
syntex = { version = "^0", optional = true }

[dependencies]
rand = "^0.3"
time = "^0.1"
rustc-serialize = "^0.3"
serde = "^0"
clippy = { version = "^0", optional = true }
serde_macros = { version = "^0", optional = true }
clippy = { version = "^0", optional = true }
34 changes: 23 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
extern crate syntex;
extern crate serde_codegen;
#[cfg(feature = "with-syntex")]
mod inner {
extern crate syntex;
extern crate serde_codegen;

use std::env;
use std::path::Path;
use std::env;
use std::path::Path;

fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");
let mut registry = syntex::Registry::new();

let mut registry = syntex::Registry::new();
serde_codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
}
}

serde_codegen::register(&mut registry);
registry.expand("", &src, &dst).unwrap();
#[cfg(not(feature = "with-syntex"))]
mod inner {
pub fn main() {}
}

fn main() {
inner::main();
}
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]

#![cfg_attr(not(feature = "with-syntex"), feature(custom_attribute, custom_derive, plugin))]
#![cfg_attr(not(feature = "with-syntex"), plugin(serde_macros))]

extern crate rand;
extern crate time;
extern crate rustc_serialize;
extern crate serde;

include!(concat!(env!("OUT_DIR"), "/lib.rs"));

#[cfg(not(feature = "with-syntex"))]
include!("lib.rs.in");

#[cfg(feature = "with-syntex")]
include!(concat!(env!("OUT_DIR"), "/lib.rs"));

0 comments on commit 89e8809

Please sign in to comment.