Repository navigation
Expand file tree
/
Copy pathvarn.py
More file actions
236 lines (195 loc) · 7.79 KB
/
Copy pathvarn.py
File metadata and controls
236 lines (195 loc) · 7.79 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
"""Build, test and publish Varn on every target from one command."""
from __future__ import annotations
import argparse
import os
from tools.core import android, apple, apps, bench, cxx, general, helper, lib, site, tests, wasm
def _common(
parser: argparse.ArgumentParser, default_build_dir: str | None = None
) -> None:
parser.add_argument(
"--build-dir", default=default_build_dir, help="Build directory."
)
parser.add_argument(
"--config", default="Release", help="CMake build type (default: \"Release\")."
)
def _opt_build(parser: argparse.ArgumentParser) -> None:
_common(parser, "build")
parser.add_argument("--arch", help="Override for \"CMAKE_OSX_ARCHITECTURES\" (for example \"x86_64\").")
parser.add_argument(
"-D",
"--define",
action="append",
default=[],
metavar="VAR=VALUE",
help="Extra \"-D\" cache entry forwarded to \"cmake\" (repeatable).",
)
def _opt_lib(parser: argparse.ArgumentParser) -> None:
_common(parser, "build/lib")
parser.add_argument("--prefix", help="Value of \"CMAKE_INSTALL_PREFIX\" for a later \"--install\".")
parser.add_argument(
"--install",
action="store_true",
help="Install the \"varn\" component into the prefix after building.",
)
def _opt_android(parser: argparse.ArgumentParser) -> None:
_common(parser)
parser.add_argument(
"--api", type=int, default=24, help="Android min SDK (default: 24)."
)
def _opt_wasm(parser: argparse.ArgumentParser) -> None:
_common(parser)
parser.add_argument("--zip", help="Either \"ON\" or \"OFF\".")
def _opt_apple(parser: argparse.ArgumentParser) -> None:
_common(parser)
selection = parser.add_mutually_exclusive_group()
selection.add_argument("--family", help="Build only the slices of this family, such as \"ios\", without assembling the XCFramework.")
selection.add_argument(
"--assemble",
action="store_true",
help="Assemble \"varn.xcframework\" from the slices that the families already built.",
)
def _opt_test(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--build-dir", default="build", help="Build directory holding \"bin/varn\" (default: \"build\")."
)
parser.add_argument(
"--timeout",
type=_positive,
default=300,
help="Seconds one Lua test may run before it fails (default: 300).",
)
def _opt_test_cpp(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--build-dir", default="build/test", help="Build directory for the C++ tests (default: \"build/test\")."
)
parser.add_argument(
"--config", default="Release", help="CMake build type (default: \"Release\")."
)
parser.add_argument(
"-D",
"--define",
action="append",
default=[],
metavar="VAR=VALUE",
help="Extra \"-D\" cache entry forwarded to \"cmake\" (repeatable).",
)
def _opt_clean(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--build-dir", default="build", help="Build directory (default: \"build\")."
)
def _positive(text: str) -> int:
value = int(text)
if value < 1:
raise argparse.ArgumentTypeError(f"The value \"{text}\" must be a whole number of at least 1.")
return value
def _opt_bench(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--connections", type=int, default=256, help="Concurrent connections (default: 256).")
parser.add_argument("--duration", default="10s", help="Duration of each \"wrk\" route run (default: \"10s\").")
parser.add_argument("--workers", type=int, default=1, help="Worker processes per runtime (default: 1).")
parser.add_argument("--pool-size", type=int, default=64, help="Database connection pool size (default: 64).")
def _opt_site(parser: argparse.ArgumentParser) -> None:
_common(parser)
parser.add_argument("--zip", help="Either \"ON\" or \"OFF\".")
parser.add_argument(
"--remote",
default="git@github.com:varn-org/website.git",
help="Target Git remote (default: the \"varn-org/website\" repository over SSH).",
)
parser.add_argument("--branch", default="main", help="Target branch (default: \"main\").")
parser.add_argument("--message", help="Commit message (default: derived from the source commit).")
parser.add_argument("--dry-run", action="store_true", help="Build and commit locally without pushing.")
def _opt_fetch_native(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--version",
default="latest",
help="Release tag to fetch, or \"latest\" (default: \"latest\").",
)
parser.add_argument(
"--platform",
choices=["all", "android", "ios"],
default="all",
help="Which artifact to fetch (default: \"all\").",
)
# Each task maps to its handler, its options configurator and the one-line help shown by `--help`.
_TASKS = {
"build": (
cxx.build,
_opt_build,
"Build the native \"varn\" executable for the current desktop OS.",
),
"test": (
tests.run,
_opt_test,
"Run the Lua test suite against the built \"varn\" binary.",
),
"test-cpp": (
tests.run_cpp,
_opt_test_cpp,
"Build and run the native C++ test target (googletest).",
),
"bench": (
bench.run,
_opt_bench,
"Run the Varn vs Node vs Python benchmark (plaintext, JSON, MySQL, Redis) in Docker.",
),
"apple": (apple.build, _opt_apple, "Build \"varn.xcframework\" for all Apple slices."),
"lib": (
lib.build,
_opt_lib,
"Build the embeddable Varn shared library as a \"find_package(varn)\" package. Add \"--install\" to place the \"varn\" component into \"--prefix\".",
),
"android": (
android.build,
_opt_android,
"Build the Android AAR (\"libvarn.so\" for every ABI).",
),
"wasm": (wasm.build, _opt_wasm, "Build the \"varn-wasm\" target with Emscripten."),
"app-wasm": (
wasm.app,
_opt_wasm,
"Build the wasm engine, then bundle the browser app into \"apps/wasm/dist\".",
),
"serve": (
wasm.serve,
_opt_wasm,
"Build the wasm engine, then start the Vite dev server for \"apps/wasm\".",
),
"site-deploy": (
site.deploy,
_opt_site,
"Build the production wasm site and publish it to the \"varn-org/website\" repository.",
),
"format": (
general.fmt,
None,
"Run \"clang-format\" over the \"modules/\" and \"src/\" sources.",
),
"clean": (general.clean, _opt_clean, "Remove the build directory."),
"zip": (general.zip, None, "Create a source archive beside the repo."),
"fetch-native": (
apps.fetch,
_opt_fetch_native,
"Download the released AAR and XCFramework the mobile apps link against.",
),
}
def _build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog="varn", description=__doc__)
tasks = parser.add_subparsers(dest="task", metavar="task", required=True)
for name, (_, configure, help_text) in _TASKS.items():
task = tasks.add_parser(name, help=help_text, description=help_text)
task.add_argument(
"--jobs",
type=_positive,
default=helper.DEFAULT_JOBS,
help=f"Parallel build jobs (default: {helper.DEFAULT_JOBS}).",
)
if configure:
configure(task)
return parser
def main() -> None:
args = _build_parser().parse_args()
# A build that a dependency runs by itself, such as the one of OpenSSL, keeps to the same job count as the build around it.
os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(args.jobs)
_TASKS[args.task][0](args)
if __name__ == "__main__":
main()