-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
34 lines (26 loc) · 1.02 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
use std::fs;
fn main() {
let workspace_cargo_toml = read_cargo_toml("Cargo.toml");
let frontend_cargo_toml = read_cargo_toml("frontend/Cargo.toml");
let frontend_version = get_package_version(&frontend_cargo_toml).as_str().unwrap();
let backend_uses_workspace_version = get_package_version(&workspace_cargo_toml)
.get("workspace")
.unwrap()
.as_bool()
.unwrap();
assert!(backend_uses_workspace_version);
let workspace_version = get_package_version(workspace_cargo_toml.get("workspace").unwrap())
.as_str()
.unwrap();
// Check if versions are the same
assert_eq!(
workspace_version, frontend_version,
"Versions are not the same: workspace = {workspace_version} vs. frontend = {frontend_version}"
);
}
fn read_cargo_toml(path: &str) -> toml::Value {
fs::read_to_string(path).unwrap().parse().unwrap()
}
fn get_package_version(cargo_toml: &toml::Value) -> &toml::Value {
cargo_toml.get("package").unwrap().get("version").unwrap()
}