Maraiah/tycho/build.rs

83 lines
1.8 KiB
Rust
Raw Normal View History

use std::{io::prelude::*, path::{Path, PathBuf}};
2019-06-09 13:02:26 -07:00
fn gen_bindings(out_dir: &Path)
2019-06-09 13:02:26 -07:00
{
2019-07-05 20:21:11 -07:00
use rust_qt_binding_generator::{configuration, generate_bindings};
2019-06-09 13:02:26 -07:00
2019-07-05 20:21:11 -07:00
let mut config = configuration::parse("bindings.json").unwrap();
2019-06-09 13:02:26 -07:00
2019-07-05 20:21:11 -07:00
config.overwrite_implementation = true;
config.cpp_file = out_dir.join("bindings.cc");
config.rust.dir = out_dir.to_path_buf();
2019-06-09 13:02:26 -07:00
2019-07-05 20:21:11 -07:00
generate_bindings(&config).unwrap();
}
2019-06-09 13:02:26 -07:00
fn cxx_build() -> PathBuf
{
2019-07-05 20:21:11 -07:00
let mut config = cmake::Config::new(".");
2019-06-09 13:02:26 -07:00
2019-07-05 20:21:11 -07:00
if cfg!(debug_assertions) {
config.cxxflag("-DTYCHO_DEBUG_ASSERTIONS");
}
2019-06-13 18:10:33 -07:00
2019-07-05 20:21:11 -07:00
config.build()
}
fn get_link_dirs(lnk: &Path) -> Vec<PathBuf>
{
2019-07-05 20:21:11 -07:00
let mut dirs = Vec::new();
2019-07-05 20:21:11 -07:00
let lnk = std::fs::File::open(lnk).unwrap();
let lnk = std::io::BufReader::new(lnk);
2019-07-05 20:21:11 -07:00
for path in lnk.lines() {
let path = PathBuf::from(path.unwrap());
let path = path.parent().unwrap();
2019-07-05 20:21:11 -07:00
let path = if cfg!(target_os = "macos") {
path.parent().unwrap()
} else {
path
};
2019-07-05 20:21:11 -07:00
dirs.push(path.to_path_buf());
}
2019-07-05 20:21:11 -07:00
dirs
}
fn main()
{
2019-07-05 20:21:11 -07:00
let (lty, dty, qtpre, cxx) = if cfg!(target_os = "macos") {
("framework", "framework", "Qt", "c++")
} else {
("dylib", "native", "Qt5", "stdc++")
};
2019-07-05 20:21:11 -07:00
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
2019-07-05 20:21:11 -07:00
gen_bindings(&out_dir);
2019-07-05 20:21:11 -07:00
let cxx_dir = cxx_build();
let lib_dir = cxx_dir.join("lib");
let etc_dir = cxx_dir.join("etc");
2019-07-05 20:21:11 -07:00
println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=static=maraiah-tycho-hermes");
2019-07-05 20:21:11 -07:00
let dirs = get_link_dirs(&etc_dir.join("link.txt"));
2019-07-05 20:21:11 -07:00
for path in dirs {
println!("cargo:rustc-link-search={}={}", dty, path.display());
}
2019-07-05 20:21:11 -07:00
println!("cargo:rustc-link-lib={}={}Core", lty, qtpre);
println!("cargo:rustc-link-lib={}={}Widgets", lty, qtpre);
println!("cargo:rustc-link-lib={}={}Gui", lty, qtpre);
2019-07-05 20:21:11 -07:00
println!("cargo:rustc-link-lib=dylib={}", cxx);
2019-06-09 13:02:26 -07:00
}
// EOF