forked from probe-rs/probe-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
38 lines (35 loc) · 1.09 KB
/
build.rs
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
31
32
33
34
35
36
37
38
fn main() {
generate_meta();
println!("cargo:rerun-if-changed=build.rs");
}
// Code below is currently copied between cargo-embed, cargo-flash and probe-rs-cli crates.
/// Generates a `meta.rs` file in a crates `OUT_DIR`.
///
/// This is intended to be used in the `build.rs` of a crate.
///
///
///
/// # Examples
///
/// ```no_run
/// probe_rs_cli_util::meta::generate_meta();
/// println!("cargo:rerun-if-changed=build.rs");
/// ```
pub fn generate_meta() {
const CARGO_VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_VERSION: &str = git_version::git_version!(fallback = "crates.io");
let long_version: String = format!("{CARGO_VERSION}\ngit commit: {GIT_VERSION}");
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let dest_path = std::path::Path::new(&out_dir).join("meta.rs");
std::fs::write(
dest_path,
format!(
r#"#[allow(dead_code)]mod meta {{
pub const CARGO_VERSION: &str = "{CARGO_VERSION}";
pub const GIT_VERSION: &str = "{GIT_VERSION}";
pub const LONG_VERSION: &str = "{long_version}";
}} "#
),
)
.unwrap();
}