Skip to content

Commit

Permalink
Add serde_codegen and build script for stable Rust
Browse files Browse the repository at this point in the history
This is necessary because stable Rust does not yet support custom #[derive]
implementations, which are needed for Serde's Serialize/Deserialize traits.

Serde has a macro package and compiler plugin which handle those, but compiler
plugins are *also* not availble in stable Rust, so we instead have to generate
code at build time using serde_codegen.

Bug for `custom_derive` feature: rust-lang/rust#29644

Bug for compiler plugins: rust-lang/rust#29597
  • Loading branch information
callahad committed Jun 26, 2016
1 parent ea2cc7b commit 1160ddb
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 371 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
name = "ladaemon"
version = "0.1.0"
authors = ["Dirkjan Ochtman <[email protected]>"]
build = "build.rs"

[build-dependencies]
serde_codegen = "0.7.10"

[dependencies]
docopt = "0.6.81"
Expand All @@ -14,7 +18,8 @@ rand = "0.3.14"
redis = "0.5.3"
router = "0.1.1"
rustc-serialize = "0.3.19"
serde_json = "0.7.0"
serde = "0.7.10"
serde_json = "0.7.1"
time = "0.1.35"
url = "1.1.0"
urlencoded = "0.3.0"
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Stable Rust 1.9 doesn't support the custom_derive feature, so we generate
// code for structures which #[derive] Serde's Serialize/Deserialize traits.

extern crate serde_codegen;

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

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");

serde_codegen::expand(&src, &dst).unwrap();
}
Loading

0 comments on commit 1160ddb

Please sign in to comment.