#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_logo_url = "https://raw.githubusercontent.com/ifiokjr/gelx/main/setup/assets/logo.png")]
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/readme.md"))]
use std::env;
use std::path::PathBuf;
pub use gelx_core::GelxCoreError;
pub use gelx_core::GelxCoreResult;
pub use gelx_core::GelxMetadata;
pub use tokio;
use tokio::fs;
use tokio::runtime::Runtime;
pub async fn gelx_build() -> GelxCoreResult<GelxMetadata> {
let manifest_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
let cargo_toml_path = manifest_dir.join("Cargo.toml");
println!("cargo::rerun-if-changed={}", cargo_toml_path.display());
let cargo_toml_contents = fs::read_to_string(&cargo_toml_path).await?;
let metadata = GelxMetadata::try_from(&cargo_toml_contents).unwrap_or_default();
set_metadata_env(&metadata)?;
Ok(metadata)
}
pub fn set_metadata_env(metadata: &GelxMetadata) -> GelxCoreResult<()> {
let metadata_base64 = metadata.try_to_base64()?;
println!("cargo::rustc-env=GELX_METADATA_BASE64={metadata_base64}");
Ok(())
}
pub fn gelx_build_sync() -> GelxCoreResult<GelxMetadata> {
let rt = Runtime::new()?;
rt.block_on(async { gelx_build().await })
}