From 6319504b72eebdea77b5b3a304c8eabf938cfcca Mon Sep 17 00:00:00 2001 From: kardeiz Date: Thu, 24 Mar 2016 11:24:35 -0500 Subject: [PATCH 1/3] added with-syntex feature --- Cargo.toml | 9 +++++++-- build.rs | 34 +++++++++++++++++++++++----------- src/lib.rs | 10 ++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4ea462..df47d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" +serde_macros = { version = "^0", optional = true } clippy = { version = "^0", optional = true } diff --git a/build.rs b/build.rs index 2b469fb..80a8c56 100644 --- a/build.rs +++ b/build.rs @@ -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(); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 354d54e..7f5ad8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,19 @@ #![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; + +#[cfg(not(feature = "with-syntex"))] +include!("lib.rs.in"); + +#[cfg(feature = "with-syntex")] include!(concat!(env!("OUT_DIR"), "/lib.rs")); + + From 47b142a41edb33709ea8a6bfe99c39e98dd75000 Mon Sep 17 00:00:00 2001 From: kardeiz Date: Thu, 24 Mar 2016 12:39:46 -0500 Subject: [PATCH 2/3] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index df47d3b..0fec23f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "textnonce" -version = "0.2.4" +version = "0.2.5" description = "Text based random nonce generator" authors = [ "Mike Dilger ", From f317c9a46528c279189569912d7e7042e12f46b7 Mon Sep 17 00:00:00 2001 From: kardeiz Date: Thu, 24 Mar 2016 12:42:10 -0500 Subject: [PATCH 3/3] fix newlines --- Cargo.toml | 2 +- src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fec23f..621a305 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,4 @@ time = "^0.1" rustc-serialize = "^0.3" serde = "^0" serde_macros = { version = "^0", optional = true } -clippy = { version = "^0", optional = true } +clippy = { version = "^0", optional = true } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 7f5ad8c..7862559 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,4 @@ extern crate serde; include!("lib.rs.in"); #[cfg(feature = "with-syntex")] -include!(concat!(env!("OUT_DIR"), "/lib.rs")); - - +include!(concat!(env!("OUT_DIR"), "/lib.rs")); \ No newline at end of file