Skip to content

Commit 1160ddb

Browse files
committed
Add serde_codegen and build script for stable Rust
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
1 parent ea2cc7b commit 1160ddb

File tree

4 files changed

+400
-371
lines changed

4 files changed

+400
-371
lines changed

Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
name = "ladaemon"
33
version = "0.1.0"
44
authors = ["Dirkjan Ochtman <[email protected]>"]
5+
build = "build.rs"
6+
7+
[build-dependencies]
8+
serde_codegen = "0.7.10"
59

610
[dependencies]
711
docopt = "0.6.81"
@@ -14,7 +18,8 @@ rand = "0.3.14"
1418
redis = "0.5.3"
1519
router = "0.1.1"
1620
rustc-serialize = "0.3.19"
17-
serde_json = "0.7.0"
21+
serde = "0.7.10"
22+
serde_json = "0.7.1"
1823
time = "0.1.35"
1924
url = "1.1.0"
2025
urlencoded = "0.3.0"

build.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Stable Rust 1.9 doesn't support the custom_derive feature, so we generate
2+
// code for structures which #[derive] Serde's Serialize/Deserialize traits.
3+
4+
extern crate serde_codegen;
5+
6+
use std::env;
7+
use std::path::Path;
8+
9+
pub fn main() {
10+
let out_dir = env::var_os("OUT_DIR").unwrap();
11+
12+
let src = Path::new("src/lib.rs.in");
13+
let dst = Path::new(&out_dir).join("lib.rs");
14+
15+
serde_codegen::expand(&src, &dst).unwrap();
16+
}

0 commit comments

Comments
 (0)