Skip to content

Commit ed789cf

Browse files
committed
Use persistent codegen for SqlState and Type
Makes it easier to detect changes and speeds up the build.
1 parent f6c0ce1 commit ed789cf

File tree

13 files changed

+2519
-26
lines changed

13 files changed

+2519
-26
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/target/
1+
target/
22
Cargo.lock
33
.cargo/

Cargo.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ repository = "https://github.com/sfackler/rust-postgres"
88
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.3/postgres"
99
readme = "README.md"
1010
keywords = ["database", "postgres", "postgresql", "sql"]
11-
build = "build/main.rs"
12-
include = ["src/*", "build/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
11+
include = ["src/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
1312

1413
[lib]
1514
name = "postgres"
@@ -21,10 +20,6 @@ bench = false
2120
name = "test"
2221
path = "tests/test.rs"
2322

24-
[build-dependencies]
25-
phf_codegen = "0.7"
26-
regex = "0.1"
27-
2823
[dependencies]
2924
bufstream = "0.1"
3025
byteorder = ">= 0.3, < 0.5"

codegen/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "codegen"
3+
version = "0.1.0"
4+
authors = ["Steven Fackler <[email protected]>"]
5+
6+
[dependencies]
7+
phf_codegen = "0.7"
8+
regex = "0.1"
File renamed without changes.

build/main.rs renamed to codegen/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ extern crate phf_codegen;
22
extern crate regex;
33

44
use std::ascii::AsciiExt;
5+
use std::path::Path;
56

67
mod sqlstate;
78
mod types;
89

910
fn main() {
10-
sqlstate::build();
11-
types::build();
12-
13-
println!("cargo:rerun-if-changed=build");
11+
let path = Path::new("../src");
12+
sqlstate::build(path);
13+
types::build(path);
1414
}
1515

1616
fn snake_to_camel(s: &str) -> String {
File renamed without changes.
File renamed without changes.

build/sqlstate.rs renamed to codegen/src/sqlstate.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::env;
21
use std::fs::File;
32
use std::io::{Write, BufWriter};
43
use std::path::Path;
5-
use std::convert::AsRef;
64
use phf_codegen;
75

86
use snake_to_camel;
@@ -14,11 +12,8 @@ struct Code {
1412
variant: String,
1513
}
1614

17-
pub fn build() {
18-
let path = env::var_os("OUT_DIR").unwrap();
19-
let path: &Path = path.as_ref();
20-
let path = path.join("sqlstate.rs");
21-
let mut file = BufWriter::new(File::create(&path).unwrap());
15+
pub fn build(path: &Path) {
16+
let mut file = BufWriter::new(File::create(path.join("error/sqlstate.rs")).unwrap());
2217

2318
let codes = parse_codes();
2419

build/types.rs renamed to codegen/src/types.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use regex::Regex;
22
use std::ascii::AsciiExt;
33
use std::collections::BTreeMap;
4-
use std::env;
54
use std::fs::File;
65
use std::io::{Write, BufWriter};
76
use std::path::Path;
@@ -19,11 +18,8 @@ struct Type {
1918
doc: String,
2019
}
2120

22-
pub fn build() {
23-
let path = env::var_os("OUT_DIR").unwrap();
24-
let path: &Path = path.as_ref();
25-
let path = path.join("type.rs");
26-
let mut file = BufWriter::new(File::create(&path).unwrap());
21+
pub fn build(path: &Path) {
22+
let mut file = BufWriter::new(File::create(path.join("types/types.rs")).unwrap());
2723

2824
let ranges = parse_ranges();
2925
let types = parse_types(&ranges);

src/error.rs renamed to src/error/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111

1212
use {Result, DbErrorNew};
1313

14-
include!(concat!(env!("OUT_DIR"), "/sqlstate.rs"));
14+
include!("sqlstate.rs");
1515

1616
/// A Postgres error or notice.
1717
#[derive(Clone, PartialEq, Eq)]

0 commit comments

Comments
 (0)