tycho: restructure build script (again)

master
Alison G. Watson 2019-07-04 06:14:41 -04:00
parent cbd4ef0171
commit 8f975ad44b
3 changed files with 56 additions and 34 deletions

View File

@ -10,5 +10,5 @@ serde = "1.0"
serde_yaml = "0.8"
[[bin]]
name = "leela"
name = "maraiah-leela"
path = "main.rs"

View File

@ -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"

View File

@ -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<PathBuf>
{
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());
}