-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
150 lines (130 loc) · 5.91 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
use std::env;
use std::path::Path;
enum Platform {
Windows,
Mac,
// Linux,
}
fn get_platform() -> Platform {
match std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"windows" => Platform::Windows,
"macos" => Platform::Mac,
// "linux" => Platform::Linux,
other => panic!("Sorry, platform \"{}\" is not supported by CEF.", other),
}
}
fn choose_source_dir() -> Option<String> {
if let Ok(path) = env::var("CEF_ROOT") {
if Path::new(&path).exists() {
return Some(path);
}
}
// Check out `zaplib/main/bind/cef-sys/README.md` file for notes on the current CEF/Chromium version.
let cef_build = "cef_binary_91.1.23+g04c8d56+chromium-91.0.4472.164";
let default_path = match get_platform() {
Platform::Windows => Path::new(env!("CARGO_MANIFEST_DIR"))
.join("deps")
.join(format!("{}_windows64", cef_build)),
Platform::Mac => Path::new(env!("CARGO_MANIFEST_DIR"))
.join("deps")
.join(format!("{}_macosx64", cef_build)),
// TODO(Dmitry): switch linux version from minimal
// Platform::Linux => Path::new(env!("CARGO_MANIFEST_DIR")).join("deps").join(format!("{}_linux64_minimal", cef_build)),
};
if default_path.exists() {
return Some(default_path.to_str().unwrap().to_string());
}
None
}
fn main() {
let source_dir = "cef"; // choose_source_dir().expect("Failed to locate CEF lib path");
let input_header = "build/wrapper.hh";
// Inform rust what to link.
// match get_platform() {
// Platform::Windows => println!("cargo:rustc-link-lib=libcef"),
// Platform::Mac => println!("cargo:rustc-link-lib=framework=Chromium Embedded Framework"),
// // Platform::Linux => println!("cargo:rustc-link-lib=cef"),
// };
// link libcef
println!("cargo:rustc-link-lib=cef/lib/win/libcef");
// lazy load libcef
println!("cargo:rustc-cdylib-link-arg=/delayload:libcef.dll");
println!("cargo:rustc-cdylib-link-arg=delayimp.lib");
// export map
println!("cargo:rustc-cdylib-link-arg=/DEF:build/library.def");
// Generate bindings.rs.
println!("cargo:rerun-if-changed={}", input_header);
let bindings = bindgen::Builder::default()
.layout_tests(false)
.derive_debug(false)
.header(input_header)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.clang_arg("-I".to_string() + &source_dir)
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
})
.no_copy("_cef_string_utf16_t")
.allowlist_type("cef_.*")
.allowlist_type("_cef_.*")
.allowlist_function("cef_.*")
.bitfield_enum(".*_mask_t")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(Path::new(&env::var("OUT_DIR").unwrap()).join("cef_bindings.rs"))
.expect("Couldn't write bindings!");
// Get the "Release" dir, which contains the resources (or "Debug" when using the "debug" feature).
#[allow(unused_mut, unused_assignments)]
let mut release_dir = Path::new(&source_dir).join("Release");
#[cfg(feature = "debug")]
{
release_dir = Path::new(&source_dir).join("Debug");
}
// if !release_dir.exists() {
// panic!("CEF Release directory ({}) does not exist", release_dir.to_str().unwrap_or(""));
// }
// let opts = fs_extra::dir::CopyOptions {
// overwrite: true,
// skip_exist: false,
// buffer_size: 64000, // Default
// copy_inside: true,
// depth: 0,
// content_only: false,
// };
// if let Platform::Mac = get_platform() {
// // Add the release dir as a framework search path.
// if let Some(release_dir) = release_dir.to_str() {
// println!("cargo:rustc-link-search=framework={}", release_dir);
// }
// // Copy the framework to "../Frameworks" relative to the final executable, which is where it will
// // automatically get linked to. This is pretty brittle. TODO(JP): Figure out something better here,
// // e.g. absolute paths during debugging (at least that is more stable and seems to be done for system
// // frameworks) and "@rpath" for release builds? See also https://github.com/rust-lang/cargo/issues/5077.
// // Or keep the current behavior for release builds and put everything in the correct place in the final
// // `.app`.
// let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("../../../../Frameworks");
// if dest_path.exists() {
// fs_extra::remove_items(&[&dest_path]).unwrap();
// }
// let all_items = vec![release_dir.to_str().unwrap()];
// fs_extra::copy_items(&all_items, &dest_path, &opts).unwrap();
// } else {
// if let Some(release_dir) = release_dir.to_str() {
// println!("cargo:rustc-link-search=native={}", release_dir);
// }
// let resources_dir = Path::new(&source_dir).join("Resources");
// if !resources_dir.exists() {
// panic!("CEF Resources directory ({}) does not exist", resources_dir.to_str().unwrap_or(""));
// }
// // Copy the required Resources & Release contents to OUT_DIR so that a cargo run works.
// let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("../../..");
// let mut release_items = fs_extra::dir::get_dir_content(&release_dir).unwrap();
// let mut resources_items = fs_extra::dir::get_dir_content(&resources_dir).unwrap();
// let mut all_items = Vec::new();
// all_items.append(&mut release_items.directories);
// all_items.append(&mut release_items.files);
// all_items.append(&mut resources_items.directories);
// all_items.append(&mut resources_items.files);
// fs_extra::copy_items(&all_items, &dest_path, &opts).unwrap();
// }
}