-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
38 lines (28 loc) · 842 Bytes
/
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
extern crate napi_build;
fn main() -> Result<(), Box<dyn std::error::Error>> {
napi_build::setup();
// ------ CONFIGURE AXUM VERSION ------
let cargo_toml_path = std::path::Path::new("Cargo.toml");
let mut cargo_toml = String::new();
use std::io::Read;
std::fs::File::open(cargo_toml_path)?.read_to_string(&mut cargo_toml)?;
// Define the structure to hold the part of Cargo.toml that we are interested in
#[derive(serde::Deserialize)]
struct Config {
dependencies: Dependencies,
}
#[derive(serde::Deserialize)]
struct Dependencies {
axum: ExpandedConfig,
}
#[derive(serde::Deserialize)]
struct ExpandedConfig {
version: String,
}
let config: Config = toml::from_str(&cargo_toml)?;
println!(
"cargo:rustc-env=AXUM_VERSION={}",
config.dependencies.axum.version
);
Ok(())
}