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 DisableWarningsForRust():
80 """Template to disable warnings when compiling rust (rust build scripts
81 compile C/C++ sources which we can't control easily). Meant to be used by
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()
94 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
95 """Template for Rust libraries."""
98 IS_RUST_LIBRARY = True
100 DisableWarningsForRust()
103 RUST_LIBRARY_FEATURES = features
106 RUST_LIBRARY_OUTPUT_CATEGORY = output_category
113 def RustProgram(name):
114 """Template for Rust programs."""
115 RUST_PROGRAMS += [name]
116 DisableWarningsForRust()
120 def SharedLibrary(name, output_category=None):
121 """Template for shared libraries."""
124 FORCE_SHARED_LIB = True
127 SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
133 def Framework(name, output_category=None):
134 """Template for OSX Frameworks."""
135 SharedLibrary(name, output_category)
141 def HostProgram(name):
142 """Template for build tools executables."""
147 def HostSimplePrograms(names, ext=".cpp"):
148 """Template for simple build tools executables.
150 Those have a single source with the same base name as the executable.
152 HOST_SIMPLE_PROGRAMS += names
153 HOST_SOURCES += ["%s%s" % (name.replace("host_", ""), ext) for name in names]
157 def HostSharedLibrary(name):
158 """Template for build tools libraries."""
159 if name != "clang-plugin":
161 "Please make sure host shared library support is complete "
162 "before using for something else than the clang plugin"
165 HOST_LIBRARY_NAME = name
167 FORCE_SHARED_LIB = True
171 def HostLibrary(name):
172 """Template for build tools libraries."""
173 HOST_LIBRARY_NAME = name
177 def HostRustLibrary(name, features=None):
178 """Template for host Rust libraries."""
181 IS_RUST_LIBRARY = True
182 # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
183 AllowCompilerWarnings()
186 HOST_RUST_LIBRARY_FEATURES = features
190 def DisableStlWrapping():
191 COMPILE_FLAGS["STL"] = []
195 def NoVisibilityFlags():
196 COMPILE_FLAGS["VISIBILITY"] = []
200 def ForceInclude(*headers):
201 """Force includes a set of header files in C++ compilations"""
202 if CONFIG["CC_TYPE"] == "clang-cl":
205 include_flag = "-include"
206 for header in headers:
207 CXXFLAGS += [include_flag, header]
211 def GeneratedFile(name, *names, **kwargs):
212 """Add one or more GENERATED_FILES with the given attributes.
214 You must pass in at least one generated file (the "name" argument). Other
215 names can be included as positional arguments after "name"."""
216 script = kwargs.pop("script", None)
217 entry_point = kwargs.pop("entry_point", None)
218 inputs = kwargs.pop("inputs", [])
219 flags = kwargs.pop("flags", [])
220 force = kwargs.pop("force", False)
222 error("Unrecognized argument(s) to GeneratedFile: %s" % ", ".join(kwargs))
223 if entry_point and not script:
224 error("entry_point cannot be provided if script is not provided")
225 if script and ":" in script:
227 "script should not include a `:`. If you want to provide an "
228 "alternative entry point for your script, use the entry_point "
232 key = (name,) + names if names else name
233 GENERATED_FILES += [key]
234 generated_file = GENERATED_FILES[key]
235 if script and not entry_point:
236 generated_file.script = script
237 if script and entry_point:
238 generated_file.script = script + ":" + entry_point
239 generated_file.inputs = inputs
240 generated_file.flags = flags
241 generated_file.force = force
245 def CbindgenHeader(name, inputs):
246 """Add one GENERATED_FILES by running RunCbindgen.py"""
248 inputs = ["!/config/cbindgen-metadata.json"] + inputs
250 name, script="/build/RunCbindgen.py", entry_point="generate", inputs=inputs
254 include("gecko_templates.mozbuild")