-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuild.hx
175 lines (160 loc) · 4.53 KB
/
Build.hx
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import sys.io.File;
import sys.FileSystem;
import haxe.io.Path;
using StringTools;
enum abstract Target(String) to String {
var Windows = "windows";
var Linux = "linux";
var macOS = "macos";
var Android = "android";
var iOS = "ios";
public static function fromString(s:String):Target {
return switch s {
case "windows": Windows;
case "linux": Linux;
case "macos", "mac": macOS;
case "android": Android;
case "ios": iOS;
default:
throw "Invalid target";
}
}
}
function applyPatch(dir:String, patch:String) {
Sys.command("git", ["-C", dir, "apply", '../patches/$patch']);
}
function resetPatch(dir:String) {
Sys.command("git", ["-C", dir, "reset", "--hard", "--quiet"]);
}
function main() {
final gw = Sys.getEnv("GITHUB_WORKSPACE");
var num_cpus:Null<Int> = null;
try {
if (Sys.getEnv("NUMBER_OF_PROCESSORS") != null) {
num_cpus = Std.parseInt(Sys.getEnv("NUMBER_OF_PROCESSORS"));
} else {
#if eval
final cpus = eval.luv.SystemInfo.cpuInfo().resolve();
num_cpus = cpus.length;
#end
}
}
final working_dir = Sys.getCwd();
final sys_name = Sys.systemName().toLowerCase();
var debug = Sys.getEnv("DEBUG") != null;
var krafix = Sys.getEnv("INCLUDE_KRAFIX") != null;
var g_api = Sys.getEnv("KINCHL_GRAPHICS");
var target = null;
{
final args = Sys.args();
while (true) {
switch args.shift() {
case null:
break;
case "-g":
g_api = args.shift();
case "-t":
target = Target.fromString(args.shift());
case "--debug":
debug = true;
case "--krafix":
krafix = true;
case var arg:
trace('Unknown argument: $arg');
Sys.exit(1);
}
}
}
if (krafix) {
Sys.putEnv("INCLUDE_KRAFIX", "1");
}
if (debug) {
Sys.putEnv("KINCHL_VALIDATE_VULKAN", "1");
}
applyPatch("krafix", "krafix.diff");
final n_args = ["--dynlib", "--noshaders"];
if (sys_name == "windows") {
n_args.push("-v");
n_args.push("vs2019");
}
if (g_api != null) {
n_args.push("-g");
n_args.push(g_api);
}
if (target != null) {
n_args.push("-t");
n_args.push(target);
}
if (debug)
n_args.push("--debug");
if (Sys.command(sys_name == "windows" ? "Kinc/make.bat" : "Kinc/make", n_args) != 0)
Sys.exit(1);
Sys.setCwd("build");
FileSystem.createDirectory("bin");
switch target == null ? Target.fromString(sys_name) : target {
case Windows:
final configuration = debug ? "Debug" : "Release";
final vswhere = new sys.io.Process('C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe',
['-products', '*', '-latest', '-find', 'VC\\Auxiliary\\Build\\vcvars64.bat']);
if (vswhere.exitCode(true) == 0) {
final path = vswhere.stdout.readAll().toString();
File.saveContent("build.bat",
'@call "'
+ path
+ '"\n'
+ "@MSBuild.exe"
+ " KincHL.vcxproj"
+ " /m"
+ (num_cpus == null ? "" : ':$num_cpus')
+ ' /p:Configuration=$configuration,Platform=x64,OutDir=bin/,TargetExt=.hdll,TargetName=kinc');
if (Sys.command("build.bat") != 0)
Sys.exit(1);
} else {
Sys.println("Visual Studio not found.");
Sys.exit(0);
}
case Linux:
final configuration = debug ? "Debug" : "Release";
File.saveContent('$configuration/makefile', File.getContent('$configuration/makefile').replace('KincHL.so', 'kinc.hdll'));
Sys.setCwd(configuration);
final m_args = [];
if (num_cpus != null) {
Sys.println('Using $num_cpus cores.');
m_args.push("-j" + num_cpus);
}
if (Sys.command("make", m_args) != 0)
Sys.exit(1);
Sys.setCwd("..");
File.copy('$configuration/kinc.hdll', "bin/kinc.hdll");
case macOS, iOS:
final configuration = debug ? "Debug" : "Release";
final args = [
"-configuration",
configuration,
"-project",
"KincHL.xcodeproj",
"EXECUTABLE_NAME=kinc.hdll",
];
if (target != iOS)
args.push("ARCHS=x86_64");
if (Sys.command("xcodebuild", args) != 0)
Sys.exit(1);
File.copy('build/$configuration/kinc.hdll', "bin/kinc.hdll");
case Android:
Sys.setCwd("KincHL");
File.saveContent("app/CMakeLists.txt", File.getContent("app/CMakeLists.txt") + '\nset_target_properties(kinc PROPERTIES SUFFIX ".hdll")');
final configuration = debug ? "Debug" : "Release";
switch sys_name {
case "windows":
Sys.command("gradlew.bat", ['assemble$configuration']);
case _:
Sys.command("bash", ["gradlew", 'assemble$configuration']);
}
}
try {
File.copy("bin/kinc.hdll", Path.normalize(gw + "/" + "kinc.hdll"));
File.copy("bin/kinc.lib", Path.normalize(gw + "/" + "kinc.lib"));
} catch (_) {};
Sys.setCwd(working_dir);
resetPatch("krafix");
}