1use mcai_license::McaiWorkerLicense;
27use std::{io::Write, str::FromStr};
28
29pub fn build_mcai_info() {
30 let manifest = cargo_toml::Manifest::from_path("./Cargo.toml").unwrap();
31 if let Some(inherited_license) = manifest.package.clone().unwrap().license {
32 if let Ok(license) = inherited_license.get() {
33 if let Err(error) = McaiWorkerLicense::from_str(license) {
34 println!("cargo:warning={}. Possible values: 'Commercial', 'Private' or a SPDX Open Source license identifier.", error);
35 }
36 } else {
37 println!("cargo:warning=License field is not properly inherited");
38 }
39 } else {
40 println!("cargo:warning=License field is mandatory for MCAI workers");
41 }
42 let package = serde_json::to_string(&manifest.package).unwrap();
43 let dst = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("mcai_build.rs");
44 let mut built_file = std::fs::File::create(dst).unwrap();
45 let content = format!("serde_json::from_str(r#\"{}\"#).unwrap()", package);
46 built_file.write_all(content.as_bytes()).unwrap();
47 println!("cargo:rerun-if-changed=build.rs")
48}