-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (22 loc) · 819 Bytes
/
build.rs
File metadata and controls
30 lines (22 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use rusqlite::Connection;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?;
let sql_path = Path::new(&manifest_dir)
.join("test_data")
.join("database.sql");
println!("cargo:rerun-if-changed={}", sql_path.display());
let sql = std::fs::read_to_string(&sql_path)?;
let out_dir_path = std::env::var("OUT_DIR")?;
let database_path = std::path::Path::new(&out_dir_path).join("test_database.sqlite");
if database_path.exists() {
std::fs::remove_file(&database_path)?;
}
let connection = Connection::open(&database_path)?;
connection.execute_batch(&sql)?;
println!(
"cargo:rustc-env=TEST_DATABASE_PATH={}",
database_path.display()
);
Ok(())
}