-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild_wasm.rs
43 lines (36 loc) · 1.2 KB
/
build_wasm.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
use std::{path::PathBuf, process::Command};
fn get_build_mode() -> &'static str {
if cfg!(debug_assertions) {
"debug"
} else {
"release"
}
}
fn main() {
let crate_dir: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_dir: PathBuf = crate_dir.parent().unwrap().parent().unwrap().to_path_buf();
let func_name = crate_dir.file_name().unwrap().to_string_lossy();
let src_file = crate_dir.join(format!("target/x86_64-unknown-none/{}/lib{}.so", get_build_mode(), func_name));
let dst_dir = workspace_dir.join(format!("target/{}", get_build_mode()));
if !dst_dir.exists() {
assert!(Command::new("mkdir")
.arg("-p")
.arg(&dst_dir)
.status()
.unwrap()
.success());
}
let dst_file = dst_dir.join(format!("lib{}.so", func_name));
if dst_file.is_symlink() {
return;
}
let mut ln_commd = Command::new("ln");
ln_commd.arg("-s");
ln_commd.args([src_file, dst_file.to_owned()]);
assert!(
ln_commd.status().unwrap().success(),
"ln -s failed, command: {:?}",
ln_commd
);
assert!(dst_file.is_symlink(), "build symbol link failed.")
}