Serde: Remove public dependency on Syntex

Created on 8 Jun 2016  路  3Comments  路  Source: serde-rs/serde

Currently Syntex is a public dependency because the argument to serde_codegen::register is &mut syntex::Registry:

// build.rs
pub fn main() {
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let src = Path::new("src/main.rs.in");
    let dst = Path::new(&out_dir).join("main.rs");

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

Let's see if we can do something more similar to this instead:

// build.rs
pub fn main() {
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let src = Path::new("src/main.rs.in");
    let dst = Path::new(&out_dir).join("main.rs");

    // no more public Syntex dependency
    serde_codegen::expand(&src, &dst).unwrap();
}

The downside would be if someone wants to apply more than one compiler plugin, their code is parsed multiple times:

serde_codegen::expand(&src, &tmp1).unwrap();
other_plugin::expand(&tmp1, &tmp2).unwrap();
third_plugin::expand(&tmp2, &dst).unwrap();
breaking change derive

Most helpful comment

As I mentioned in in the other thread, I'm all for getting rid of serde_codegen::register.

All 3 comments

This seems like a worthwhile compromise to me. I'm betting that the number of projects that use more than one compiler plugin on stable is pretty small. (My main project actually does, but it's nightly-only, so this wouldn't affect me.)

The new serde_codegen::expand is in, but I am leaving this open until we either remove serde_codegen::register in a breaking release or decide to keep it.

As I mentioned in in the other thread, I'm all for getting rid of serde_codegen::register.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yamakaky picture Yamakaky  路  3Comments

mwu-tow picture mwu-tow  路  3Comments

sackery picture sackery  路  3Comments

pitkley picture pitkley  路  3Comments

dtolnay picture dtolnay  路  3Comments