-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
66 lines (56 loc) · 1.6 KB
/
Copy pathbuild.rs
File metadata and controls
66 lines (56 loc) · 1.6 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
64
65
66
use std::env;
use std::path::Path;
use std::process::Command;
extern crate napi_build;
macro_rules! join {
($start: expr $(, $join: expr)*) => {
Path::new($start)
$(.join($join))*
};
}
fn main() {
let in_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let status = Command::new("zig")
.arg("build-lib")
.arg("-O")
.arg("ReleaseSmall")
.arg("-static")
.arg("-target")
.arg(match_target(&target_arch, &target_os))
.arg(format!(
"-femit-bin={}",
Path::display(&join!(&out_dir, "libzig-dxt.a"))
))
.arg(dbg!(join!(&in_dir, "zig-lib", "dxt", "lib.zig")))
.status()
.expect("Failed to compile Zig code");
if !status.success() {
panic!("Zig compilation failed! status -> {}", status);
}
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=zig-dxt");
napi_build::setup();
}
fn match_target(arch: &str, os: &str) -> String {
if arch == "wasm32" {
return String::from("wasm32-freestanding");
}
format!("{}-{}", map_arch(arch), map_os(os))
}
fn map_arch(input: &str) -> &str {
match input {
"i686" => "x86",
"armv7" => "arm",
_ => input,
}
}
fn map_os(input: &str) -> &str {
match input {
"darwin" => "macos",
"android" | "androideabi" => "linux",
_ => input,
}
}