-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun_build.js
executable file
·89 lines (72 loc) · 1.61 KB
/
run_build.js
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
#!/usr/bin/env -S deno run -A
// build-deno-1.36/run_build.js
console.log("run_build.js");
let exe_file = Deno.args[0];
let env = Deno.env.toObject();
console.log(exe_file);
console.log(JSON.stringify(env, "", " "));
// command to run
let cmd = [
`cd ${Deno.cwd()}`,
];
// pass env var
let env_list = [
"TARGET",
"PROFILE",
"OUT_DIR",
"HOST",
"CARGO_MANIFEST_DIR",
];
for (let i of env_list) {
cmd.push(`export ${i}=${env[i]}`);
}
let is_android = env["TARGET"].includes("android");
if (is_android) {
// fix `libz.so`
cmd.push("export LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib/");
}
// DEBUG
cmd.push("export RUST_BACKTRACE=1");
// run build.rs
cmd.push(exe_file);
// docker image name
function get_img(target) {
if ("aarch64-linux-android" == target) {
return "termux/termux-docker:aarch64";
} else if ("x86_64-linux-android" == target) {
return "termux/termux-docker:x86_64";
} else if ("aarch64-unknown-linux-gnu" == target) {
return "arm64v8/debian:bookworm-slim";
}
}
let workdir = env["WORKDIR"];
let cargo_dir = env["CARGO_DIR"];
// docker run
let args = [
"run",
"--rm",
"--privileged",
"--mount",
`type=bind,src=${workdir},target=${workdir}`,
"--mount",
`type=bind,src=${cargo_dir},target=${cargo_dir}`,
];
if (is_android) {
args = args.concat([
"--entrypoint",
"/entrypoint_root.sh",
]);
}
args = args.concat([
get_img(env["TARGET"]),
"bash",
"-c",
cmd.join(" && "),
]);
// DEBUG
console.log("RUN docker " + JSON.stringify(args));
let p = new Deno.Command("docker", {
args,
}).spawn();
let { code } = await p.status;
Deno.exit(code);