aboutsummaryrefslogtreecommitdiff
path: root/syn/codegen/src/version.rs
blob: 9374624f0e392f503ef98924718fd7daf98d9631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use anyhow::Result;
use semver::Version;
use serde::Deserialize;

use std::fs;
use std::path::Path;

pub fn get() -> Result<Version> {
    let codegen_root = Path::new(env!("CARGO_MANIFEST_DIR"));
    let syn_cargo_toml = codegen_root.join("../Cargo.toml");
    let manifest = fs::read_to_string(syn_cargo_toml)?;
    let parsed: Manifest = toml::from_str(&manifest)?;
    Ok(parsed.package.version)
}

#[derive(Debug, Deserialize)]
struct Manifest {
    package: Package,
}

#[derive(Debug, Deserialize)]
struct Package {
    version: Version,
}