// Copyright 2021 - developers of the `tdlib-rs` project. // Copyright 2020 - developers of the `grammers` project. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use std::env; use std::fs::File; use std::io::{self, BufWriter, Read, Write}; use std::path::Path; use tdlib_tl_gen::generate_rust_code; use tdlib_tl_parser::parse_tl_file; use tdlib_tl_parser::tl::Definition; /// Load the type language definitions from a certain file. /// Parse errors will be printed to `stderr`, and only the /// valid results will be returned. fn load_tl(file: &str) -> io::Result> { let mut file = File::open(file)?; let mut contents = String::new(); file.read_to_string(&mut contents)?; Ok(parse_tl_file(contents) .into_iter() .filter_map(|d| match d { Ok(d) => Some(d), Err(e) => { eprintln!("TL: parse error: {:?}", e); None } }) .collect()) } fn main() -> std::io::Result<()> { // Prevent linking libraries to avoid documentation failure #[cfg(not(feature = "dox"))] system_deps::Config::new().probe().unwrap(); let definitions = load_tl("tl/api.tl")?; let mut file = BufWriter::new(File::create( Path::new(&env::var("OUT_DIR").unwrap()).join("generated.rs"), )?); generate_rust_code(&mut file, &definitions, cfg!(feature = "bots-only-api"))?; file.flush()?; Ok(()) }