#[cfg(not(feature = "serde_macros"))]
mod inner {
    extern crate serde_codegen;

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

    const MODULES: &'static[&'static str] = &[
        "error",
        "keys",
        "stats",
        "version",
    ];

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

        for module in MODULES.iter() {
            let src = format!("src/{}_gen.rs", module);
            let src_path = Path::new(&src);
            let dst = format!("{}.rs", module);
            let dst_path = Path::new(&out_dir).join(&dst);

            serde_codegen::expand(&src_path, &dst_path).unwrap();
        }
    }
}

#[cfg(feature = "serde_macros")]
mod inner {
    pub fn main() {}
}

fn main() {
    inner::main();
}

#[cfg(not(feature = "serde_macros"))]
mod inner {
    extern crate serde_codegen;
    extern crate syntex;

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

    const MODULES: &'static[&'static str] = &[
        "error",
        "keys",
        "stats",
        "version",
    ];

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

        for module in MODULES.iter() {
            let src = format!("src/{}_gen.rs", module);
            let src_path = Path::new(&src);
            let dst = format!("{}.rs", module);
            let dst_path = Path::new(&out_dir).join(&dst);

            let mut registry = syntex::Registry::new();

            serde_codegen::register(&mut registry);
            registry.expand("", &src_path, &dst_path).unwrap();
        }
    }
}

#[cfg(feature = "serde_macros")]
mod inner {
    pub fn main() {}
}

fn main() {
    inner::main();
}

--- 
+++ 
@@ -1,7 +1,6 @@
 #[cfg(not(feature = "serde_macros"))]
 mod inner {
     extern crate serde_codegen;
-    extern crate syntex;
 
     use std::env;
     use std::path::Path;
@@ -22,10 +21,7 @@
             let dst = format!("{}.rs", module);
             let dst_path = Path::new(&out_dir).join(&dst);
 
-            let mut registry = syntex::Registry::new();
-
-            serde_codegen::register(&mut registry);
-            registry.expand("", &src_path, &dst_path).unwrap();
+            serde_codegen::expand(&src_path, &dst_path).unwrap();
         }
     }
 }
Fix compilation error due to syntex mismatched types

Error:
build.rs:27:37: 27:50 error: mismatched types:
expected `&mut syntex::Registry`,
found `&mut inner::syntex::Registry`
(expected struct `syntex::Registry`,
found struct `inner::syntex::Registry`) [E0308]
build.rs:27             serde_codegen::register(&mut registry);
                                            ^~~~~~~~~~~~~

Solution is to use codegen without explicit dependency on syntex, see:
https://users.rust-lang.org/t/here-is-how-to-avoid-being-broken-by-syntex-updates/6189?u=dtolnay
