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/.
10 """Generic template for target binaries. Meant to be used by other
13 # Add -llog by default, since we use it all over the place.
14 if CONFIG["OS_TARGET"] == "Android":
20 """Template for program executables."""
27 def SimplePrograms(names, ext=".cpp"):
28 """Template for simple program executables.
30 Those have a single source with the same base name as the executable.
32 SIMPLE_PROGRAMS += names
33 SOURCES += ["%s%s" % (name, ext) for name in names]
39 def CppUnitTests(names, ext=".cpp"):
40 """Template for C++ unit tests.
42 Those have a single source with the same base name as the executable.
44 COMPILE_FLAGS["EXTRA_INCLUDES"] = [
45 "-I%s/dist/include" % TOPOBJDIR,
46 "-I%s/dist/include/testing" % TOPOBJDIR,
48 CPP_UNIT_TESTS += names
49 SOURCES += ["%s%s" % (name, ext) for name in names]
56 """Template for libraries."""
61 def AllowCompilerWarnings():
62 COMPILE_FLAGS["WARNINGS_AS_ERRORS"] = []
63 WASM_FLAGS["WARNINGS_AS_ERRORS"] = []
67 def DisableCompilerWarnings():
68 # Keep the -Wno-* flags to disable warnings that may be enabled through other means.
70 return [f for f in flags or [] if f.startswith("-Wno-")]
72 COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_CFLAGS"])
73 COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_CXXFLAGS"])
74 HOST_COMPILE_FLAGS["WARNINGS_CFLAGS"] = filter(CONFIG["WARNINGS_HOST_CFLAGS"])
75 HOST_COMPILE_FLAGS["WARNINGS_CXXFLAGS"] = filter(CONFIG["WARNINGS_HOST_CXXFLAGS"])
79 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
80 """Template for Rust libraries."""
83 IS_RUST_LIBRARY = True
84 # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
85 AllowCompilerWarnings()
87 # And furthermore, don't even show warnings for them, so they don't regress
88 # the Compiler Warnings build metric
89 # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
90 DisableCompilerWarnings()
93 RUST_LIBRARY_FEATURES = features
96 RUST_LIBRARY_OUTPUT_CATEGORY = output_category
103 def SharedLibrary(name, output_category=None):
104 """Template for shared libraries."""
107 FORCE_SHARED_LIB = True
110 SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
116 def Framework(name, output_category=None):
117 """Template for OSX Frameworks."""
118 SharedLibrary(name, output_category)
124 def HostProgram(name):
125 """Template for build tools executables."""
130 def HostSimplePrograms(names, ext=".cpp"):
131 """Template for simple build tools executables.
133 Those have a single source with the same base name as the executable.
135 HOST_SIMPLE_PROGRAMS += names
136 HOST_SOURCES += ["%s%s" % (name.replace("host_", ""), ext) for name in names]
140 def HostSharedLibrary(name):
141 """Template for build tools libraries."""
142 if name != "clang-plugin":
144 "Please make sure host shared library support is complete "
145 "before using for something else than the clang plugin"
148 HOST_LIBRARY_NAME = name
150 FORCE_SHARED_LIB = True
154 def HostLibrary(name):
155 """Template for build tools libraries."""
156 HOST_LIBRARY_NAME = name
160 def HostRustLibrary(name, features=None):
161 """Template for host Rust libraries."""
164 IS_RUST_LIBRARY = True
165 # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
166 AllowCompilerWarnings()
169 HOST_RUST_LIBRARY_FEATURES = features
173 def DisableStlWrapping():
174 COMPILE_FLAGS["STL"] = []
178 def NoVisibilityFlags():
179 COMPILE_FLAGS["VISIBILITY"] = []
183 def ForceInclude(*headers):
184 """Force includes a set of header files in C++ compilations"""
185 if CONFIG["CC_TYPE"] == "clang-cl":
188 include_flag = "-include"
189 for header in headers:
190 CXXFLAGS += [include_flag, header]
194 def GeneratedFile(name, *names, **kwargs):
195 """Add one or more GENERATED_FILES with the given attributes.
197 You must pass in at least one generated file (the "name" argument). Other
198 names can be included as positional arguments after "name"."""
199 script = kwargs.pop("script", None)
200 entry_point = kwargs.pop("entry_point", None)
201 inputs = kwargs.pop("inputs", [])
202 flags = kwargs.pop("flags", [])
203 force = kwargs.pop("force", False)
205 error("Unrecognized argument(s) to GeneratedFile: %s" % ", ".join(kwargs))
206 if entry_point and not script:
207 error("entry_point cannot be provided if script is not provided")
208 if script and ":" in script:
210 "script should not include a `:`. If you want to provide an "
211 "alternative entry point for your script, use the entry_point "
215 key = (name,) + names if names else name
216 GENERATED_FILES += [key]
217 generated_file = GENERATED_FILES[key]
218 if script and not entry_point:
219 generated_file.script = script
220 if script and entry_point:
221 generated_file.script = script + ":" + entry_point
222 generated_file.inputs = inputs
223 generated_file.flags = flags
224 generated_file.force = force
228 def CbindgenHeader(name, inputs):
229 """Add one GENERATED_FILES by running RunCbindgen.py"""
231 inputs = ["!/config/cbindgen-metadata.json"] + inputs
233 name, script="/build/RunCbindgen.py", entry_point="generate", inputs=inputs
237 include("gecko_templates.mozbuild")