-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
37 lines (34 loc) · 1.27 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::path::Path;
use std::process::Command;
use std::{env, str};
fn command_ok(cmd: &mut Command) -> bool {
cmd.status().ok().map_or(false, |s| s.success())
}
fn command_output(cmd: &mut Command) -> String {
str::from_utf8(&cmd.output().unwrap().stdout)
.unwrap()
.trim()
.to_string()
}
fn main() {
if command_ok(Command::new("stack").arg("--version")) {
let ghc_lib =
command_output(Command::new("stack").args(&["exec", "--", "ghc", "--print-libdir"]));
let ghc_version =
command_output(Command::new("stack").args(&["exec", "--", "ghc", "--numeric-version"]));
let dir_path = env::current_dir().unwrap();
let path = dir_path.to_str().unwrap();
let ghc_lib_path = Path::new(&ghc_lib);
let rts_path = ghc_lib_path.join("rts");
println!("cargo:rustc-link-search=native={}/ext_lib/", path);
println!(
"cargo:rustc-link-search=native={}",
rts_path.to_str().unwrap()
);
println!("cargo:rustc-link-lib=dylib=ducklingffi");
println!("cargo:rustc-link-lib=dylib=HSrts-ghc{}", ghc_version);
println!("cargo:rustc-env=GHC_VERSION={}", ghc_version);
} else {
panic!("Stack was not found in the PATH")
}
}