-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild.rs
More file actions
55 lines (44 loc) · 1.39 KB
/
build.rs
File metadata and controls
55 lines (44 loc) · 1.39 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
fn main() {
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
compile_native_lib();
}
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
fn compile_native_lib() {
let src_dir = std::path::PathBuf::from("src/platform/bsd/native");
let mut c_files = Vec::new();
find_c_files(&src_dir, &mut c_files);
if c_files.is_empty() {
println!("cargo:warning=no C files found in {}", src_dir.display());
return;
}
let mut build = cc::Build::new();
for file in &c_files {
build.file(file);
}
build.include(&src_dir);
build.compile("bsd_native_lib");
for file in &c_files {
println!("cargo:rerun-if-changed={}", file.display());
}
println!("cargo:rerun-if-changed={}", src_dir.display());
}
#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
fn find_c_files(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {
if !dir.is_dir() {
return;
}
let Ok(entries) = std::fs::read_dir(dir) else {
return;
};
for entry in entries {
let Ok(entry) = entry else { continue };
let path = entry.path();
if path.is_dir() {
find_c_files(&path, out);
} else if let Some(ext) = path.extension()
&& ext == "c"
{
out.push(path);
}
}
}