-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.ts
114 lines (97 loc) · 2.59 KB
/
build.ts
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
109
110
111
112
113
114
// Copyright 2022 Tristan Isham. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
import { Tar } from "https://deno.land/[email protected]/archive/mod.ts";
import { copy } from "https://deno.land/[email protected]/streams/copy.ts";
// Command to count final build results
// find ./build -type f \( -name "*.tar" -o -name "*.zip" \) | wc -l
const GOARCH = [
"amd64",
"arm64",
];
const GOOS = [
"windows",
"linux",
"darwin",
"freebsd",
"netbsd",
"openbsd",
"plan9",
"solaris",
];
await Deno.mkdir("./build", { recursive: true });
console.time("Built zvm");
Deno.env.set("CGO_ENABLED", "0");
// Compile step
for (const os of GOOS) {
for (const ar of GOARCH) {
if (os == "solaris" && ar == "arm64" || os == "plan9" && ar == "arm64") {
continue;
}
Deno.env.set("GOOS", os);
Deno.env.set("GOARCH", ar);
const zvm_str = `zvm-${os}-${ar}`;
console.time(`Build zvm: ${zvm_str}`);
const build_cmd = new Deno.Command("go", {
args: [
"build",
"-o",
`build/${zvm_str}/zvm${os === "windows" ? ".exe" : ""}`,
"-ldflags=-w -s",
"-trimpath",
],
});
const { code, stderr } = await build_cmd.output();
if (code !== 0) {
console.error(new TextDecoder().decode(stderr));
Deno.exit(1);
}
// if (os == "windows") {
// await Deno.mkdir(zvm_str, { recursive: true });
//
// }
console.timeEnd(`Build zvm: ${zvm_str}`);
}
}
// Bundle step
Deno.chdir("build");
for (const os of GOOS) {
for (const ar of GOARCH) {
if (os == "solaris" && ar == "arm64" || os == "plan9" && ar == "arm64") {
continue;
}
const zvm_str = `zvm-${os}-${ar}`;
/**
* Windows
*/
if (os === "windows") {
console.time(`Compress zvm (zip): ${zvm_str}`);
const zip = new Deno.Command(`zip`, {
args: [
`${zvm_str}.zip`,
`${zvm_str}/zvm.exe`,
`${zvm_str}/elevate.cmd`,
`${zvm_str}/elevate.vbs`,
],
stdin: "piped",
stdout: "piped",
});
zip.spawn();
console.timeEnd(`Compress zvm (zip): ${zvm_str}`);
continue;
}
const tar = new Tar();
console.time(`Compress zvm (tar): ${zvm_str}`);
await tar.append("zvm", {
filePath: `${zvm_str}/zvm`,
});
const writer = await Deno.open(`./${zvm_str}.tar`, {
write: true,
create: true,
});
await copy(tar.getReader(), writer);
writer.close();
console.timeEnd(`Compress zvm (tar): ${zvm_str}`);
}
}
console.timeEnd(`Built zvm`);