compiler_llvm_builder/
lock.rs

1//!
2//! The ZKsync LLVM builder lock file.
3//!
4
5use anyhow::Context;
6use std::fs::File;
7use std::io::Read;
8use std::path::PathBuf;
9
10use serde::Deserialize;
11use serde::Serialize;
12
13///
14/// The lock file data.
15///
16/// This file describes the exact reference of the LLVM framework.
17///
18#[derive(Debug, Deserialize, Serialize)]
19pub struct Lock {
20    /// The LLVM repository URL.
21    pub url: String,
22    /// The LLVM repository branch.
23    pub branch: String,
24    /// The LLVM repository commit reference.
25    pub r#ref: Option<String>,
26}
27
28impl TryFrom<&PathBuf> for Lock {
29    type Error = anyhow::Error;
30
31    fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
32        let mut config_str = String::new();
33        let mut config_file =
34            File::open(path).with_context(|| format!("Error opening {:?} file", path))?;
35        config_file.read_to_string(&mut config_str)?;
36        Ok(toml::from_str(&config_str)?)
37    }
38}