Repository navigation
Expand file tree
/
Copy pathconfigure.py
More file actions
179 lines (165 loc) · 6.54 KB
/
Copy pathconfigure.py
File metadata and controls
179 lines (165 loc) · 6.54 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
#!/usr/bin/env python3
# root build script: writes build.ninja for the native ports (Linux, Windows,
# Android)
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.windows_build import generate_windows_build, windows_configure_inputs
# 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): 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("--macos", action="store_true", help="generate the rebased Apple Silicon guest target")
parser.add_argument("--macos-renderer", choices=("angle", "metal"), default="angle",
help="Apple Silicon guest renderer. metal draws with native Metal")
parser.add_argument("--ios", action="store_true", help="generate the signed-image iPhone guest target")
parser.add_argument("--android-guest-only", action="store_true", help="build the portable ARM image without an Android host")
parser.add_argument("--android-guest-llvm-bin", type=Path, help="directory containing llvm-ar and ld.lld")
parser.add_argument("--android-guest-gl-include", type=Path, help="directory containing Khronos GLES headers")
parser.add_argument("--android-guest-builtins", type=Path, help="optional AArch64 compiler builtins archive")
args = parser.parse_args()
if args.macos and args.ios:
parser.error("Choose either --macos or --ios")
if args.macos_renderer != "angle" and not args.macos:
parser.error("--macos-renderer metal requires --macos")
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=("tools/ios_guest_cc.py" if args.ios else "tools/macos_guest_cc.py" if args.macos else args.android_guest_cc),
android_guest_only=args.android_guest_only or args.macos or args.ios,
android_guest_llvm_bin=args.android_guest_llvm_bin,
android_guest_gl_include=args.android_guest_gl_include,
android_guest_builtins=args.android_guest_builtins,
macos=args.macos,
ios=args.ios,
macos_renderer=args.macos_renderer,
)
def is_windows() -> bool:
return os.name == "nt"
# 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)
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(),
],
)
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 = "ios_guest" if args.ios else "macos_guest" if args.macos else "windows" if is_windows() 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()