-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.rs
53 lines (48 loc) · 1.8 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
use std::{collections::HashSet, env, ffi::OsStr, fs, path::PathBuf};
const C2RUST_DEPENDENCIES: &[(&str, &str)] = &[
("libc2rust_bitfields", "rlib"),
(
"libc2rust_bitfields_derive",
if cfg!(target_os = "macos") {
"dylib"
} else {
"so"
},
),
("liblibc", "rlib"),
("libf128_internal", "rlib"),
("libf128", "rlib"),
("libnum_traits", "rlib"),
("libcrown_annotation", "rlib"),
];
fn main() {
let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let extra_deps_dir = project_dir.join("extra_deps");
if extra_deps_dir.exists() {
fs::remove_dir_all(extra_deps_dir.as_path()).unwrap();
}
fs::create_dir(extra_deps_dir.as_path()).unwrap();
let profile = std::env::var("PROFILE").unwrap();
let deps_path = project_dir.join("target").join(profile).join("deps");
let mut lib_prepared: HashSet<&str> = HashSet::new();
for file in fs::read_dir(deps_path.as_path()).expect("dependency build error") {
let absolute_path = file.unwrap().path();
let path = absolute_path
.as_path()
.strip_prefix(deps_path.as_path())
.unwrap();
if let Some(lib_name) = path.file_stem().and_then(|stem| stem.to_str()) {
let lib_name = lib_name.split("-").next().unwrap();
for &(lib, lib_type) in C2RUST_DEPENDENCIES {
if lib_name == lib
&& path.extension() == Some(OsStr::new(lib_type))
&& !lib_prepared.contains(&lib)
{
lib_prepared.insert(lib);
fs::copy(absolute_path.as_path(), extra_deps_dir.join(path))
.expect("failed to prepare dependency");
}
}
}
}
}