Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/build.rs
8446 views
1
use std::env;
2
use std::io::Write;
3
use std::path::Path;
4
5
use sha2::Digest;
6
7
fn main() {
8
println!("cargo:rerun-if-changed=build.rs");
9
let channel = version_check::Channel::read().unwrap();
10
if channel.is_nightly() {
11
println!("cargo:rustc-cfg=feature=\"nightly\"");
12
}
13
14
generate_schema_hash();
15
}
16
17
/// Generate a hash of the schema hashes file, to be embedded in the binary.
18
///
19
/// Used in `SchemaHash` (crates/polars-plan/src/dsl/plan.rs) for DSL compatibility check.
20
fn generate_schema_hash() {
21
let hash_hexstr = {
22
let mut digest = sha2::Sha256::new();
23
// Read as UTF-8 text and normalize CRLF to LF to make hashing
24
// invariant to Git EOL conversion on Windows.
25
let content = include_str!("dsl-schema-hashes.json");
26
let normalized = content.replace("\r\n", "\n");
27
digest
28
.write_all(normalized.as_bytes())
29
.expect("failed to hash the schema hashes file");
30
let hash = digest.finalize();
31
32
format!("{hash:064x}")
33
};
34
35
let out_dir = env::var_os("OUT_DIR").unwrap();
36
let dst = Path::new(&out_dir).join("dsl-schema.sha256");
37
std::fs::write(dst, &hash_hexstr).expect("failed to write the schema hash file");
38
39
println!("cargo:rerun-if-changed=dsl-schema-hashes.json");
40
}
41
42