-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
134 lines (121 loc) · 4.29 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
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
extern crate pkg_config;
extern crate cmake;
use std::process::Command;
use std::env;
use std::fs;
use std::path::Path;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
static VERSION: &str = "2.8.1";
fn build_unix() {
match pkg_config::find_library("freetype2") {
Ok(_) => return,
Err(_) => {
let freetype_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let freetype_native_dir = Path::new(&freetype_dir).join(&format!("freetype-{}", VERSION));
fs::create_dir(freetype_native_dir.join("objs")).is_ok();
#[cfg(unix)]
fs::set_permissions(freetype_native_dir.join("configure"), fs::Permissions::from_mode(0o755))
.unwrap();
Command::new("./configure")
.current_dir(&freetype_native_dir)
.arg("--without-bzip2")
.arg("--with-harfbuzz=no")
.arg("--enable-static=yes")
.arg("--enable-shared=no")
.arg("--with-zlib=no")
.status().unwrap();
Command::new("make")
.current_dir(&freetype_native_dir)
.status().unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("libfreetype.a");
fs::copy(freetype_native_dir.join("objs/.libs/libfreetype.a"),dest_path).unwrap();
println!("cargo:rustc-link-search=native={}",out_dir);
println!("cargo:link_search={}",out_dir);
println!("cargo:include_search={}",freetype_native_dir.join("include").to_str().unwrap());
}
}
}
fn build_windows() {
let dst = cmake::build("freetype-2.8.1");
let lib_dir = dst.join("lib");
println!("cargo:rustc-link-search=native={}", lib_dir.display());
#[cfg(debug_assertions)]
println!("cargo:rustc-link-lib=static=freetyped");
#[cfg(not(debug_assertions))]
println!("cargo:rustc-link-lib=static=freetype");
}
fn build_emscripten() {
match pkg_config::find_library("freetype2") {
Ok(_) => return,
Err(_) => {
let freetype_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let freetype_native_dir = Path::new(&freetype_dir).join(&format!("freetype-{}", VERSION));
fs::create_dir(freetype_native_dir.join("objs")).is_ok();
#[cfg(unix)]
fs::set_permissions(freetype_native_dir.join("configure"), fs::Permissions::from_mode(0o755))
.unwrap();
Command::new("./configure")
.current_dir(&freetype_native_dir)
.arg("--without-bzip2")
.arg("--with-harfbuzz=no")
.arg("--enable-static=yes")
.arg("--enable-shared=no")
.arg("--with-zlib=no")
.arg("--with-png=no")
.status()
.unwrap();
Command::new("make")
.arg("clean")
.current_dir(&freetype_native_dir)
.status().unwrap();
Command::new("make")
.current_dir(&freetype_native_dir)
.status().unwrap();
fs::copy(freetype_native_dir.join("objs").join("apinames"), freetype_native_dir.join("apinames")).unwrap();
Command::new("emconfigure")
.current_dir(&freetype_native_dir)
.arg("./configure")
.arg("--without-bzip2")
.arg("--with-harfbuzz=no")
.arg("--enable-static=yes")
.arg("--enable-shared=no")
.arg("--with-zlib=no")
.arg("--with-png=no")
.status().unwrap();
Command::new("emmake")
.arg("make")
.arg("clean")
.current_dir(&freetype_native_dir)
.status().unwrap();
fs::copy(freetype_native_dir.join("apinames"), freetype_native_dir.join("objs").join("apinames")).unwrap();
Command::new("emmake")
.arg("make")
.current_dir(&freetype_native_dir)
.status().unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("libfreetype.a");
fs::copy(freetype_native_dir.join("objs/.libs/libfreetype.a"),dest_path).unwrap();
println!("cargo:rustc-link-search=native={}",out_dir);
println!("cargo:link_search={}",out_dir);
println!("cargo:include_search={}",freetype_native_dir.join("include").to_str().unwrap());
}
}
}
fn main(){
let target_triple = env::var("TARGET").unwrap();
if target_triple.contains("linux") {
build_unix()
}else if target_triple.contains("darwin") {
build_unix()
}else if target_triple.contains("windows") {
build_windows()
}else if target_triple.contains("emscripten") {
build_emscripten()
}else if target_triple.contains("wasm32"){
build_emscripten()
}else{
panic!("target OS {} not suported yet", target_triple);
}
}