-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuild.rs
More file actions
172 lines (139 loc) · 4.64 KB
/
build.rs
File metadata and controls
172 lines (139 loc) · 4.64 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#![allow(unused_variables)]
// extern crate bindgen;
extern crate make_cmd;
extern crate autotools;
use make_cmd::make;
use std::env;
use std::path::Path;
use std::fs::canonicalize;
use std::process::Command;
use autotools::Config;
const LIBSIXEL_DIR: &str = "libsixel";
fn main() {
let testing_build = false;
let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir);
if testing_build {
return;
}
let curl = has_feature("curl");
let jpeg = has_feature("jpeg");
let pixbuf = has_feature("pixbuf");
let png = has_feature("png");
let gd = has_feature("gd");
let python_interface = has_feature("python_interface");
let sixel_dir = Path::new(LIBSIXEL_DIR);
let sixel_build_dir = sixel_dir.join("build");
let sixel_build_dir_prefix = if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
println!("cargo::warning=Detected Windows compilation. Attempting to use MinGW compilers.");
sixel_prefix("build")
} else { sixel_build_dir.clone().into_os_string().into_string().expect("Could not convert OS path to utf8") };
{
let mut bld = Config::new("libsixel");
if curl {
bld.with("libcurl", None);
} else {
bld.without("libcurl", None);
}
if gd {
bld.with("gd", None);
} else {
bld.without("gd", None);
}
if pixbuf {
bld.with("gdk-pixbuf", None);
} else {
bld.without("gdk-pixbuff", None);
}
if jpeg {
bld.with("jpeg", None);
} else {
bld.without("jpeg", None);
}
if png {
bld.with("png", None);
println!("cargo::warning=WITH PNG");
} else {
println!("cargo::warning=WITHOUT PNG");
bld.without("png", None);
}
if python_interface {
bld.enable("python", None);
} else {
bld.disable("python", None);
}
let dst = bld
.reconf("-ivf")
.build();
println!("cargo::warning={}", dst.display());
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=static=sixel");
}
/*{
let mut cmd = Command::new("sh");
cmd.current_dir(sixel_dir)
.arg("configure")
.arg("--prefix")
.arg(sixel_build_dir_prefix.clone());
//cmd.arg("-fPIC");
if curl {
cmd.arg("--with-libcurl");
}
if gd {
cmd.arg("--with-gd");
}
if pixbuf {
cmd.arg("--with-gdk-pixbuf");
}
if jpeg {
cmd.arg("--with-jpeg");
}
if png {
cmd.arg("--with-png");
}
if python_interface {
cmd.arg("--enable-python");
}
cmd.status().expect("Failed to execute ./configure");
make()
.arg("install")
.current_dir(sixel_dir)
.status().expect("Failed to execute make");
}
//println!("cargo::warning=p1: {}", canonicalize(&sixel_build_dir_prefix).unwrap().display());
println!("cargo::warning=p2: {}", canonicalize(&sixel_build_dir.join("lib")).unwrap().display());
// generate_bindings(out_dir);
println!("cargo:rustc-link-lib=static=sixel");
// println!("cargo:rustc-link-lib=static=sixel");
println!("cargo:rustc-link-search=native={}", canonicalize(&sixel_build_dir).unwrap().display()); //out_dir.join(".libs").display());
println!("cargo:rustc-link-search=native={}", canonicalize(&sixel_build_dir.join("lib")).unwrap().display()); //out_dir.join(".libs").display());
*/
}
// fn generate_bindings(out_dir: &Path) {
// let bindings = bindgen::Builder::default()
// .no_unstable_rust()
// .header("wrapper.h")
// .hide_type("max_align_t")
// .generate()
// .expect("Unable to generate bindings");
//
// bindings
// .write_to_file(out_dir.join("bindings.rs"))
// .expect("Couldn't write bindings");
// }
const FEATURE_PREFIX: &str = "CARGO_FEATURE_";
fn has_feature(feature: &'static str) -> bool {
let feature = feature.to_owned().to_uppercase();
let mut name = FEATURE_PREFIX.to_owned();
name.push_str(&feature);
env::var(name).is_ok()
}
fn sixel_prefix(directory: &str) -> String {
let cmd = Command::new("pwd").output().expect("Could not run `pwd`");
let base_path = std::str::from_utf8(&cmd.stdout)
.expect("Could not turn libsixel path into utf8")
.trim()
.to_string();
let path = base_path + "/" + LIBSIXEL_DIR + "/" + "build";
path
}