This repository was archived by the owner on Oct 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
63 lines (50 loc) · 1.87 KB
/
build.rs
File metadata and controls
63 lines (50 loc) · 1.87 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
use std::env;
use std::str::FromStr;
fn main() {
link_libflutter_engine();
}
fn link_libflutter_engine() {
link_libgl();
let flutter_engine_config = match env::var("FLUTTER_ENGINE") {
Ok(config) => FlutterEngineConfig::from_str(&config).unwrap_or(FlutterEngineConfig::Debug),
Err(_) => FlutterEngineConfig::Debug,
};
let libflutter_engine_dirs = "third_party/flutter_engine";
let libflutter_engine_dir = match flutter_engine_config {
FlutterEngineConfig::Debug => format!("{libflutter_engine_dirs}/debug"),
FlutterEngineConfig::Profile => format!("{libflutter_engine_dirs}/profile"),
FlutterEngineConfig::Release => format!("{libflutter_engine_dirs}/release"),
};
println!("cargo:rerun-if-changed={libflutter_engine_dir}");
println!("cargo:rustc-link-search={libflutter_engine_dir}");
println!("cargo:rustc-link-lib=flutter_engine");
let rpath = if option_env!("BUNDLE").is_some() {
"$ORIGIN/lib"
} else {
&libflutter_engine_dir
};
println!("cargo:rustc-link-arg=-Wl,-rpath={rpath}");
}
fn link_libgl() {
// libflutter_engine.so uses libGL.so, not the Rust code.
// rustc has no idea and thinks libGL.so is not needed.
// --no-as-needed is needed to force the linker to link libGL.so.
// We manually put -lGL here because `println!("cargo:rustc-link-lib=GL")` doesn't work.
println!("cargo:rustc-link-arg=-Wl,--no-as-needed,-lGL");
}
enum FlutterEngineConfig {
Debug,
Profile,
Release,
}
impl FromStr for FlutterEngineConfig {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"debug" => Ok(FlutterEngineConfig::Debug),
"profile" => Ok(FlutterEngineConfig::Profile),
"release" => Ok(FlutterEngineConfig::Release),
_ => Err(()),
}
}
}