Use persistent codegen for SqlState and Type

Makes it easier to detect changes and speeds up the build.
This commit is contained in:
Steven Fackler 2016-02-21 13:30:31 -08:00
parent f6c0ce1c40
commit ed789cfad8
13 changed files with 2519 additions and 26 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
/target/
target/
Cargo.lock
.cargo/

View File

@ -8,8 +8,7 @@ repository = "https://github.com/sfackler/rust-postgres"
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.3/postgres"
readme = "README.md"
keywords = ["database", "postgres", "postgresql", "sql"]
build = "build/main.rs"
include = ["src/*", "build/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
include = ["src/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
[lib]
name = "postgres"
@ -21,10 +20,6 @@ bench = false
name = "test"
path = "tests/test.rs"
[build-dependencies]
phf_codegen = "0.7"
regex = "0.1"
[dependencies]
bufstream = "0.1"
byteorder = ">= 0.3, < 0.5"

8
codegen/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "codegen"
version = "0.1.0"
authors = ["Steven Fackler <sfackler@gmail.com>"]
[dependencies]
phf_codegen = "0.7"
regex = "0.1"

View File

@ -2,15 +2,15 @@ extern crate phf_codegen;
extern crate regex;
use std::ascii::AsciiExt;
use std::path::Path;
mod sqlstate;
mod types;
fn main() {
sqlstate::build();
types::build();
println!("cargo:rerun-if-changed=build");
let path = Path::new("../src");
sqlstate::build(path);
types::build(path);
}
fn snake_to_camel(s: &str) -> String {

View File

@ -1,8 +1,6 @@
use std::env;
use std::fs::File;
use std::io::{Write, BufWriter};
use std::path::Path;
use std::convert::AsRef;
use phf_codegen;
use snake_to_camel;
@ -14,11 +12,8 @@ struct Code {
variant: String,
}
pub fn build() {
let path = env::var_os("OUT_DIR").unwrap();
let path: &Path = path.as_ref();
let path = path.join("sqlstate.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
pub fn build(path: &Path) {
let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap());
let codes = parse_codes();

View File

@ -1,7 +1,6 @@
use regex::Regex;
use std::ascii::AsciiExt;
use std::collections::BTreeMap;
use std::env;
use std::fs::File;
use std::io::{Write, BufWriter};
use std::path::Path;
@ -19,11 +18,8 @@ struct Type {
doc: String,
}
pub fn build() {
let path = env::var_os("OUT_DIR").unwrap();
let path: &Path = path.as_ref();
let path = path.join("type.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
pub fn build(path: &Path) {
let mut file = BufWriter::new(File::create(path.join("types/types.rs")).unwrap());
let ranges = parse_ranges();
let types = parse_types(&ranges);

View File

@ -11,7 +11,7 @@ use std::collections::HashMap;
use {Result, DbErrorNew};
include!(concat!(env!("OUT_DIR"), "/sqlstate.rs"));
include!("sqlstate.rs");
/// A Postgres error or notice.
#[derive(Clone, PartialEq, Eq)]

1022
src/error/sqlstate.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -149,7 +149,7 @@ impl FieldNew for Field {
}
}
include!(concat!(env!("OUT_DIR"), "/type.rs"));
include!("types.rs");
/// Information about an unknown type.
#[derive(PartialEq, Eq, Clone)]

1477
src/types/types.rs Normal file

File diff suppressed because it is too large Load Diff