-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.d
89 lines (78 loc) · 2.17 KB
/
build.d
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 rdmd
module build;
/*
Simple script for building the game. Why not use:
dub: no WebAssembly, need to specify preferred architecture / compiler in flags
.bat / .sh scripts: I hate the syntax
make: not pre-installed on Windows
any of the other gazillion build systems: not pre-installed
*/
import std.process: ProcessException, execute;
import std.file: exists, mkdirRecurse;
import std.path: buildPath;
import std.stdio: writeln;
int main(string[] args) {
if (args.length == 2) {
switch (args[1]) {
case "wasm": return buildWasm();
case "cmd32": return buildCmd("x86");
case "cmd64": return buildCmd("x86_64");
default: break;
}
}
writeln("Usage: rdmd build [option]");
writeln("Options are:");
writeln(" cmd32 command line executible (32-bit)");
writeln(" cmd64 command line executible (64-bit)");
writeln(" wasm Webpage with Web Assembly");
return -1;
}
int buildCmd(string arch = "x86_64") {
auto path = buildPath("build");
if (exists(path)) {
mkdirRecurse(path);
}
auto result = execute(["dub", "build", "--compiler=ldc2", "--arch="~arch, "--build=release"]);
if (!result[0]) {
writeln("Build succesful");
writeln(result[1]);
writeln("Look in the folder '", path, "'");
} else {
writeln("Build failed:");
writeln(result[1]);
}
return 0;
}
int buildWasm() {
auto dest = "docs";
if (exists(dest)) {
mkdirRecurse(dest);
}
enum wasmOptions = [
"-mtriple=wasm32-unknown-unknown-wasm",
"-betterC",
"-link-internally",
"-L-allow-undefined",
];
enum releaseOptions = ["-O3", "-release"];
enum files = ["-Isource",
"source/app.d",
"source/jsdraw.d",
"source/game.d",
"source/util.d"
];
try {
auto result = execute(
["ldc2", "-of="~dest~"/tictac.wasm"] ~ wasmOptions ~ releaseOptions ~ files
);
if (result[0]) {
writeln("Build failed:");
writeln(result[1]);
}
} catch (ProcessException e) {
writeln("Ldc was not found. You can download it here: https://github.com/ldc-developers/ldc/releases");
writeln("And make sure it's added to the PATH environment variable");
return -1;
}
return 0;
}