Repository navigation
Expand file tree
/
Copy pathconfigure.py
More file actions
207 lines (190 loc) · 6.83 KB
/
Copy pathconfigure.py
File metadata and controls
207 lines (190 loc) · 6.83 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
# root build script: writes build.ninja for the native ports (Linux, Windows,
# Android) and the web port
import argparse
import io
import os
import sys
from pathlib import Path
from types import SimpleNamespace
from tools import ninja_syntax
from tools.android_build import android_configure_inputs, generate_android_build
from tools.linux_build import check_profile_options, generate_linux_build, linux_configure_inputs
from tools.web_build import generate_web_build, web_configure_inputs
from tools.windows_build import generate_windows_build, windows_configure_inputs
def is_windows() -> bool:
return os.name == "nt"
# arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"--linux-cc",
metavar="BINARY",
help="compiler for the native Linux build, `ninja linux` (default: clang)",
)
parser.add_argument(
"--compiler-launcher",
metavar="BINARY",
help="a program that runs each compile, such as ccache "
"(links and the Android host's few units run the compiler directly)",
)
parser.add_argument(
"--release",
action="store_true",
help="release builds (Linux, Windows, Android, web): assertions are not checked",
)
parser.add_argument(
"--profile",
action="store_true",
help="profiling builds (Linux, Windows, Android): CPU scopes recorded on a "
"console command or launch setting (README, \"Profiling builds\"); not with --pgo=train",
)
parser.add_argument(
"--lto",
choices=["full", "thin", "off"],
default="full",
help="link-time optimisation (Linux, Windows): full (the default: the whole game "
"optimised as one module, the fastest code and the slowest links), thin (parallel and incremental) or off",
)
parser.add_argument(
"--portable",
action="store_true",
help="x86 builds (Linux, Windows): code for any x86-64 processor (SSE2) rather than for this "
"machine's (-march=native, the default); use it for builds that run on other computers. On Linux it also "
"builds against Debian 11's glibc 2.31 rather than this machine's, and brings its own SDL 3 (libSDL3.so.0, "
"beside the executable), so that it starts on SteamOS and older distributions: the first build downloads "
"the Debian packages and SDL's source (build/linux/third_party, tools/linux_sysroot.py), and needs CMake, "
"pkgconf and wayland-scanner, not the 32-bit SDL 3",
)
parser.add_argument(
"--pgo",
nargs="?",
const="train",
default="use",
choices=["use", "train", "off"],
help="profile-guided optimisation: use (the default) optimises with the profiles in pgo/, "
"train (or plain --pgo) first records this platform's profile if it is missing, by letting an instrumented "
"build play every campaign level (needs the game data in assets/ and a display; Linux and Windows), off does "
"without",
)
parser.add_argument(
"--pgo-profile",
metavar="PROFDATA",
type=Path,
help="profile-guided optimisation from this profile instead",
)
parser.add_argument(
"--android-ndk",
type=str,
help="Android NDK for `ninja android` (default: ANDROID_NDK_HOME, or the newest under the Android SDK)",
)
parser.add_argument(
"--android-guest-cc",
type=str,
help="clang with the arm64_32 target for the Android guest (default: clang)",
)
parser.add_argument(
"--web-emcc",
type=str,
help="Emscripten's emcc for `ninja web` (default: emcc on the PATH, then EMSDK's or ~/emsdk's)",
)
# no need to spam those extra flags when running on Windows
if not is_windows():
parser.add_argument(
"--windows-cross",
action="store_true",
help="generate the Windows build (`ninja windows`) on Linux, cross-compiling "
"with clang against an MSVC toolchain (--windows-vctools-dir and --windows-sdk-dir), "
"and make it the default target",
)
parser.add_argument(
"--windows-cc",
metavar="BINARY",
help="compiler for the Windows cross build, `ninja windows` (default: clang). "
"Only clang is supported for now.",
)
parser.add_argument(
"--windows-vctools-dir",
metavar="DIR",
type=Path,
help="the Visual C++ tools of the MSVC toolchain a --windows-cross build compiles "
"and links against: the versioned folder under VC/Tools/MSVC, the one with `include` "
"and `lib` (default: VCToolsInstallDir)",
)
parser.add_argument(
"--windows-sdk-dir",
metavar="DIR",
type=Path,
help="the Windows SDK a --windows-cross build compiles and links against: the "
"folder with `Include` and `Lib`, each with a versioned folder (default: WindowsSdkDir)",
)
args = parser.parse_args()
try:
check_profile_options(args.profile, args.pgo)
except ValueError as error:
parser.error(str(error))
# the settings the builds read
sln = SimpleNamespace(
build_dir=Path("build"),
linux_cc=args.linux_cc,
compiler_launcher=args.compiler_launcher,
port_release=args.release,
port_profile=args.profile,
port_lto=args.lto,
port_portable=args.portable,
port_pgo=args.pgo,
port_pgo_profile=args.pgo_profile,
android_ndk=args.android_ndk,
android_guest_cc=args.android_guest_cc,
web_emcc=args.web_emcc,
)
if not is_windows():
sln.windows_cc = args.windows_cc
sln.windows_cross = args.windows_cross
sln.windows_vctools_dir = args.windows_vctools_dir
sln.windows_sdk_dir = args.windows_sdk_dir
# build.ninja
out = io.StringIO()
n = ninja_syntax.Writer(out)
n.variable("ninja_required_version", "1.3")
n.newline()
configure_script = Path(os.path.relpath(os.path.abspath(sys.argv[0])))
n.comment("The arguments passed to configure.py, for rerunning it.")
n.variable(
"configure_args",
[f'"{arg}"' if any(ch.isspace() for ch in arg) else arg for arg in sys.argv[1:]],
)
n.variable("python", f'"{sys.executable}"')
n.newline()
generate_linux_build(n, sln)
generate_android_build(n, sln)
generate_windows_build(n, sln)
generate_web_build(n, sln)
n.comment("Reconfigure on change")
n.rule(
name="configure",
command=f"$python {configure_script} $configure_args",
generator=True,
description=f"RUN {configure_script}",
)
n.build(
outputs="build.ninja",
rule="configure",
implicit=[
configure_script,
Path("tools/ninja_syntax.py"),
*linux_configure_inputs(),
*android_configure_inputs(),
*windows_configure_inputs(),
*web_configure_inputs(),
],
)
n.newline()
# the build for this computer, where it could be generated (the Windows
# build is left out when SDL cannot be fetched, for instance)
default = "windows" if is_windows() or sln.windows_cross else "linux"
if f"\nbuild {default}: " in out.getvalue():
n.comment("Default rule: the build for this computer")
n.default(default)
with open("build.ninja", "w", encoding="utf-8") as f:
f.write(out.getvalue())
out.close()