-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
155 lines (139 loc) · 6.4 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#![allow(
non_upper_case_globals,
non_camel_case_types,
non_snake_case,
dead_code
)]
#![warn(unused_variables)]
extern crate bindgen;
use os_info;
use std::env;
use std::fs::File;
use std::path::PathBuf;
use std::process::Command;
// WINDOWS
fn link_libs_windows() {
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
// The compiled libraries have been copied out of PJPROJECT to pjproject-sys/pjlibs/
println!("cargo:rustc-link-search={}/pjlibs/windows", project_dir);
println!("cargo:rustc-link-lib=static=libpjproject-x86_64-x64-vc14-Release");
println!("cargo:rustc-link-lib=static=Ole32");
}
// UNIX
fn link_libs_unix() {
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
// The compiled libraries have been copied out of PJPROJECT to pjproject-sys/pjlibs/
println!("cargo:rustc-link-search={}/pjlibs/linux", project_dir);
println!(
"cargo:rustc-link-search={}/pjlibs/linux/extras",
project_dir
);
//Libraries inside PJPROEJCT
println!("cargo:rustc-link-lib=pjsua-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjsip-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pj-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjsip-simple-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjsua2-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjsip-ua-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjmedia-codec-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjsdp-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjmedia-videodev-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjmedia-audiodev-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjmedia-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjnath-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=pjlib-util-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=yuv-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=ilbccodec-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=g7221codec-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=gsmcodec-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=resample-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=srtp-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=webrtc-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=speex-x86_64-unknown-linux-gnu");
println!("cargo:rustc-link-lib=ssl");
println!("cargo:rustc-link-lib=crypto");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-link-lib=asound");
}
// MAC_OS
fn link_libs_macos() {
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
// Need to include this so I can call core functions and security functions on mac
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=Security");
println!("cargo:rustc-link-search={}/pjlibs/mac_os", project_dir);
println!("cargo:rustc-link-lib=pjsua-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjsip-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pj-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjsip-simple-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjsua2-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjsip-ua-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjmedia-codec-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjsdp-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjmedia-videodev-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjmedia-audiodev-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjmedia-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjnath-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=pjlib-util-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=yuv-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=ilbccodec-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=g7221codec-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=gsmcodec-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=resample-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=srtp-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=webrtc-x86_64-apple-darwin17.7.0");
println!("cargo:rustc-link-lib=speex-x86_64-apple-darwin17.7.0");
}
fn generate_bindings() {
let bindings = bindgen::Builder::default()
.clang_arg("-I./pjproject/pjlib/include")
.clang_arg("-I./pjproject/pjsip/include")
.clang_arg("-I./pjproject/pjlib-util/include")
.clang_arg("-I./pjproject/pjmedia/include")
.clang_arg("-I./pjproject/pjnath/include")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_SUBNORMAL")
.blocklist_item("FP_NORMAL")
.derive_debug(true)
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
pub fn main() {
//1. Fetch pjproject
let curr_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
Command::new("git")
.arg("submodule")
.arg("update")
.arg("--init")
.current_dir(&curr_dir)
.status()
.unwrap();
//2. Create config_site.h (so bindgen doesnt complain about missing header files)
let file = File::create("pjproject/pjlib/include/pj/config_site.h");
match file {
Ok(_x) => println!("config_site.h created"),
Err(_x) => {
println!("config_site.h not created, Error!");
panic!("config_site.h not created, Error!");
}
};
//3. Determine OS and Link Libraries Accordingly
let info = os_info::get();
if info.os_type() == os_info::Type::Windows {
link_libs_windows();
} else if (info.os_type() == os_info::Type::Linux) || (info.os_type() == os_info::Type::Ubuntu)
{
link_libs_unix();
} else if info.os_type() == os_info::Type::Macos {
link_libs_macos();
}
//4. Produce bindings.rs file
generate_bindings();
}