| 1 |
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- |
| 2 |
# vim: set filetype=python: |
| 3 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
include("build/moz.configure/init.configure") |
| 8 |
|
| 9 |
# Note: |
| 10 |
# - Gecko-specific options and rules should go in toolkit/moz.configure. |
| 11 |
# - Firefox-specific options and rules should go in browser/moz.configure. |
| 12 |
# - Fennec-specific options and rules should go in |
| 13 |
# mobile/android/moz.configure. |
| 14 |
# - Spidermonkey-specific options and rules should go in js/moz.configure. |
| 15 |
# - etc. |
| 16 |
|
| 17 |
imply_option( |
| 18 |
"--enable-artifact-build-symbols", |
| 19 |
depends(artifact_builds)(lambda v: False if v is None else None), |
| 20 |
reason="--disable-artifact-builds", |
| 21 |
) |
| 22 |
|
| 23 |
option( |
| 24 |
"--enable-artifact-build-symbols", |
| 25 |
nargs="?", |
| 26 |
choices=("full",), |
| 27 |
help="Download symbols when artifact builds are enabled", |
| 28 |
) |
| 29 |
|
| 30 |
|
| 31 |
@depends("--enable-artifact-build-symbols", moz_automation, target) |
| 32 |
def enable_artifact_build_symbols(value, automation, target): |
| 33 |
if len(value): |
| 34 |
return value[0] |
| 35 |
if bool(value): |
| 36 |
if target.os == "Android" and not automation: |
| 37 |
return "full" |
| 38 |
return True |
| 39 |
return None |
| 40 |
|
| 41 |
|
| 42 |
set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols) |
| 43 |
|
| 44 |
|
| 45 |
@depends("--enable-artifact-builds", build_project) |
| 46 |
def imply_disable_compile_environment(value, build_project): |
| 47 |
if value or build_project == "browser/extensions": |
| 48 |
return False |
| 49 |
|
| 50 |
|
| 51 |
option( |
| 52 |
env="MOZ_BUILD_HOOK", |
| 53 |
nargs=1, |
| 54 |
help="Path to the moz.build file that will be executed as if it were " |
| 55 |
"appended to every moz.build in the tree", |
| 56 |
) |
| 57 |
|
| 58 |
|
| 59 |
@depends_if("MOZ_BUILD_HOOK") |
| 60 |
@imports("os") |
| 61 |
def moz_build_hook(value): |
| 62 |
if not os.path.exists(value[0]): |
| 63 |
die(f"MOZ_BUILD_HOOK set to {value[0]} but the file doesn't exist") |
| 64 |
return os.path.abspath(value[0]) |
| 65 |
|
| 66 |
|
| 67 |
set_config("MOZ_BUILD_HOOK", moz_build_hook) |
| 68 |
|
| 69 |
|
| 70 |
option( |
| 71 |
env="MOZ_COPY_PDBS", |
| 72 |
help="For builds that do not support symbols in the normal fashion," |
| 73 |
" generate and copy them into the resulting build archive", |
| 74 |
) |
| 75 |
|
| 76 |
set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True)) |
| 77 |
|
| 78 |
imply_option( |
| 79 |
"--enable-compile-environment", imply_disable_compile_environment, reason="default" |
| 80 |
) |
| 81 |
|
| 82 |
option("--disable-compile-environment", help="Disable compiler/library checks") |
| 83 |
|
| 84 |
|
| 85 |
@depends("--disable-compile-environment") |
| 86 |
def compile_environment(compile_env): |
| 87 |
if compile_env: |
| 88 |
return True |
| 89 |
|
| 90 |
|
| 91 |
set_config("COMPILE_ENVIRONMENT", compile_environment) |
| 92 |
|
| 93 |
option("--disable-tests", help="Do not build test libraries & programs") |
| 94 |
|
| 95 |
|
| 96 |
@depends("--disable-tests") |
| 97 |
def enable_tests(value): |
| 98 |
if value: |
| 99 |
return True |
| 100 |
|
| 101 |
|
| 102 |
set_config("ENABLE_TESTS", enable_tests) |
| 103 |
set_define("ENABLE_TESTS", enable_tests) |
| 104 |
|
| 105 |
|
| 106 |
@depends(enable_tests) |
| 107 |
def gtest_has_rtti(value): |
| 108 |
if value: |
| 109 |
return "0" |
| 110 |
|
| 111 |
|
| 112 |
set_define("GTEST_HAS_RTTI", gtest_has_rtti) |
| 113 |
|
| 114 |
|
| 115 |
@depends(target, enable_tests) |
| 116 |
def linux_gtest_defines(target, enable_tests): |
| 117 |
if enable_tests and target.os == "Android": |
| 118 |
return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0") |
| 119 |
|
| 120 |
|
| 121 |
set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android) |
| 122 |
set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple) |
| 123 |
set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone) |
| 124 |
|
| 125 |
set_define("FMT_API", "MFBT_API") |
| 126 |
set_define("FMT_ENFORCE_COMPILE_STRING", 1) |
| 127 |
set_define("FMT_USE_EXCEPTIONS", 0) |
| 128 |
set_define("FMT_USE_WRITE_CONSOLE", 1) |
| 129 |
set_define("FMT_USE_LOCALE", 0) |
| 130 |
|
| 131 |
option( |
| 132 |
"--enable-debug", |
| 133 |
nargs="?", |
| 134 |
help="Enable building with developer debug info " |
| 135 |
"(using the given compiler flags)", |
| 136 |
) |
| 137 |
|
| 138 |
|
| 139 |
@depends("--enable-debug") |
| 140 |
def moz_debug(debug): |
| 141 |
if debug: |
| 142 |
return bool(debug) |
| 143 |
|
| 144 |
|
| 145 |
set_config("MOZ_DEBUG", moz_debug) |
| 146 |
set_define("MOZ_DEBUG", moz_debug) |
| 147 |
|
| 148 |
|
| 149 |
set_config( |
| 150 |
"MOZ_DIAGNOSTIC_ASSERT_ENABLED", |
| 151 |
True, |
| 152 |
when=moz_debug | milestone.is_early_beta_or_earlier, |
| 153 |
) |
| 154 |
set_define( |
| 155 |
"MOZ_DIAGNOSTIC_ASSERT_ENABLED", |
| 156 |
True, |
| 157 |
when=moz_debug | milestone.is_early_beta_or_earlier, |
| 158 |
) |
| 159 |
|
| 160 |
option( |
| 161 |
"--with-debug-label", |
| 162 |
nargs="+", |
| 163 |
help="Debug DEBUG_<value> for each comma-separated value given", |
| 164 |
) |
| 165 |
|
| 166 |
|
| 167 |
@depends(moz_debug, "--with-debug-label") |
| 168 |
def debug_defines(debug, labels): |
| 169 |
if debug: |
| 170 |
return ["DEBUG"] + ["DEBUG_%s" % label for label in labels] |
| 171 |
return ["NDEBUG", "TRIMMED"] |
| 172 |
|
| 173 |
|
| 174 |
set_config("MOZ_DEBUG_DEFINES", debug_defines) |
| 175 |
|
| 176 |
option(env="MOZ_PGO", help="Build with profile guided optimizations") |
| 177 |
|
| 178 |
set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x))) |
| 179 |
|
| 180 |
|
| 181 |
# Imply --enable-release when MOZILLA_OFFICIAL is set rather than adjusting the |
| 182 |
# default so that we can't have both MOZILLA_OFFICIAL and --disable-release set. |
| 183 |
imply_option("--enable-release", mozilla_official) |
| 184 |
|
| 185 |
option( |
| 186 |
"--enable-release", |
| 187 |
default=milestone.is_release_or_beta | moz_automation, |
| 188 |
help="{Build|Do not build} with more conservative, release " |
| 189 |
"engineering-oriented options.{ This may slow down builds.|}", |
| 190 |
) |
| 191 |
|
| 192 |
|
| 193 |
@depends("--enable-release") |
| 194 |
def developer_options(value): |
| 195 |
if not value: |
| 196 |
return True |
| 197 |
|
| 198 |
|
| 199 |
set_config("DEVELOPER_OPTIONS", developer_options) |
| 200 |
|
| 201 |
|
| 202 |
# hybrid build handling |
| 203 |
# ============================================================== |
| 204 |
|
| 205 |
option( |
| 206 |
"--disable-unified-build", |
| 207 |
help="Enable building modules in non unified context", |
| 208 |
) |
| 209 |
|
| 210 |
set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build") |
| 211 |
|
| 212 |
|
| 213 |
include("build/moz.configure/bootstrap.configure") |
| 214 |
|
| 215 |
|
| 216 |
# The execution model of the configure sandbox doesn't allow for |
| 217 |
# check_prog to use bootstrap_search_path directly because check_prog |
| 218 |
# comes first, so we use a trick to allow it. Uses of check_prog |
| 219 |
# happening before here won't allow bootstrap. |
| 220 |
|
| 221 |
|
| 222 |
@template |
| 223 |
def check_prog(*args, **kwargs): |
| 224 |
kwargs["bootstrap_search_path"] = bootstrap_search_path |
| 225 |
return check_prog(*args, **kwargs) |
| 226 |
|
| 227 |
|
| 228 |
check_prog("WGET", ("wget",), allow_missing=True) |
| 229 |
|
| 230 |
|
| 231 |
include("build/moz.configure/toolchain.configure", when="--enable-compile-environment") |
| 232 |
|
| 233 |
include("build/moz.configure/pkg.configure") |
| 234 |
include("build/moz.configure/memory.configure", when="--enable-compile-environment") |
| 235 |
include("build/moz.configure/headers.configure", when="--enable-compile-environment") |
| 236 |
include("build/moz.configure/libraries.configure", when="--enable-compile-environment") |
| 237 |
include("build/moz.configure/warnings.configure", when="--enable-compile-environment") |
| 238 |
include("build/moz.configure/flags.configure", when="--enable-compile-environment") |
| 239 |
include("build/moz.configure/default-flags.configure", when=~compile_environment) |
| 240 |
include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment") |
| 241 |
# rust.configure is included by js/moz.configure. |
| 242 |
|
| 243 |
|
| 244 |
option("--enable-valgrind", help="Enable Valgrind integration hooks") |
| 245 |
|
| 246 |
valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind") |
| 247 |
|
| 248 |
|
| 249 |
@depends("--enable-valgrind", valgrind_h) |
| 250 |
def check_valgrind(valgrind, valgrind_h): |
| 251 |
if valgrind: |
| 252 |
if not valgrind_h: |
| 253 |
die("--enable-valgrind specified but Valgrind is not installed") |
| 254 |
return True |
| 255 |
|
| 256 |
|
| 257 |
set_define("MOZ_VALGRIND", check_valgrind) |
| 258 |
set_config("MOZ_VALGRIND", check_valgrind) |
| 259 |
|
| 260 |
|
| 261 |
@depends(target, host) |
| 262 |
def is_openbsd(target, host): |
| 263 |
return target.kernel == "OpenBSD" or host.kernel == "OpenBSD" |
| 264 |
|
| 265 |
|
| 266 |
option( |
| 267 |
env="SO_VERSION", |
| 268 |
nargs=1, |
| 269 |
default="1.0", |
| 270 |
when=is_openbsd, |
| 271 |
help="Shared library version for OpenBSD systems", |
| 272 |
) |
| 273 |
|
| 274 |
|
| 275 |
@depends("SO_VERSION", when=is_openbsd) |
| 276 |
def so_version(value): |
| 277 |
return value |
| 278 |
|
| 279 |
|
| 280 |
@template |
| 281 |
def library_name_info_template(host_or_target): |
| 282 |
assert host_or_target in {host, target} |
| 283 |
windows_abi = { |
| 284 |
host: host_windows_abi, |
| 285 |
target: target_windows_abi, |
| 286 |
}[host_or_target] |
| 287 |
|
| 288 |
@depends(host_or_target, host_or_target.abi | windows_abi, so_version) |
| 289 |
def library_name_info_impl(host_or_target, windows_abi, so_version): |
| 290 |
if host_or_target.kernel == "WINNT": |
| 291 |
# There aren't artifacts for mingw builds, so it's OK that the |
| 292 |
# results are inaccurate in that case. |
| 293 |
if windows_abi and windows_abi != "msvc": |
| 294 |
return namespace( |
| 295 |
dll=namespace(prefix="", suffix=".dll"), |
| 296 |
lib=namespace(prefix="lib", suffix="a"), |
| 297 |
import_lib=namespace(prefix="lib", suffix="a"), |
| 298 |
obj=namespace(prefix="", suffix="o"), |
| 299 |
) |
| 300 |
|
| 301 |
return namespace( |
| 302 |
dll=namespace(prefix="", suffix=".dll"), |
| 303 |
lib=namespace(prefix="", suffix="lib"), |
| 304 |
import_lib=namespace(prefix="", suffix="lib"), |
| 305 |
obj=namespace(prefix="", suffix="obj"), |
| 306 |
) |
| 307 |
|
| 308 |
elif host_or_target.kernel == "Darwin": |
| 309 |
return namespace( |
| 310 |
dll=namespace(prefix="lib", suffix=".dylib"), |
| 311 |
lib=namespace(prefix="lib", suffix="a"), |
| 312 |
import_lib=namespace(prefix=None, suffix=""), |
| 313 |
obj=namespace(prefix="", suffix="o"), |
| 314 |
) |
| 315 |
elif so_version: |
| 316 |
so = ".so.%s" % so_version |
| 317 |
else: |
| 318 |
so = ".so" |
| 319 |
|
| 320 |
return namespace( |
| 321 |
dll=namespace(prefix="lib", suffix=so), |
| 322 |
lib=namespace(prefix="lib", suffix="a"), |
| 323 |
import_lib=namespace(prefix=None, suffix=""), |
| 324 |
obj=namespace(prefix="", suffix="o"), |
| 325 |
) |
| 326 |
|
| 327 |
return library_name_info_impl |
| 328 |
|
| 329 |
|
| 330 |
host_library_name_info = library_name_info_template(host) |
| 331 |
library_name_info = library_name_info_template(target) |
| 332 |
|
| 333 |
set_config("DLL_PREFIX", library_name_info.dll.prefix) |
| 334 |
set_config("DLL_SUFFIX", library_name_info.dll.suffix) |
| 335 |
set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix) |
| 336 |
set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix) |
| 337 |
set_config("LIB_PREFIX", library_name_info.lib.prefix) |
| 338 |
set_config("LIB_SUFFIX", library_name_info.lib.suffix) |
| 339 |
set_config("OBJ_SUFFIX", library_name_info.obj.suffix) |
| 340 |
set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix) |
| 341 |
set_define( |
| 342 |
"MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s) |
| 343 |
) |
| 344 |
set_define( |
| 345 |
"MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s) |
| 346 |
) |
| 347 |
set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix) |
| 348 |
set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix) |
| 349 |
set_config("WASM_OBJ_SUFFIX", "wasm") |
| 350 |
|
| 351 |
|
| 352 |
@template |
| 353 |
def bin_suffix(host_or_target): |
| 354 |
return depends(host_or_target)( |
| 355 |
lambda host_or_target: ".exe" if host_or_target.os == "WINNT" else "" |
| 356 |
) |
| 357 |
|
| 358 |
|
| 359 |
set_config("BIN_SUFFIX", bin_suffix(target)) |
| 360 |
set_config("HOST_BIN_SUFFIX", bin_suffix(host)) |
| 361 |
|
| 362 |
|
| 363 |
@template |
| 364 |
def plain_llvm_or_prefixed(name, llvm_name=None): |
| 365 |
# look for a tool, using the following alternatives, in that order: |
| 366 |
# 1. llvm-${llvm_name}, or llvm-${name} if ${llvm_name} is not provided |
| 367 |
# 2. ${toolchain_prefix}${name} |
| 368 |
# 3. ${name} |
| 369 |
|
| 370 |
@depends(llvm_tool(f"llvm-{llvm_name or name}"), toolchain_prefix) |
| 371 |
def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix): |
| 372 |
commands = [llvm_tool[0], name] |
| 373 |
for prefix in toolchain_prefix or (): |
| 374 |
commands.insert(1, f"{prefix}{name}") |
| 375 |
return tuple(commands) |
| 376 |
|
| 377 |
return plain_llvm_or_prefixed |
| 378 |
|
| 379 |
|
| 380 |
def validate_readelf(path): |
| 381 |
# llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d` |
| 382 |
# flag. We could try running `$path -d $some_binary` but we might be cross |
| 383 |
# compiling and not have a binary at hand to run that against. `$path -d` alone |
| 384 |
# would fail whether the flag is supported or not. So we resort to look for the |
| 385 |
# option in the `--help` output, which fortunately, s compatible between |
| 386 |
# llvm-readelf and readelf. |
| 387 |
retcode, stdout, stderr = get_cmd_output(path, "--help") |
| 388 |
return retcode == 0 and any(l.startswith(" -d ") for l in stdout.splitlines()) |
| 389 |
|
| 390 |
|
| 391 |
@depends("--enable-compile-environment", target, host) |
| 392 |
def readelf_when(compile_env, target, host): |
| 393 |
return compile_env and any( |
| 394 |
x.kernel not in ("Darwin", "WINNT") for x in (target, host) |
| 395 |
) |
| 396 |
|
| 397 |
|
| 398 |
readelf = check_prog( |
| 399 |
"READELF", |
| 400 |
plain_llvm_or_prefixed("readelf"), |
| 401 |
when=readelf_when, |
| 402 |
paths=clang_search_path, |
| 403 |
validate=validate_readelf, |
| 404 |
) |
| 405 |
|
| 406 |
|
| 407 |
def validate_objcopy(path): |
| 408 |
if "llvm-objcopy" not in path: |
| 409 |
return True |
| 410 |
# llvm-objcopy doesn't support --only-keep-debug before llvm 9.0. |
| 411 |
retcode, stdout, stderr = get_cmd_output(path, "--help") |
| 412 |
return retcode == 0 and any( |
| 413 |
l.startswith(" --only-keep-debug ") for l in stdout.splitlines() |
| 414 |
) |
| 415 |
|
| 416 |
|
| 417 |
check_prog( |
| 418 |
"OBJCOPY", |
| 419 |
plain_llvm_or_prefixed("objcopy"), |
| 420 |
when=readelf_when, |
| 421 |
paths=clang_search_path, |
| 422 |
validate=validate_objcopy, |
| 423 |
) |
| 424 |
|
| 425 |
|
| 426 |
# Make `profiling` available to this file even when js/moz.configure |
| 427 |
# doesn't end up included. |
| 428 |
profiling = dependable(False) |
| 429 |
# Same for js_standalone |
| 430 |
js_standalone = dependable(False) |
| 431 |
# Same for fold_libs |
| 432 |
fold_libs = dependable(False) |
| 433 |
# And dmd |
| 434 |
dmd = dependable(False) |
| 435 |
|
| 436 |
# Only available when toolkit/moz.configure is included |
| 437 |
pack_relative_relocs_flags = dependable(False) |
| 438 |
real_branding_directory = dependable(None) |
| 439 |
|
| 440 |
include(include_project_configure) |
| 441 |
|
| 442 |
|
| 443 |
@template |
| 444 |
def load_keyvalue_file(location, filename): |
| 445 |
|
| 446 |
@depends(build_environment, location, "--help", when=location) |
| 447 |
@checking(f"if configuration file {filename} exists") |
| 448 |
# This gives access to the sandbox. Don't copy this blindly. |
| 449 |
@imports("__sandbox__") |
| 450 |
@imports(_from="mozbuild.configure", _import="confvars") |
| 451 |
@imports("os.path") |
| 452 |
def load_keyvalue_file_impl(build_env, location, help): |
| 453 |
file_path = os.path.join(build_env.topsrcdir, location, filename) |
| 454 |
if os.path.exists(file_path): |
| 455 |
helper = __sandbox__._helper |
| 456 |
# parse confvars |
| 457 |
try: |
| 458 |
keyvals = confvars.parse(file_path) |
| 459 |
except confvars.ConfVarsSyntaxError as e: |
| 460 |
die(str(e)) |
| 461 |
for key, value in keyvals.items(): |
| 462 |
# FIXME: remove test once we no longer load confvars from old-configure. |
| 463 |
if key in __sandbox__._options: |
| 464 |
# ~= imply_option, but with an accurate origin |
| 465 |
helper.add(f"{key}={value}", origin="confvars", args=helper._args) |
| 466 |
return file_path |
| 467 |
|
| 468 |
return load_keyvalue_file_impl |
| 469 |
|
| 470 |
|
| 471 |
load_confvars = load_keyvalue_file(build_project, "confvars.sh") |
| 472 |
load_brandvars = load_keyvalue_file(real_branding_directory, "configure.sh") |
| 473 |
|
| 474 |
|
| 475 |
# Final flags validation and gathering |
| 476 |
# ------------------------------------------------- |
| 477 |
|
| 478 |
include( |
| 479 |
"build/moz.configure/finalize-flags.configure", when="--enable-compile-environment" |
| 480 |
) |
| 481 |
|
| 482 |
# ------------------------------------------------- |
| 483 |
|
| 484 |
|
| 485 |
@depends("--help") |
| 486 |
@imports(_from="mozbuild.backend", _import="backends") |
| 487 |
def build_backends_choices(_): |
| 488 |
return tuple(backends) |
| 489 |
|
| 490 |
|
| 491 |
@deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices) |
| 492 |
def build_backend(backends): |
| 493 |
if backends: |
| 494 |
return tuple("+%s" % b for b in backends) |
| 495 |
|
| 496 |
|
| 497 |
imply_option("--build-backends", build_backend) |
| 498 |
|
| 499 |
|
| 500 |
@depends( |
| 501 |
host, |
| 502 |
target, |
| 503 |
"--enable-artifact-builds", |
| 504 |
"--disable-compile-environment", |
| 505 |
"--enable-project", |
| 506 |
"--enable-application", |
| 507 |
"--help", |
| 508 |
) |
| 509 |
@imports("sys") |
| 510 |
def build_backend_defaults( |
| 511 |
host, |
| 512 |
target, |
| 513 |
artifact_builds, |
| 514 |
compile_environment, |
| 515 |
project, |
| 516 |
application, |
| 517 |
_, |
| 518 |
): |
| 519 |
if application: |
| 520 |
project = application[0] |
| 521 |
elif project: |
| 522 |
project = project[0] |
| 523 |
|
| 524 |
if artifact_builds: |
| 525 |
all_backends = ["FasterMake+RecursiveMake"] |
| 526 |
else: |
| 527 |
all_backends = ["RecursiveMake", "FasterMake"] |
| 528 |
if ( |
| 529 |
host.os == "WINNT" |
| 530 |
and target.os == "WINNT" |
| 531 |
and compile_environment |
| 532 |
and project not in ("mobile/android", "memory", "tools/update-programs") |
| 533 |
): |
| 534 |
all_backends.append("VisualStudio") |
| 535 |
if compile_environment and project not in ("memory", "tools/update-programs"): |
| 536 |
all_backends.append("Clangd") |
| 537 |
return tuple(all_backends) or None |
| 538 |
|
| 539 |
|
| 540 |
option( |
| 541 |
"--build-backends", |
| 542 |
nargs="+", |
| 543 |
default=build_backend_defaults, |
| 544 |
choices=build_backends_choices, |
| 545 |
help="Build backends to generate", |
| 546 |
) |
| 547 |
|
| 548 |
|
| 549 |
@depends("--build-backends") |
| 550 |
def build_backends(backends): |
| 551 |
return backends |
| 552 |
|
| 553 |
|
| 554 |
set_config("BUILD_BACKENDS", build_backends) |
| 555 |
|
| 556 |
|
| 557 |
# Determine whether to build the gtest xul. This happens in automation |
| 558 |
# on Android and Desktop platforms with the exception of: |
| 559 |
# - Windows PGO, where linking xul-gtest.dll takes too long; |
| 560 |
# - Android other than x86_64, where gtest is not required. |
| 561 |
@depends( |
| 562 |
build_project, |
| 563 |
target, |
| 564 |
moz_automation, |
| 565 |
enable_tests, |
| 566 |
when="--enable-compile-environment", |
| 567 |
) |
| 568 |
def build_gtest(build_project, target, automation, enable_tests): |
| 569 |
return bool( |
| 570 |
enable_tests |
| 571 |
and automation |
| 572 |
and build_project in ("browser", "comm/mail", "mobile/android") |
| 573 |
and not (target.os == "Android" and target.cpu != "x86_64") |
| 574 |
) |
| 575 |
|
| 576 |
|
| 577 |
option( |
| 578 |
"--enable-gtest-in-build", |
| 579 |
default=build_gtest, |
| 580 |
help="{Enable|Force disable} building the gtest libxul during the build", |
| 581 |
when="--enable-compile-environment", |
| 582 |
) |
| 583 |
|
| 584 |
set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build") |
| 585 |
|
| 586 |
# Localization |
| 587 |
# ============================================================== |
| 588 |
option( |
| 589 |
"--enable-ui-locale", |
| 590 |
default="en-US", |
| 591 |
help="Select the user interface locale (default: en-US)", |
| 592 |
) |
| 593 |
|
| 594 |
set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x)) |
| 595 |
|
| 596 |
# clang-plugin location |
| 597 |
# ============================================================== |
| 598 |
include( |
| 599 |
"build/moz.configure/clang_plugin.configure", when="--enable-compile-environment" |
| 600 |
) |
| 601 |
|
| 602 |
|
| 603 |
# Awk detection |
| 604 |
# ============================================================== |
| 605 |
awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path) |
| 606 |
|
| 607 |
# Until the AWK variable is not necessary in old-configure |
| 608 |
|
| 609 |
|
| 610 |
@depends(awk) |
| 611 |
def awk_for_old_configure(value): |
| 612 |
return value |
| 613 |
|
| 614 |
|
| 615 |
# GNU make detection |
| 616 |
# ============================================================== |
| 617 |
option(env="MAKE", nargs=1, help="Path to GNU make") |
| 618 |
|
| 619 |
|
| 620 |
@depends("MAKE", host) |
| 621 |
def possible_makes(make, host): |
| 622 |
candidates = [] |
| 623 |
if make: |
| 624 |
candidates.append(make[0]) |
| 625 |
if host.kernel == "WINNT": |
| 626 |
candidates.extend(("mozmake", "mingw32-make", "make", "gmake")) |
| 627 |
else: |
| 628 |
candidates.extend(("gmake", "make")) |
| 629 |
return candidates |
| 630 |
|
| 631 |
|
| 632 |
check_prog("GMAKE", possible_makes, bootstrap="mozmake") |
| 633 |
|
| 634 |
# watchman detection |
| 635 |
# ============================================================== |
| 636 |
|
| 637 |
option(env="WATCHMAN", nargs=1, help="Path to the watchman program") |
| 638 |
|
| 639 |
|
| 640 |
@depends(host, "WATCHMAN") |
| 641 |
@checking("for watchman", callback=lambda w: w.path if w else "not found") |
| 642 |
def watchman(host, prog): |
| 643 |
# On Windows, `watchman` is only supported on 64-bit hosts. |
| 644 |
if host.os == "WINNT" and host.cpu != "x86_64": |
| 645 |
return |
| 646 |
|
| 647 |
if not prog: |
| 648 |
prog = find_program("watchman") |
| 649 |
|
| 650 |
if not prog: |
| 651 |
return |
| 652 |
|
| 653 |
# `watchman version` will talk to the Watchman daemon service. |
| 654 |
# This can hang due to permissions problems. e.g. |
| 655 |
# https://github.com/facebook/watchman/issues/376. So use |
| 656 |
# `watchman --version` to prevent a class of failures. |
| 657 |
out = check_cmd_output(prog, "--version", onerror=lambda: None) |
| 658 |
if out is None: |
| 659 |
return |
| 660 |
|
| 661 |
return namespace(path=prog, version=Version(out.strip())) |
| 662 |
|
| 663 |
|
| 664 |
@depends_if(watchman) |
| 665 |
@checking("for watchman version") |
| 666 |
def watchman_version(w): |
| 667 |
return w.version |
| 668 |
|
| 669 |
|
| 670 |
set_config("WATCHMAN", watchman.path) |
| 671 |
|
| 672 |
|
| 673 |
@depends_all(hg_version, hg_config, watchman) |
| 674 |
@checking("for watchman Mercurial integration") |
| 675 |
@imports("os") |
| 676 |
def watchman_hg(hg_version, hg_config, watchman): |
| 677 |
if hg_version < Version("3.8"): |
| 678 |
return "no (Mercurial 3.8+ required)" |
| 679 |
|
| 680 |
ext_enabled = False |
| 681 |
mode_disabled = False |
| 682 |
|
| 683 |
for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"): |
| 684 |
if k in hg_config and hg_config[k] != "!": |
| 685 |
ext_enabled = True |
| 686 |
|
| 687 |
mode_disabled = hg_config.get("fsmonitor.mode") == "off" |
| 688 |
|
| 689 |
if not ext_enabled: |
| 690 |
return "no (fsmonitor extension not enabled)" |
| 691 |
if mode_disabled: |
| 692 |
return "no (fsmonitor.mode=off disables fsmonitor)" |
| 693 |
|
| 694 |
return True |
| 695 |
|
| 696 |
|
| 697 |
# Miscellaneous programs |
| 698 |
# ============================================================== |
| 699 |
check_prog("XARGS", ("xargs",)) |
| 700 |
|
| 701 |
|
| 702 |
@depends(target) |
| 703 |
def extra_programs(target): |
| 704 |
if target.kernel == "Darwin": |
| 705 |
return namespace( |
| 706 |
MKFSHFS=("newfs_hfs", "mkfs.hfsplus"), |
| 707 |
HFS_TOOL=("hfsplus",), |
| 708 |
) |
| 709 |
if target.os == "GNU" and target.kernel == "Linux": |
| 710 |
return namespace(RPMBUILD=("rpmbuild",)) |
| 711 |
|
| 712 |
|
| 713 |
check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True) |
| 714 |
check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True) |
| 715 |
check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True) |
| 716 |
|
| 717 |
|
| 718 |
nsis = check_prog( |
| 719 |
"MAKENSISU", |
| 720 |
("makensis",), |
| 721 |
bootstrap="nsis/bin", |
| 722 |
allow_missing=True, |
| 723 |
when=target_is_windows, |
| 724 |
) |
| 725 |
|
| 726 |
# Make sure the version of makensis is up to date. |
| 727 |
|
| 728 |
|
| 729 |
@depends_if(nsis) |
| 730 |
@checking("for NSIS version") |
| 731 |
@imports("re") |
| 732 |
def nsis_version(nsis): |
| 733 |
nsis_min_version = "3.0b1" |
| 734 |
|
| 735 |
def onerror(): |
| 736 |
return die("Failed to get nsis version.") |
| 737 |
|
| 738 |
out = check_cmd_output(nsis, "-version", onerror=onerror) |
| 739 |
|
| 740 |
m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out) |
| 741 |
|
| 742 |
if not m: |
| 743 |
raise FatalCheckError("Unknown version of makensis") |
| 744 |
ver = Version(m.group(0)) |
| 745 |
|
| 746 |
# Versions comparisons don't quite work well with beta versions, so ensure |
| 747 |
# it works for the non-beta version. |
| 748 |
if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"): |
| 749 |
raise FatalCheckError( |
| 750 |
"To build the installer you must have NSIS" |
| 751 |
" version %s or greater in your path" % nsis_min_version |
| 752 |
) |
| 753 |
|
| 754 |
return ver |
| 755 |
|
| 756 |
|
| 757 |
# And that makensis is 32-bit (but only on Windows). |
| 758 |
@depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT")) |
| 759 |
@checking("for 32-bit NSIS") |
| 760 |
def nsis_binary_type(nsis): |
| 761 |
bin_type = windows_binary_type(nsis) |
| 762 |
if bin_type != "win32": |
| 763 |
raise FatalCheckError("%s is not a 32-bit Windows application" % nsis) |
| 764 |
|
| 765 |
return "yes" |
| 766 |
|
| 767 |
|
| 768 |
# And any flags we have to give to makensis |
| 769 |
@depends(host) |
| 770 |
def nsis_flags(host): |
| 771 |
if host.kernel != "WINNT": |
| 772 |
return "-nocd" |
| 773 |
return "" |
| 774 |
|
| 775 |
|
| 776 |
set_config("MAKENSISU_FLAGS", nsis_flags) |
| 777 |
|
| 778 |
check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows) |
| 779 |
check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows) |
| 780 |
|
| 781 |
|
| 782 |
check_prog( |
| 783 |
"DSYMUTIL", |
| 784 |
llvm_tool("dsymutil"), |
| 785 |
when=compile_environment & target_is_darwin, |
| 786 |
paths=clang_search_path, |
| 787 |
) |
| 788 |
|
| 789 |
|
| 790 |
check_prog( |
| 791 |
"OTOOL", |
| 792 |
plain_llvm_or_prefixed("otool"), |
| 793 |
when=compile_environment & target_is_darwin, |
| 794 |
paths=clang_search_path, |
| 795 |
) |
| 796 |
|
| 797 |
check_prog( |
| 798 |
"INSTALL_NAME_TOOL", |
| 799 |
plain_llvm_or_prefixed("install_name_tool", llvm_name="install-name-tool"), |
| 800 |
when=compile_environment & target_is_darwin & js_standalone, |
| 801 |
paths=clang_search_path, |
| 802 |
) |
| 803 |
|
| 804 |
option( |
| 805 |
"--enable-strip", |
| 806 |
when=compile_environment, |
| 807 |
help="Enable stripping of libs & executables", |
| 808 |
) |
| 809 |
|
| 810 |
# This should be handled as a `when` once bug 1617793 is fixed. |
| 811 |
|
| 812 |
|
| 813 |
@depends("--enable-strip", c_compiler, when=compile_environment) |
| 814 |
def enable_strip(strip, c_compiler): |
| 815 |
if strip and c_compiler.type != "clang-cl": |
| 816 |
return True |
| 817 |
|
| 818 |
|
| 819 |
set_config("ENABLE_STRIP", enable_strip) |
| 820 |
|
| 821 |
option( |
| 822 |
"--disable-install-strip", |
| 823 |
when=compile_environment, |
| 824 |
help="Enable stripping of libs & executables when packaging", |
| 825 |
) |
| 826 |
|
| 827 |
# This should be handled as a `when` once bug 1617793 is fixed. |
| 828 |
|
| 829 |
|
| 830 |
@depends("--enable-install-strip", c_compiler, when=compile_environment) |
| 831 |
def enable_install_strip(strip, c_compiler): |
| 832 |
if strip and c_compiler.type != "clang-cl": |
| 833 |
return True |
| 834 |
|
| 835 |
|
| 836 |
set_config("PKG_STRIP", enable_install_strip) |
| 837 |
|
| 838 |
|
| 839 |
@depends("--enable-strip", "--enable-install-strip", when=compile_environment) |
| 840 |
def strip(strip, install_strip): |
| 841 |
return strip or install_strip |
| 842 |
|
| 843 |
|
| 844 |
option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command") |
| 845 |
|
| 846 |
|
| 847 |
@depends("STRIP_FLAGS", profiling, target, when=strip) |
| 848 |
def strip_flags(flags, profiling, target): |
| 849 |
if flags: |
| 850 |
return flags[0].split() |
| 851 |
if profiling: |
| 852 |
# Only strip debug info and symbols when profiling is enabled, keeping |
| 853 |
# local symbols. |
| 854 |
if target.kernel == "Darwin": |
| 855 |
return ["-S"] |
| 856 |
elif target.os == "Android": |
| 857 |
# The tooling we use with Android supports detached symbols, and the |
| 858 |
# size increase caused by local symbols are too much for mobile. So, |
| 859 |
# don't restrict the amount of stripping with a flag. |
| 860 |
return |
| 861 |
else: |
| 862 |
return ["--strip-debug"] |
| 863 |
# Otherwise strip everything we can, which happens without flags on non-Darwin. |
| 864 |
# On Darwin, it tries to strip things it can't, so we need to limit its scope. |
| 865 |
elif target.kernel == "Darwin": |
| 866 |
return ["-x", "-S"] |
| 867 |
|
| 868 |
|
| 869 |
set_config("STRIP_FLAGS", strip_flags) |
| 870 |
|
| 871 |
|
| 872 |
def validate_strip(path): |
| 873 |
if "llvm-strip" not in path: |
| 874 |
return True |
| 875 |
# llvm-strip doesn't support -S before llvm 8.0. |
| 876 |
retcode, stdout, stderr = get_cmd_output(path, "--help") |
| 877 |
return retcode == 0 and any(l.startswith(" -S ") for l in stdout.splitlines()) |
| 878 |
|
| 879 |
|
| 880 |
@depends("--enable-compile-environment", target, host) |
| 881 |
def strip_when(compile_env, target, host): |
| 882 |
return compile_env and any(x.kernel != "WINNT" for x in (target, host)) |
| 883 |
|
| 884 |
|
| 885 |
check_prog( |
| 886 |
"STRIP", |
| 887 |
plain_llvm_or_prefixed("strip"), |
| 888 |
when=strip_when, |
| 889 |
paths=clang_search_path, |
| 890 |
validate=validate_strip, |
| 891 |
) |
| 892 |
|
| 893 |
|
| 894 |
@depends(js_standalone, target) |
| 895 |
def system_zlib_default(js_standalone, target): |
| 896 |
return ( |
| 897 |
js_standalone |
| 898 |
and target.kernel not in ("WINNT", "Darwin") |
| 899 |
and target.os != "Android" |
| 900 |
) |
| 901 |
|
| 902 |
|
| 903 |
option( |
| 904 |
"--with-system-zlib", |
| 905 |
nargs="?", |
| 906 |
default=system_zlib_default, |
| 907 |
help="{Use|Do not use} system libz", |
| 908 |
when=use_pkg_config, |
| 909 |
) |
| 910 |
|
| 911 |
|
| 912 |
@depends("--with-system-zlib", when=use_pkg_config) |
| 913 |
def with_system_zlib_option(with_system_zlib): |
| 914 |
return with_system_zlib |
| 915 |
|
| 916 |
|
| 917 |
@depends(with_system_zlib_option) |
| 918 |
def deprecated_system_zlib_path(value): |
| 919 |
if value and len(value) == 1: |
| 920 |
die( |
| 921 |
"--with-system-zlib=PATH is not supported anymore. Please use " |
| 922 |
"--with-system-zlib and set any necessary pkg-config environment variable." |
| 923 |
) |
| 924 |
|
| 925 |
|
| 926 |
pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib") |
| 927 |
|
| 928 |
set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib") |
| 929 |
|
| 930 |
option( |
| 931 |
env="USE_LIBZ_RS", |
| 932 |
default=milestone.is_early_beta_or_earlier, |
| 933 |
help="Use libz-rs-sys instead of zlib", |
| 934 |
when=toolkit & ~with_system_zlib_option, |
| 935 |
) |
| 936 |
|
| 937 |
set_config("USE_LIBZ_RS", True, when="USE_LIBZ_RS") |
| 938 |
|
| 939 |
with only_when(cross_compiling): |
| 940 |
option( |
| 941 |
env="JS_BINARY", |
| 942 |
nargs=1, |
| 943 |
help="Host JavaScript runtime, if any, to use during cross compiles", |
| 944 |
) |
| 945 |
set_config("JS_BINARY", depends_if("JS_BINARY")(lambda value: value[0])) |
| 946 |
|
| 947 |
# Please do not add configure checks from here on. |
| 948 |
|
| 949 |
|
| 950 |
# Assuming no other option is declared after this function, handle the |
| 951 |
# env options that were injected by mozconfig_options by creating dummy |
| 952 |
# Option instances and having the sandbox's CommandLineHelper handle |
| 953 |
# them. We only do so for options that haven't been declared so far, |
| 954 |
# which should be a proxy for the options that old-configure handles |
| 955 |
# and that we don't know anything about. |
| 956 |
@depends("--help") |
| 957 |
@imports("__sandbox__") |
| 958 |
@imports(_from="mozbuild.configure.options", _import="Option") |
| 959 |
def remaining_mozconfig_options(_): |
| 960 |
helper = __sandbox__._helper |
| 961 |
for arg in list(helper): |
| 962 |
if helper._origins[arg] != "mozconfig": |
| 963 |
continue |
| 964 |
name = arg.split("=", 1)[0] |
| 965 |
if name.isupper() and name not in __sandbox__._options: |
| 966 |
option = Option(env=name, nargs="*", help=name) |
| 967 |
helper.handle(option) |
| 968 |
|
| 969 |
|
| 970 |
@depends(build_environment, configure_cache) |
| 971 |
@imports(_import="json") |
| 972 |
@imports(_from="pathlib", _import="Path") |
| 973 |
def save_cache(build_environment, configure_cache): |
| 974 |
cache_file = Path(build_environment.topobjdir) / "configure.cache" |
| 975 |
|
| 976 |
with cache_file.open(mode="w") as fd: |
| 977 |
json.dump(configure_cache, fd, indent=4) |
| 978 |
|
| 979 |
|
| 980 |
@depends(build_environment, build_project) |
| 981 |
@imports("__sandbox__") |
| 982 |
@imports("glob") |
| 983 |
@imports(_from="os.path", _import="exists") |
| 984 |
def config_status_deps(build_env, build_project): |
| 985 |
topsrcdir = build_env.topsrcdir |
| 986 |
topobjdir = build_env.topobjdir |
| 987 |
|
| 988 |
if not topobjdir.endswith("js/src"): |
| 989 |
extra_deps = [os.path.join(topobjdir, ".mozconfig.json")] |
| 990 |
else: |
| 991 |
# mozconfig changes may impact js configure. |
| 992 |
extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")] |
| 993 |
|
| 994 |
confvars = os.path.join(topsrcdir, build_project, "confvars.sh") |
| 995 |
if exists(confvars): |
| 996 |
extra_deps.append(confvars) |
| 997 |
|
| 998 |
return ( |
| 999 |
list(__sandbox__._all_paths) |
| 1000 |
+ extra_deps |
| 1001 |
+ [ |
| 1002 |
os.path.join(topsrcdir, "CLOBBER"), |
| 1003 |
os.path.join(topsrcdir, "configure"), |
| 1004 |
os.path.join(topsrcdir, "js", "src", "configure"), |
| 1005 |
os.path.join(topsrcdir, "nsprpub", "configure"), |
| 1006 |
os.path.join(topsrcdir, "config", "milestone.txt"), |
| 1007 |
os.path.join(topsrcdir, "browser", "config", "version.txt"), |
| 1008 |
os.path.join(topsrcdir, "browser", "config", "version_display.txt"), |
| 1009 |
os.path.join(topsrcdir, "python", "sites", "build.txt"), |
| 1010 |
os.path.join(topsrcdir, "python", "sites", "common.txt"), |
| 1011 |
os.path.join(topsrcdir, "python", "sites", "mach.txt"), |
| 1012 |
os.path.join(topsrcdir, "python", "mach", "mach", "site.py"), |
| 1013 |
] |
| 1014 |
+ glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4")) |
| 1015 |
) |
| 1016 |
|
| 1017 |
|
| 1018 |
set_config("CONFIG_STATUS_DEPS", config_status_deps) |
| 1019 |
# Please do not add anything after setting config_dep_paths. |