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
#[cfg(windows)]
use std::env;
#[cfg(windows)]
use std::path::PathBuf;
use std::cfg;
#[cfg(all(not(feature = "docs-only"), windows))]
fn find_dart_sdk() -> Option<PathBuf> {
if let Ok(path) = env::var("dart_sdk") {
Some(path.into())
} else {
//We'll look for either a flutter sdk _or_ a choco tool path.
if let Ok(path) = env::var("ChocolateyToolsLocation") {
let path = PathBuf::from(path).join("dart-sdk");
if let Ok(x) = std::fs::metadata(&path) {
if x.is_dir() {
return Some(path);
}
}
} else {
let paths: Vec<PathBuf> = env::split_paths(&std::env::var("Path").ok().expect("Could not find $PATH variable.")).collect();
for i in &paths {
if i.components().any(|x| x.as_os_str() == "dart-sdk") {
let mut path = i.clone();
while !path.is_dir() || path.file_name().unwrap() != "dart-sdk" {
path.pop();
}
if !path.as_os_str().is_empty() {
return Some(path);
}
}
}
for i in &paths {
if i.components().any(|x| x.as_os_str() == "flutter") {
let mut path = i.clone();
while !path.is_dir() || path.file_name().unwrap() != "flutter" {
path.pop();
}
if !path.as_os_str().is_empty() {
println!("cargo:warning=Using Flutter path by default. This is not recommended!");
return Some(path);
}
}
}
}
None
}
}
#[cfg(windows)]
fn emit_compiler_flags() {
let dart_path = match find_dart_sdk() {
Some(x) => x,
None => panic!("Could not find dart sdk!")
};
let dart_path = PathBuf::from(dart_path);
println!(r#"cargo:rustc-link-search=native={}"#, dart_path.join("bin").to_str().unwrap());
println!(r"cargo:rustc-link-lib=dart");
}
#[cfg(unix)]
fn emit_compiler_flags() {}
fn main() {
#[cfg(not(feature = "docs-only"))]
fn _main() {
emit_compiler_flags();
}
#[cfg(feature = "docs-only")]
fn _main() {}
_main();
// We're using the precompiled ones instead of using bindgen each time
// let bindings = bindgen::Builder::default()
// .header("./bindgen/wrapper.h")
// .clang_arg(format!("--include-directory={}", dart_path.join("include").to_str().unwrap()))
// .clang_arg("-DDART_SHARED_LIB")
// .generate()
// .expect("Unable to generate bindings.");
// let out_path = PathBuf::from(env::var("OUT_DIR").expect("Could not find OUT_DIR"));
// bindings
// .write_to_file(out_path.join("bindings.rs"))
// .expect("Couldn't write bindings!");
}