diff --git a/leela/Cargo.toml b/leela/Cargo.toml index 6161788..8985f2e 100644 --- a/leela/Cargo.toml +++ b/leela/Cargo.toml @@ -10,5 +10,5 @@ serde = "1.0" serde_yaml = "0.8" [[bin]] -name = "leela" +name = "maraiah-leela" path = "main.rs" diff --git a/tycho/Cargo.toml b/tycho/Cargo.toml index 3453c8a..374d611 100644 --- a/tycho/Cargo.toml +++ b/tycho/Cargo.toml @@ -13,5 +13,5 @@ maraiah = {path = ".."} rust_qt_binding_generator = {path = "../rust-qt-binding-generator"} [[bin]] -name = "tycho" +name = "maraiah-tycho" path = "source/main.rs" diff --git a/tycho/build.rs b/tycho/build.rs index d92eebb..523d583 100644 --- a/tycho/build.rs +++ b/tycho/build.rs @@ -1,5 +1,51 @@ -use rust_qt_binding_generator::*; -use std::{io::prelude::*, path::PathBuf}; +use std::{io::prelude::*, path::{Path, PathBuf}}; + +fn gen_bindings(out_dir: &Path) +{ + use rust_qt_binding_generator::{configuration, generate_bindings}; + + let mut config = configuration::parse("bindings.json").unwrap(); + + config.overwrite_implementation = true; + config.cpp_file = out_dir.join("bindings.cc"); + config.rust.dir = out_dir.to_path_buf(); + + generate_bindings(&config).unwrap(); +} + +fn cxx_build() -> PathBuf +{ + let mut config = cmake::Config::new("."); + + if cfg!(debug_assertions) { + config.cxxflag("-DTYCHO_DEBUG_ASSERTIONS"); + } + + config.build() +} + +fn get_link_dirs(lnk: &Path) -> Vec +{ + let mut dirs = Vec::new(); + + let lnk = std::fs::File::open(lnk).unwrap(); + let lnk = std::io::BufReader::new(lnk); + + for path in lnk.lines() { + let path = PathBuf::from(path.unwrap()); + let path = path.parent().unwrap(); + + let path = if cfg!(target_os = "macos") { + path.parent().unwrap() + } else { + path + }; + + dirs.push(path.to_path_buf()); + } + + dirs +} fn main() { @@ -11,42 +57,18 @@ fn main() let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - let mut config = configuration::parse("bindings.json").unwrap(); + gen_bindings(&out_dir); - config.overwrite_implementation = true; - config.cpp_file = out_dir.join("bindings.cc"); - config.rust.dir = out_dir; - - generate_bindings(&config).unwrap(); - - let mut config = cmake::Config::new("."); - - if cfg!(debug_assertions) { - config.cxxflag("-DTYCHO_DEBUG_ASSERTIONS"); - } - - let out_dir = config.build(); - let lib_dir = out_dir.join("lib"); - let etc_dir = out_dir.join("etc"); + let cxx_dir = cxx_build(); + let lib_dir = cxx_dir.join("lib"); + let etc_dir = cxx_dir.join("etc"); println!("cargo:rustc-link-search=native={}", lib_dir.display()); println!("cargo:rustc-link-lib=static=maraiah-tycho-hermes"); - let fp = std::fs::File::open(etc_dir.join("link.txt")).unwrap(); - let fp = std::io::BufReader::new(fp); - - for ln in fp.lines() { - let ln = ln.unwrap(); - - let path = PathBuf::from(&ln); - let path = path.parent().unwrap(); - - let path = if cfg!(target_os = "macos") { - path.parent().unwrap() - } else { - path - }; + let dirs = get_link_dirs(&etc_dir.join("link.txt")); + for path in dirs { println!("cargo:rustc-link-search={}={}", dty, path.display()); }