Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Improved build scripts according to #12
Browse files Browse the repository at this point in the history
  • Loading branch information
White-Oak committed Oct 14, 2016
1 parent af2c63e commit b5846b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
32 changes: 26 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
use std::env;
use std::process::Command;
use std::path::*;

use std::str::*;
use std::fs;

fn is_dylib() -> bool {
option_env!("DyLib_DOtherSide").is_some()
}

fn main() {
if is_dylib() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
fs::copy(Path::new(&manifest_dir).join("build_lib.sh"), Path::new(&out_dir).join("build_lib.sh")).unwrap();
// Probably should unify this code
let output = if is_dylib() {
Command::new("sh")
.current_dir(&out_dir)
.arg("build_lib.sh")
.env("IS_DYLIB", "1")
.output()
.unwrap_or_else(|e| panic!("failed to execute process: {}", e));
.unwrap_or_else(|e| panic!("failed to execute process: {}", e))
} else {
Command::new("sh")
.current_dir(&out_dir)
.arg("build_lib.sh")
.output()
.unwrap_or_else(|e| panic!("failed to execute process: {}", e));
.unwrap_or_else(|e| panic!("failed to execute process: {}", e))
};

if !output.status.success() {
panic!("Cannot build qrc resource:\n{:#?}\n{:#?}",
to_utf(&output.stdout),
to_utf(&output.stderr));
}
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path = Path::new(&manifest_dir).join("DOtherSide").join("build").join("lib");

let path = Path::new(&out_dir).join("DOtherSide").join("build").join("lib");

println!("cargo:rustc-link-search=native={}", path.display());
println!("cargo:rerun-if-changed={}", path.display());
Expand All @@ -45,3 +58,10 @@ fn main() {
println!("cargo:rustc-link-lib{}=Qt{}{}", osx_framework, linux_qt_lib_ver, plugin);
}
}

fn to_utf(buf: &[u8]) -> &str {
match from_utf8(buf) {
Ok(v) => v,
Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
}
}
3 changes: 3 additions & 0 deletions build_lib.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
set -e
rm -rf DOtherSide
git clone https://github.com/filcuc/DOtherSide.git --single-branch --depth 1
cd DOtherSide
rm -rf build
Expand Down

0 comments on commit b5846b1

Please sign in to comment.