This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.rs
108 lines (99 loc) · 3.15 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
use std::{collections::HashSet, env, path::PathBuf, str::FromStr};
use flate2::read::GzDecoder;
use fs_extra::file::CopyOptions;
use tar::Archive;
use target_lexicon::{Architecture, Environment, OperatingSystem, Triple};
const PDFIUM_VERSION: &str = "5104";
fn main() {
let t = env::var("TARGET").unwrap();
let target = Triple::from_str(t.as_str()).unwrap();
let out_dir = env::var_os("OUT_DIR").unwrap();
println!("{}", target.operating_system);
// Avoid duplicate download
if !fs_extra::dir::ls(&out_dir, &HashSet::new())
.unwrap()
.items
.is_empty()
{
return;
}
let mut name = vec!["pdfium"];
match target.environment {
Environment::Android | Environment::Androideabi => {
// The prebuilt pdfium library is included in the arklib-android, no
// more fetching work needed.
name.push("android");
return;
}
_ => {}
}
match target.operating_system {
OperatingSystem::Windows => name.push("win"),
OperatingSystem::Linux => {
if target.environment != Environment::Android {
name.push("linux")
}
}
OperatingSystem::Ios => name.push("ios"),
OperatingSystem::MacOSX {
major: _,
minor: _,
patch: _,
} => name.push("mac"),
OperatingSystem::Darwin => name.push("mac"),
_ => {}
}
match target.architecture {
Architecture::Arm(_) => name.push("arm"),
Architecture::Aarch64(_) => name.push("arm64"),
Architecture::X86_32(_) => name.push("x86"),
Architecture::X86_64 => name.push("x64"),
_ => {}
}
dbg!(&name);
let filename = name.join("-");
let url = format!(
"https://github.com/bblanchon/pdfium-binaries/releases/download/chromium/{}/{}.tgz",
PDFIUM_VERSION, filename
);
let request = ureq::get(url.as_str())
.call()
.unwrap()
.into_reader();
let ar = GzDecoder::new(request);
let mut ar = Archive::new(ar);
ar.unpack(&out_dir).unwrap();
match target.operating_system {
OperatingSystem::Windows => fs_extra::file::move_file(
PathBuf::from(&out_dir)
.join("bin")
.join("pdfium.dll"),
PathBuf::from(&out_dir).join("pdfium.dll"),
&CopyOptions::new(),
)
.unwrap(),
OperatingSystem::Ios
| OperatingSystem::MacOSX {
major: _,
minor: _,
patch: _,
}
| OperatingSystem::Darwin => fs_extra::file::move_file(
PathBuf::from(&out_dir)
.join("bin")
.join("libpdfium.dylib"),
PathBuf::from(&out_dir).join("libpdfium.dylib"),
&CopyOptions::new(),
)
.unwrap(),
_ => fs_extra::file::move_file(
PathBuf::from(&out_dir)
.join("lib")
.join("libpdfium.so"),
PathBuf::from(&out_dir).join("libpdfium.so"),
&CopyOptions::new(),
)
.unwrap(),
};
println!("cargo:rerun-if-changed=build.rs");
}