2016-07-14 16:16:42 +00:00
|
|
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
2014-08-24 00:11:05 +00:00
|
|
|
# vim: set filetype=python:
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2014-09-04 00:05:12 +00:00
|
|
|
@template
|
2014-10-29 04:29:42 +00:00
|
|
|
def Binary():
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Generic template for target binaries. Meant to be used by other
|
|
|
|
templates."""
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2017-07-05 13:32:30 +00:00
|
|
|
# Add -llog by default, since we use it all over the place.
|
2023-12-08 04:26:45 +00:00
|
|
|
if CONFIG["OS_TARGET"] == "Android":
|
|
|
|
OS_LIBS += ["log"]
|
2017-07-05 13:32:30 +00:00
|
|
|
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
@template
|
|
|
|
def Program(name):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for program executables."""
|
2014-09-03 05:10:54 +00:00
|
|
|
PROGRAM = name
|
|
|
|
|
2014-10-29 04:29:42 +00:00
|
|
|
Binary()
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
@template
|
2023-12-08 04:26:45 +00:00
|
|
|
def SimplePrograms(names, ext=".cpp"):
|
|
|
|
"""Template for simple program executables.
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
Those have a single source with the same base name as the executable.
|
2023-12-08 04:26:45 +00:00
|
|
|
"""
|
2014-09-03 05:10:54 +00:00
|
|
|
SIMPLE_PROGRAMS += names
|
2023-12-08 04:26:45 +00:00
|
|
|
SOURCES += ["%s%s" % (name, ext) for name in names]
|
2014-09-03 05:10:54 +00:00
|
|
|
|
2014-10-29 04:29:42 +00:00
|
|
|
Binary()
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
@template
|
2023-12-08 04:26:45 +00:00
|
|
|
def CppUnitTests(names, ext=".cpp"):
|
|
|
|
"""Template for C++ unit tests.
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
Those have a single source with the same base name as the executable.
|
2023-12-08 04:26:45 +00:00
|
|
|
"""
|
|
|
|
COMPILE_FLAGS["EXTRA_INCLUDES"] = [
|
|
|
|
"-I%s/dist/include" % TOPOBJDIR,
|
|
|
|
"-I%s/dist/include/testing" % TOPOBJDIR,
|
|
|
|
]
|
2014-09-03 05:10:54 +00:00
|
|
|
CPP_UNIT_TESTS += names
|
2023-12-08 04:26:45 +00:00
|
|
|
SOURCES += ["%s%s" % (name, ext) for name in names]
|
2014-09-03 05:10:54 +00:00
|
|
|
|
2014-10-29 04:29:42 +00:00
|
|
|
Binary()
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
@template
|
|
|
|
def Library(name):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for libraries."""
|
2014-09-03 05:10:54 +00:00
|
|
|
LIBRARY_NAME = name
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2018-07-16 17:52:14 +00:00
|
|
|
@template
|
|
|
|
def AllowCompilerWarnings():
|
2023-12-08 04:26:45 +00:00
|
|
|
COMPILE_FLAGS["WARNINGS_AS_ERRORS"] = []
|
|
|
|
WASM_FLAGS["WARNINGS_AS_ERRORS"] = []
|
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
|
2018-08-30 17:29:54 +00:00
|
|
|
@template
|
|
|
|
def DisableCompilerWarnings():
|
2022-10-18 19:46:45 +00:00
|
|
|
# Keep the -Wno-* flags to disable warnings that may be enabled through other means.
|
|
|
|
def filter(flags):
|
2023-12-08 04:26:45 +00:00
|
|
|
return [f for f in flags or [] if f.startswith("-Wno-")]
|
|
|
|
|
|
|
|
COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_CFLAGS"])
|
|
|
|
COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_CXXFLAGS"])
|
|
|
|
HOST_COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_HOST_CFLAGS"])
|
|
|
|
HOST_COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_HOST_CXXFLAGS"])
|
|
|
|
|
2018-08-30 17:29:54 +00:00
|
|
|
|
2016-08-06 04:49:26 +00:00
|
|
|
@template
|
2020-02-11 21:51:56 +00:00
|
|
|
def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for Rust libraries."""
|
2016-08-06 04:49:26 +00:00
|
|
|
Library(name)
|
|
|
|
|
|
|
|
IS_RUST_LIBRARY = True
|
2018-07-16 17:52:14 +00:00
|
|
|
# Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
|
|
|
|
AllowCompilerWarnings()
|
2016-12-02 16:56:43 +00:00
|
|
|
|
2018-08-30 17:29:54 +00:00
|
|
|
# And furthermore, don't even show warnings for them, so they don't regress
|
|
|
|
# the Compiler Warnings build metric
|
|
|
|
# <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
|
|
|
|
DisableCompilerWarnings()
|
|
|
|
|
2016-12-02 16:56:43 +00:00
|
|
|
if features:
|
|
|
|
RUST_LIBRARY_FEATURES = features
|
2016-08-06 04:49:26 +00:00
|
|
|
|
2018-08-10 19:07:29 +00:00
|
|
|
if output_category:
|
|
|
|
RUST_LIBRARY_OUTPUT_CATEGORY = output_category
|
|
|
|
|
2020-02-11 21:51:56 +00:00
|
|
|
if is_gkrust:
|
|
|
|
IS_GKRUST = True
|
|
|
|
|
2016-08-06 04:49:26 +00:00
|
|
|
|
2014-09-04 00:04:45 +00:00
|
|
|
@template
|
2018-08-10 19:07:29 +00:00
|
|
|
def SharedLibrary(name, output_category=None):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for shared libraries."""
|
2014-09-04 00:04:45 +00:00
|
|
|
Library(name)
|
|
|
|
|
|
|
|
FORCE_SHARED_LIB = True
|
|
|
|
|
2018-08-10 19:07:29 +00:00
|
|
|
if output_category:
|
|
|
|
SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
|
|
|
|
|
2014-10-29 04:29:42 +00:00
|
|
|
Binary()
|
2014-09-04 00:05:12 +00:00
|
|
|
|
2014-09-04 00:04:45 +00:00
|
|
|
|
|
|
|
@template
|
2018-08-10 19:07:29 +00:00
|
|
|
def Framework(name, output_category=None):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for OSX Frameworks."""
|
2018-08-10 19:07:29 +00:00
|
|
|
SharedLibrary(name, output_category)
|
2014-09-04 00:04:45 +00:00
|
|
|
|
|
|
|
IS_FRAMEWORK = True
|
|
|
|
|
|
|
|
|
2014-09-04 00:05:12 +00:00
|
|
|
@template
|
Bug 1423802 - Handle stdc++compat and STLPORT_LIBS at the emitter level. r=nalexander
Bug 1256642 introduced magic at the emitter level to determine whether a
binary contains C++ sources and should be linked with the C compiler or
the C++ compiler.
Unfortunately, the Binary() moz.build template always adds C++ OS
libraries on Android (through STLPORT_LIBS), and C++ libraries on Linux
(stdc++compat).
The latter only ends up forcing every Binary() to be linked with the C++
linker, which is unfortunate, but doesn't cause much problems. The
former, however, involving OS libraries, the magic from bug 1256642
doesn't kick in, so we end up trying to link C++ OS libraries with the C
linker. Which ends up failing, because the libraries in STLPORT_LIBS
require -lm, which, while it's added by the C++ compiler when linking,
is not when the linkage is driven by the C compiler.
Because the fallible library, linked to all GeckoBinary()s is a C++
library, we still ended up linking with the C++ compiler on Android, so
this wasn't actually causing any problem... until I tried to remove that
fallible library in bug 1423803.
Anyways, the core problem is that moz.build evaluation is happening too
early to know whether any C++ sources are being linked together, so
there is no way the Binary() template can do the right thing. So this
change moves the logic to the emitter.
This also changes the type of STLPORT_LIBS to a list.
--HG--
extra : rebase_source : a70ddf7a132f94dc10e7e1db94ae80fb8d7a269f
2017-12-07 03:15:32 +00:00
|
|
|
def HostProgram(name):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for build tools executables."""
|
2014-09-03 05:10:54 +00:00
|
|
|
HOST_PROGRAM = name
|
|
|
|
|
|
|
|
|
|
|
|
@template
|
2023-12-08 04:26:45 +00:00
|
|
|
def HostSimplePrograms(names, ext=".cpp"):
|
|
|
|
"""Template for simple build tools executables.
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
Those have a single source with the same base name as the executable.
|
2023-12-08 04:26:45 +00:00
|
|
|
"""
|
2014-09-03 05:10:54 +00:00
|
|
|
HOST_SIMPLE_PROGRAMS += names
|
2023-12-08 04:26:45 +00:00
|
|
|
HOST_SOURCES += ["%s%s" % (name.replace("host_", ""), ext) for name in names]
|
2014-09-03 05:10:54 +00:00
|
|
|
|
|
|
|
|
2018-07-05 05:58:09 +00:00
|
|
|
@template
|
|
|
|
def HostSharedLibrary(name):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for build tools libraries."""
|
|
|
|
if name != "clang-plugin":
|
|
|
|
error(
|
|
|
|
"Please make sure host shared library support is complete "
|
|
|
|
"before using for something else than the clang plugin"
|
|
|
|
)
|
2018-07-05 05:58:09 +00:00
|
|
|
|
|
|
|
HOST_LIBRARY_NAME = name
|
|
|
|
|
|
|
|
FORCE_SHARED_LIB = True
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2014-09-03 05:10:54 +00:00
|
|
|
@template
|
|
|
|
def HostLibrary(name):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for build tools libraries."""
|
2014-09-03 05:10:54 +00:00
|
|
|
HOST_LIBRARY_NAME = name
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2017-01-19 22:58:10 +00:00
|
|
|
@template
|
|
|
|
def HostRustLibrary(name, features=None):
|
2023-12-08 04:26:45 +00:00
|
|
|
"""Template for host Rust libraries."""
|
2017-01-19 22:58:10 +00:00
|
|
|
HostLibrary(name)
|
|
|
|
|
|
|
|
IS_RUST_LIBRARY = True
|
2018-07-16 17:52:14 +00:00
|
|
|
# Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
|
|
|
|
AllowCompilerWarnings()
|
2017-01-19 22:58:10 +00:00
|
|
|
|
|
|
|
if features:
|
|
|
|
HOST_RUST_LIBRARY_FEATURES = features
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2017-04-28 23:35:19 +00:00
|
|
|
@template
|
|
|
|
def DisableStlWrapping():
|
2023-12-08 04:26:45 +00:00
|
|
|
COMPILE_FLAGS["STL"] = []
|
|
|
|
|
2017-04-28 23:35:19 +00:00
|
|
|
|
2017-09-11 18:36:31 +00:00
|
|
|
@template
|
|
|
|
def NoVisibilityFlags():
|
2023-12-08 04:26:45 +00:00
|
|
|
COMPILE_FLAGS["VISIBILITY"] = []
|
|
|
|
|
2017-09-11 18:36:31 +00:00
|
|
|
|
2018-05-23 03:36:39 +00:00
|
|
|
@template
|
|
|
|
def ForceInclude(*headers):
|
|
|
|
"""Force includes a set of header files in C++ compilations"""
|
2023-12-08 04:26:45 +00:00
|
|
|
if CONFIG["CC_TYPE"] == "clang-cl":
|
|
|
|
include_flag = "-FI"
|
2018-05-23 03:36:39 +00:00
|
|
|
else:
|
2023-12-08 04:26:45 +00:00
|
|
|
include_flag = "-include"
|
2018-05-23 03:36:39 +00:00
|
|
|
for header in headers:
|
|
|
|
CXXFLAGS += [include_flag, header]
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2019-10-01 18:10:16 +00:00
|
|
|
@template
|
|
|
|
def GeneratedFile(name, *names, **kwargs):
|
|
|
|
"""Add one or more GENERATED_FILES with the given attributes.
|
|
|
|
|
|
|
|
You must pass in at least one generated file (the "name" argument). Other
|
|
|
|
names can be included as positional arguments after "name"."""
|
2023-12-08 04:26:45 +00:00
|
|
|
script = kwargs.pop("script", None)
|
|
|
|
entry_point = kwargs.pop("entry_point", None)
|
|
|
|
inputs = kwargs.pop("inputs", [])
|
|
|
|
flags = kwargs.pop("flags", [])
|
|
|
|
force = kwargs.pop("force", False)
|
2020-05-05 15:53:37 +00:00
|
|
|
if kwargs:
|
2023-12-08 04:26:45 +00:00
|
|
|
error("Unrecognized argument(s) to GeneratedFile: %s" % ", ".join(kwargs))
|
2019-10-01 18:10:16 +00:00
|
|
|
if entry_point and not script:
|
2023-12-08 04:26:45 +00:00
|
|
|
error("entry_point cannot be provided if script is not provided")
|
|
|
|
if script and ":" in script:
|
|
|
|
error(
|
|
|
|
"script should not include a `:`. If you want to provide an "
|
|
|
|
"alternative entry point for your script, use the entry_point "
|
|
|
|
"parameter."
|
|
|
|
)
|
2019-10-01 18:10:16 +00:00
|
|
|
|
|
|
|
key = (name,) + names if names else name
|
|
|
|
GENERATED_FILES += [key]
|
|
|
|
generated_file = GENERATED_FILES[key]
|
|
|
|
if script and not entry_point:
|
|
|
|
generated_file.script = script
|
|
|
|
if script and entry_point:
|
2023-12-08 04:26:45 +00:00
|
|
|
generated_file.script = script + ":" + entry_point
|
2019-10-01 18:10:16 +00:00
|
|
|
generated_file.inputs = inputs
|
|
|
|
generated_file.flags = flags
|
|
|
|
generated_file.force = force
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
|
2020-06-26 10:41:26 +00:00
|
|
|
@template
|
|
|
|
def CbindgenHeader(name, inputs):
|
|
|
|
"""Add one GENERATED_FILES by running RunCbindgen.py"""
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
inputs = ["!/config/cbindgen-metadata.json"] + inputs
|
|
|
|
GeneratedFile(
|
|
|
|
name, script="/build/RunCbindgen.py", entry_point="generate", inputs=inputs
|
|
|
|
)
|
2020-06-26 10:41:26 +00:00
|
|
|
|
|
|
|
|
2023-12-08 04:26:45 +00:00
|
|
|
include("gecko_templates.mozbuild")
|