diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /config/makefiles | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'config/makefiles')
-rw-r--r-- | config/makefiles/autotargets.mk | 93 | ||||
-rw-r--r-- | config/makefiles/debugmake.mk | 116 | ||||
-rw-r--r-- | config/makefiles/functions.mk | 30 | ||||
-rw-r--r-- | config/makefiles/makeutils.mk | 121 | ||||
-rw-r--r-- | config/makefiles/nonrecursive.mk | 68 | ||||
-rw-r--r-- | config/makefiles/rust.mk | 417 | ||||
-rw-r--r-- | config/makefiles/target_binaries.mk | 43 | ||||
-rw-r--r-- | config/makefiles/xpidl/Makefile.in | 90 |
8 files changed, 978 insertions, 0 deletions
diff --git a/config/makefiles/autotargets.mk b/config/makefiles/autotargets.mk new file mode 100644 index 0000000000..a3a073b359 --- /dev/null +++ b/config/makefiles/autotargets.mk @@ -0,0 +1,93 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# 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/. +# + +ifndef INCLUDED_AUTOTARGETS_MK #{ + +# Conditional does not wrap the entire file so multiple +# includes will be able to accumulate dependencies. + +########################################################################### +# AUTO_DEPS - A list of deps/targets drived from other macros. +########################################################################### + +MKDIR ?= mkdir -p +TOUCH ?= touch + +# declare for local use, rules.mk may not have been loaded +space = $(NULL) $(NULL) + +# Deps will be considered intermediate when used as a pre-requisite for +# wildcard targets. Inhibit their removal, mkdir -p is a standalone op. +.PRECIOUS: %/.mkdir.done + +######################### +##---] FUNCTIONS [---## +######################### + +# Squeeze can be overzealous, restore root for abspath +getPathPrefix =$(if $(filter /%,$(1)),/) + +# Squeeze '//' from the path, easily created by string functions +_slashSqueeze =$(foreach val,$(getargv),$(call getPathPrefix,$(val))$(subst $(space),/,$(strip $(subst /,$(space),$(val))))) + +# Squeeze extraneous directory slashes from the path +# o protect embedded spaces within the path +# o replace //+ sequences with / +slash_strip = \ + $(strip \ + $(subst <--[**]-->,$(space),\ + $(call _slashSqueeze,\ + $(subst $(space),<--[**]-->,$(1))\ + ))) + +# Extract directory path from a dependency file. +mkdir_stem =$(foreach val,$(getargv),$(subst /.mkdir.done,$(NULL),$(val))) + +## Generate timestamp file for threadsafe directory creation +mkdir_deps =$(foreach dir,$(getargv),$(call slash_strip,$(dir)/.mkdir.done)) + +####################### +##---] TARGETS [---## +####################### + +%/.mkdir.done: # mkdir -p -p => mkdir -p + $(subst $(space)-p,$(null),$(MKDIR)) -p '$(dir $@)' +# Make the timestamp old enough for not being a problem with symbolic links +# targets depending on it. Use Jan 3, 1980 to accomodate any timezone where +# 198001010000 would translate to something older than FAT epoch. + @$(TOUCH) -t 198001030000 '$@' + +# A handful of makefiles are attempting "mkdir dot". +# tbpl/valgrind builds are using this target +# https://bugzilla.mozilla.org/show_bug.cgi?id=837754 +.mkdir.done: + @echo 'WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)' + @$(TOUCH) -t 198001030000 '$@' + +INCLUDED_AUTOTARGETS_MK = 1 +endif #} + + +## Accumulate deps and cleanup +ifneq (,$(GENERATED_DIRS)) + GENERATED_DIRS := $(strip $(sort $(GENERATED_DIRS))) + tmpauto :=$(call mkdir_deps,GENERATED_DIRS) + GENERATED_DIRS_DEPS +=$(tmpauto) +endif + +################################################################# +# One ring/dep to rule them all: +# config/rules.mk::all target is available by default +# Add $(AUTO_DEPS) as an explicit target dependency when needed. +################################################################# + +AUTO_DEPS +=$(GENERATED_DIRS_DEPS) +AUTO_DEPS := $(strip $(sort $(AUTO_DEPS))) + +# Complain loudly if deps have not loaded so getargv != $(NULL) +$(call requiredfunction,getargv) diff --git a/config/makefiles/debugmake.mk b/config/makefiles/debugmake.mk new file mode 100644 index 0000000000..b1cd05bfe5 --- /dev/null +++ b/config/makefiles/debugmake.mk @@ -0,0 +1,116 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# 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/. +# + +########################################################################### +## Intent: Helper targets for displaying variables and state information +########################################################################### + +# Support usage outside of config/rules.mk +ifndef INCLUDED_DEBUGMAKE_MK #{ + +define CR + + +endef + +define shell_quote +'$(subst $(CR),\$(CR),$(subst ','\'',$(1)))' +endef + +echo-variable-%: + @echo $(call shell_quote,$($*)) + +echo-dirs: + @echo $(call shell_quote,$(DIRS)) + +define print_var +@printf '%20s = %s\n' $1 $(call shell_quote,$($1)) + +endef + +define print_vars +$(foreach var,$1,$(call print_var,$(var))) +endef + +showtargs: +ifneq (,$(filter $(PROGRAM) $(HOST_PROGRAM) $(SIMPLE_PROGRAMS) $(LIBRARY) $(SHARED_LIBRARY),$(TARGETS))) + @echo -------------------------------------------------------------------------------- + $(call print_vars,\ + PROGRAM \ + SIMPLE_PROGRAMS \ + LIBRARY \ + SHARED_LIBRARY \ + LIBS \ + DEF_FILE \ + IMPORT_LIBRARY \ + STATIC_LIBS \ + SHARED_LIBS \ + EXTRA_DSO_LDOPTS \ + DEPENDENT_LIBS \ + ) + @echo -------------------------------------------------------------------------------- +endif + $(LOOP_OVER_DIRS) + +showbuild showhost: _DEPEND_CFLAGS= +showbuild showhost: COMPILE_PDB_FLAG= +showbuild: + $(call print_vars,\ + MOZ_WIDGET_TOOLKIT \ + CC \ + CXX \ + CCC \ + CPP \ + LD \ + AR \ + IMPLIB \ + FILTER \ + MKSHLIB \ + MKCSHLIB \ + RC \ + CFLAGS \ + OS_CFLAGS \ + COMPILE_CFLAGS \ + CXXFLAGS \ + OS_CXXFLAGS \ + COMPILE_CXXFLAGS \ + COMPILE_CMFLAGS \ + COMPILE_CMMFLAGS \ + LDFLAGS \ + OS_LDFLAGS \ + DSO_LDOPTS \ + OS_INCLUDES \ + OS_LIBS \ + BIN_FLAGS \ + INCLUDES \ + DEFINES \ + ACDEFINES \ + BIN_SUFFIX \ + LIB_SUFFIX \ + DLL_SUFFIX \ + IMPORT_LIB_SUFFIX \ + INSTALL \ + VPATH \ + ) + +showhost: + $(call print_vars,\ + HOST_CC \ + HOST_CXX \ + HOST_CFLAGS \ + HOST_LDFLAGS \ + HOST_LIBS \ + HOST_EXTRA_LIBS \ + HOST_EXTRA_DEPS \ + HOST_PROGRAM \ + HOST_OBJS \ + HOST_PROGOBJS \ + ) + +INCLUDED_DEBUGMAKE_MK = 1 +endif #} diff --git a/config/makefiles/functions.mk b/config/makefiles/functions.mk new file mode 100644 index 0000000000..93282c4029 --- /dev/null +++ b/config/makefiles/functions.mk @@ -0,0 +1,30 @@ +# +# 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/. + +# +# functions.mk +# +# Defines functions that are needed by various Makefiles throughout the build +# system, which are needed before config.mk can be included. +# + +# Define an include-at-most-once flag +ifdef INCLUDED_FUNCTIONS_MK +$(error Do not include functions.mk twice!) +endif +INCLUDED_FUNCTIONS_MK = 1 + +core_abspath = $(error core_abspath is unsupported, use $$(abspath) instead) +core_realpath = $(error core_realpath is unsupported) + +core_winabspath = $(error core_winabspath is unsupported) + +# Run a named Python build action. The first argument is the name of the build +# action. The second argument are the arguments to pass to the action (space +# delimited arguments). e.g. +# +# libs:: +# $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest) +py_action = $(PYTHON3) -m mozbuild.action.$(1) $(2) diff --git a/config/makefiles/makeutils.mk b/config/makefiles/makeutils.mk new file mode 100644 index 0000000000..95c7791a4b --- /dev/null +++ b/config/makefiles/makeutils.mk @@ -0,0 +1,121 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# 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/. + +## Identify function argument types +istype =$(if $(value ${1}),list,scalar) +isval =$(if $(filter-out list,$(call istype,${1})),true) +isvar =$(if $(filter-out scalar,$(call istype,${1})),true) + +# Access up to 9 arguments passed, option needed to emulate $* +# Inline for function expansion, do not use $(call ) +argv =$(strip +argv +=$(if $(1), $(1))$(if $(2), $(2))$(if $(3), $(3))$(if $(4), $(4)) +argv +=$(if $(5), $(5))$(if $(6), $(6))$(if $(7), $(7))$(if $(8), $(8)) +argv +=$(if $(9), $(9)) +argv +=$(if $(10), $(error makeutils.mk::argv can only handle 9 arguments)) +argv +=) + +########################################################################### +## Access function args as a simple list, inline within user functions. +## Usage: $(info ** $(call banner,$(getargv))) +## $(call banner,scalar) +## $(call banner,list0 list1 list2) +## $(call banner,ref) ; ref=foo bar tans +## getarglist() would be a more accurate name but is longer to type +getargv = $(if $(call isvar,$(1)),$($(1)),$(argv)) + +########################################################################### +# Strip [n] leading options from an argument list. This will allow passing +# extra args to user functions that will not propogate to sub-$(call )'s +# Usage: $(call subargv,2) +subargv =$(wordlist $(1),$(words $(getargv)),$(getargv)) + +########################################################################### +# Intent: Display a distinct banner heading in the output stream +# Usage: $(call banner,BUILDING: foo bar tans) +# Debug: +# target-preqs = \ +# $(call banner,target-preqs-BEGIN) \ +# foo bar tans \ +# $(call banner,target-preqs-END) \ +# $(NULL) +# target: $(target-preqs) + +banner = \ +$(info ) \ +$(info ***************************************************************************) \ +$(info ** $(getargv)) \ +$(info ***************************************************************************) \ +$(NULL) + +##################################################################### +# Intent: Determine if a string or pattern is contained in a list +# Usage: strcmp - $(call if_XinY,clean,$(MAKECMDGOALS)) +# : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS)) +is_XinY =$(filter $(1),$(call subargv,3,$(getargv))) + +##################################################################### +# Provide an alternate var to support testing +ifdef MAKEUTILS_UNIT_TEST + mcg_goals=TEST_MAKECMDGOALS +else + mcg_goals=MAKECMDGOALS +endif + +# Intent: Conditionals for detecting common/tier target use +isTargetStem = $(sort \ + $(foreach var,$(getargv),\ + $(foreach pat,$(var)% %$(var),\ + $(call is_XinY,$(pat),${$(mcg_goals)})\ + ))) +isTargetStemClean = $(call isTargetStem,clean) +isTargetStemExport = $(call isTargetStem,export) +isTargetStemLibs = $(call isTargetStem,libs) +isTargetStemTools = $(call isTargetStem,tools) + +################################################## +# Intent: Validation functions / unit test helpers + +errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)])) + +# Intent: verify function declaration exists +requiredfunction =$(foreach func,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if $(value $(func)),$(NULL),$(error required function [$(func)] is unavailable))) + + + +## http://www.gnu.org/software/make/manual/make.html#Call-Function +## Usage: o = $(call map,origin,o map $(MAKE)) +map = $(foreach val,$(2),$(call $(1),$(val))) + + +## Disable checking for clean targets +ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{ + +# Usage: $(call checkIfEmpty,[error|warning] foo NULL bar) +checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(NOP),$(call $(1),Variable $(var) does not contain a value))) + +# Usage: $(call errorIfEmpty,foo NULL bar) +errorIfEmpty =$(call checkIfEmpty,error $(argv)) +warnIfEmpty =$(call checkIfEmpty,warning $(argv)) + +endif #} + +########################################################################### +## Common makefile library loader +########################################################################### +ifdef MOZILLA_DIR +topORerr = $(MOZILLA_DIR) +else +topORerr = $(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined)) +endif + +ifdef USE_AUTOTARGETS_MK # mkdir_deps + include $(topORerr)/config/makefiles/autotargets.mk +endif + +## copy(src, dst): recursive copy +copy_dir = (cd $(1)/. && $(TAR) $(TAR_CREATE_FLAGS) - .) | (cd $(2)/. && tar -xf -) diff --git a/config/makefiles/nonrecursive.mk b/config/makefiles/nonrecursive.mk new file mode 100644 index 0000000000..498de568e7 --- /dev/null +++ b/config/makefiles/nonrecursive.mk @@ -0,0 +1,68 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# 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/. + +# The purpose of this file is to pull in non-recursive targets when performing +# a partial tree (not top-level) build. This will allow people to continue to +# build individual directories while some of the targets may not be normally +# defined in that make file. +# +# Non-recursive targets are attached to existing make targets. The +# NONRECURSIVE_TARGETS variable lists the make targets that modified. For +# each target in this list, the NONRECURSIVE_TARGET_<target> variable will +# contain a list of partial variable names. We will then look in variables +# named NONRECURSIVE_TARGETS_<target>_<fragment>_* for information describing +# how to evaluate non-recursive make targets. +# +# Targets are defined by the following variables: +# +# FILE - The make file to evaluate. This is equivalent to +# |make -f <FILE>| +# DIRECTORY - The directory whose Makefile to evaluate. This is +# equivalent to |make -C <DIRECTORY>|. +# TARGETS - Targets to evaluate in that make file. +# +# Only 1 of FILE or DIRECTORY may be defined. +# +# For example: +# +# NONRECURSIVE_TARGETS = export libs +# NONRECURSIVE_TARGETS_export = headers +# NONRECURSIVE_TARGETS_export_headers_FILE = /path/to/exports.mk +# NONRECURSIVE_TARGETS_export_headers_TARGETS = $(DIST)/include/foo.h $(DIST)/include/bar.h +# NONRECURSIVE_TARGETS_libs = cppsrcs +# NONRECURSIVE_TARGETS_libs_cppsrcs_DIRECTORY = $(DEPTH)/foo +# NONRECURSIVE_TARGETS_libs_cppsrcs_TARGETS = /path/to/foo.o /path/to/bar.o +# +# Will get turned into the following: +# +# exports:: +# $(MAKE) -C $(DEPTH) -f /path/to/exports.mk $(DIST)/include/foo.h $(DIST)/include/bar.h +# +# libs:: +# $(MAKE) -C $(DEPTH)/foo /path/to/foo.o /path/to/bar.o + +ifndef INCLUDED_NONRECURSIVE_MK + +define define_nonrecursive_target +$(1):: + $$(MAKE) -C $(or $(4),$$(DEPTH)) $(addprefix -f ,$(3)) $(2) +endef + +$(foreach target,$(NONRECURSIVE_TARGETS), \ + $(foreach entry,$(NONRECURSIVE_TARGETS_$(target)), \ + $(eval $(call define_nonrecursive_target, \ + $(target), \ + $(NONRECURSIVE_TARGETS_$(target)_$(entry)_TARGETS), \ + $(NONRECURSIVE_TARGETS_$(target)_$(entry)_FILE), \ + $(NONRECURSIVE_TARGETS_$(target)_$(entry)_DIRECTORY), \ + )) \ + ) \ +) + +INCLUDED_NONRECURSIVE_MK := 1 +endif + diff --git a/config/makefiles/rust.mk b/config/makefiles/rust.mk new file mode 100644 index 0000000000..79f5624937 --- /dev/null +++ b/config/makefiles/rust.mk @@ -0,0 +1,417 @@ +# 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/. + +# /!\ In this file, we export multiple variables globally via make rather than +# in recipes via the `env` command to avoid round-trips to msys on Windows, which +# tend to break environment variable values in interesting ways. + +# /!\ Avoid the use of double-quotes in this file, so that the cargo +# commands can be executed directly by make, without doing a round-trip +# through a shell. + +cargo_host_flag := --target=$(RUST_HOST_TARGET) +cargo_target_flag := --target=$(RUST_TARGET) + +# Permit users to pass flags to cargo from their mozconfigs (e.g. --color=always). +cargo_build_flags = $(CARGOFLAGS) +ifndef MOZ_DEBUG_RUST +cargo_build_flags += --release +endif + +# The Spidermonkey library can be built from a package tarball outside the +# tree, so we want to let Cargo create lock files in this case. When built +# within a tree, the Rust dependencies have been vendored in so Cargo won't +# touch the lock file. +ifndef JS_STANDALONE +cargo_build_flags += --frozen +endif + +cargo_build_flags += --manifest-path $(CARGO_FILE) +ifdef BUILD_VERBOSE_LOG +cargo_build_flags += -vv +endif + +# Enable color output if original stdout was a TTY and color settings +# aren't already present. This essentially restores the default behavior +# of cargo when running via `mach`. +ifdef MACH_STDOUT_ISATTY +ifeq (,$(findstring --color,$(cargo_build_flags))) +ifeq (WINNT,$(HOST_OS_ARCH)) +# Bug 1417003: color codes are non-trivial on Windows. For now, +# prefer black and white to broken color codes. +cargo_build_flags += --color=never +else +cargo_build_flags += --color=always +endif +endif +endif + +# Without -j > 1, make will not pass jobserver info down to cargo. Force +# one job when requested as a special case. +ifeq (1,$(MOZ_PARALLEL_BUILD)) +cargo_build_flags += -j1 +endif + +# We also need to rebuild the rust stdlib so that it's instrumented. Because +# build-std is still pretty experimental, we need to explicitly request +# the panic_abort crate for `panic = "abort"` support. +ifdef MOZ_TSAN +cargo_build_flags += -Zbuild-std=std,panic_abort +RUSTFLAGS += -Zsanitizer=thread +endif + +# These flags are passed via `cargo rustc` and only apply to the final rustc +# invocation (i.e., only the top-level crate, not its dependencies). +cargo_rustc_flags = $(CARGO_RUSTCFLAGS) +ifndef DEVELOPER_OPTIONS +ifndef MOZ_DEBUG_RUST +# Enable link-time optimization for release builds, but not when linking +# gkrust_gtest. And not when doing cross-language LTO. +ifndef MOZ_LTO_RUST_CROSS +ifeq (,$(findstring gkrust_gtest,$(RUST_LIBRARY_FILE))) +cargo_rustc_flags += -Clto +endif +# We need -Cembed-bitcode=yes for all crates when using -Clto. +RUSTFLAGS += -Cembed-bitcode=yes +endif +endif +endif + +ifdef CARGO_INCREMENTAL +export CARGO_INCREMENTAL +endif + +rustflags_neon = +ifeq (neon,$(MOZ_FPU)) +# Enable neon and disable restriction to 16 FPU registers +# (CPUs with neon have 32 FPU registers available) +rustflags_neon += -C target_feature=+neon,-d16 +endif + +rustflags_sancov = +ifdef LIBFUZZER +ifndef MOZ_TSAN +# These options should match what is implicitly enabled for `clang -fsanitize=fuzzer` +# here: https://github.com/llvm/llvm-project/blob/release/8.x/clang/lib/Driver/SanitizerArgs.cpp#L354 +# +# -sanitizer-coverage-inline-8bit-counters Increments 8-bit counter for every edge. +# -sanitizer-coverage-level=4 Enable coverage for all blocks, critical edges, and indirect calls. +# -sanitizer-coverage-trace-compares Tracing of CMP and similar instructions. +# -sanitizer-coverage-pc-table Create a static PC table. +# +# In TSan builds, we must not pass any of these, because sanitizer coverage is incompatible with TSan. +rustflags_sancov += -Cpasses=sancov -Cllvm-args=-sanitizer-coverage-inline-8bit-counters -Cllvm-args=-sanitizer-coverage-level=4 -Cllvm-args=-sanitizer-coverage-trace-compares -Cllvm-args=-sanitizer-coverage-pc-table +endif +endif + +rustflags_override = $(MOZ_RUST_DEFAULT_FLAGS) $(rustflags_neon) + +ifdef DEVELOPER_OPTIONS +# By default the Rust compiler will perform a limited kind of ThinLTO on each +# crate. For local builds this additional optimization is not worth the +# increase in compile time so we opt out of it. +rustflags_override += -Clto=off +endif + +ifdef MOZ_USING_SCCACHE +export RUSTC_WRAPPER=$(CCACHE) +endif + +ifneq (,$(MOZ_ASAN)$(MOZ_TSAN)$(MOZ_UBSAN)) +ifndef CROSS_COMPILE +NATIVE_SANITIZERS=1 +endif # CROSS_COMPILE +endif + +# We start with host variables because the rust host and the rust target might be the same, +# in which case we want the latter to take priority. + +# We're passing these for consumption by the `cc` crate, which doesn't use the same +# convention as cargo itself: +# https://github.com/alexcrichton/cc-rs/blob/baa71c0e298d9ad7ac30f0ad78f20b4b3b3a8fb2/src/lib.rs#L1715 +rust_host_cc_env_name := $(subst -,_,$(RUST_HOST_TARGET)) + +# HOST_CC/HOST_CXX/CC/CXX usually contain base flags for e.g. the build target. +# We want to pass those through CFLAGS_*/CXXFLAGS_* instead, so that they end up +# after whatever cc-rs adds to the compiler command line, so that they win. +# Ideally, we'd use CRATE_CC_NO_DEFAULTS=1, but that causes other problems at the +# moment. +export CC_$(rust_host_cc_env_name)=$(filter-out $(HOST_CC_BASE_FLAGS),$(HOST_CC)) +export CXX_$(rust_host_cc_env_name)=$(filter-out $(HOST_CXX_BASE_FLAGS),$(HOST_CXX)) +# We don't have a HOST_AR. If rust needs one, assume it's going to pick an appropriate one. + +rust_cc_env_name := $(subst -,_,$(RUST_TARGET)) + +export CC_$(rust_cc_env_name)=$(filter-out $(CC_BASE_FLAGS),$(CC)) +export CXX_$(rust_cc_env_name)=$(filter-out $(CXX_BASE_FLAGS),$(CXX)) +export AR_$(rust_cc_env_name)=$(AR) + +ifeq (WINNT,$(HOST_OS_ARCH)) +HOST_CC_BASE_FLAGS += -DUNICODE +HOST_CXX_BASE_FLAGS += -DUNICODE +CC_BASE_FLAGS += -DUNICODE +CXX_BASE_FLAGS += -DUNICODE +endif + +ifeq (,$(NATIVE_SANITIZERS)$(MOZ_CODE_COVERAGE)) +# -DMOZILLA_CONFIG_H is added to prevent mozilla-config.h from injecting anything +# in C/C++ compiles from rust. That's not needed in the other branch because the +# base flags don't force-include mozilla-config.h. +export CFLAGS_$(rust_host_cc_env_name)=$(HOST_CC_BASE_FLAGS) $(COMPUTED_HOST_CFLAGS) -DMOZILLA_CONFIG_H +export CXXFLAGS_$(rust_host_cc_env_name)=$(HOST_CXX_BASE_FLAGS) $(COMPUTED_HOST_CXXFLAGS) -DMOZILLA_CONFIG_H +export CFLAGS_$(rust_cc_env_name)=$(CC_BASE_FLAGS) $(COMPUTED_CFLAGS) -DMOZILLA_CONFIG_H +export CXXFLAGS_$(rust_cc_env_name)=$(CXX_BASE_FLAGS) $(COMPUTED_CXXFLAGS) -DMOZILLA_CONFIG_H +else +# Because cargo doesn't allow to distinguish builds happening for build +# scripts/procedural macros vs. those happening for the rust target, +# we can't blindly pass all our flags down for cc-rs to use them, because of the +# side effects they can have on what otherwise should be host builds. +# So for sanitizer and coverage builds, we only pass the base compiler flags. +# This means C code built by rust is not going to be covered by sanitizer +# and coverage. But at least we control what compiler is being used, +# rather than relying on cc-rs guesses, which, sometimes fail us. +export CFLAGS_$(rust_host_cc_env_name)=$(HOST_CC_BASE_FLAGS) +export CXXFLAGS_$(rust_host_cc_env_name)=$(HOST_CXX_BASE_FLAGS) +export CFLAGS_$(rust_cc_env_name)=$(CC_BASE_FLAGS) +export CXXFLAGS_$(rust_cc_env_name)=$(CXX_BASE_FLAGS) +endif + +# Force the target down to all bindgen callers, even those that may not +# read BINDGEN_SYSTEM_FLAGS some way or another. +export BINDGEN_EXTRA_CLANG_ARGS:=$(filter --target=%,$(BINDGEN_SYSTEM_FLAGS)) +export CARGO_TARGET_DIR +export RUSTFLAGS +export RUSTC +export RUSTDOC +export RUSTFMT +export MOZ_SRC=$(topsrcdir) +export MOZ_DIST=$(ABS_DIST) +export LIBCLANG_PATH=$(MOZ_LIBCLANG_PATH) +export CLANG_PATH=$(MOZ_CLANG_PATH) +export PKG_CONFIG +export PKG_CONFIG_ALLOW_CROSS=1 +export RUST_BACKTRACE=full +export MOZ_TOPOBJDIR=$(topobjdir) +export PYTHON3 + +# Set COREAUDIO_SDK_PATH for third_party/rust/coreaudio-sys/build.rs +ifeq ($(OS_ARCH), Darwin) +ifdef MACOS_SDK_DIR +export COREAUDIO_SDK_PATH=$(MACOS_SDK_DIR) +endif +endif + +target_rust_ltoable := force-cargo-library-build +target_rust_nonltoable := force-cargo-test-run force-cargo-library-check $(foreach b,build check,force-cargo-program-$(b)) + +ifdef MOZ_PGO_RUST +ifdef MOZ_PROFILE_GENERATE +rust_pgo_flags := -C profile-generate=$(topobjdir) +# The C compiler may be passed extra llvm flags for PGO that we also want to pass to rust as well. +# In PROFILE_GEN_CFLAGS, they look like "-mllvm foo", and we want "-C llvm-args=foo", so first turn +# "-mllvm foo" into "-mllvm:foo" so that it becomes a unique argument, that we can then filter for, +# excluding other flags, and then turn into the right string. +rust_pgo_flags += $(patsubst -mllvm:%,-C llvm-args=%,$(filter -mllvm:%,$(subst -mllvm ,-mllvm:,$(PROFILE_GEN_CFLAGS)))) +else # MOZ_PROFILE_USE +rust_pgo_flags := -C profile-use=$(PGO_PROFILE_PATH) +endif +endif + +$(target_rust_ltoable): RUSTFLAGS:=$(rustflags_override) $(rustflags_sancov) $(RUSTFLAGS) $(if $(MOZ_LTO_RUST_CROSS),-Clinker-plugin-lto) $(rust_pgo_flags) +$(target_rust_nonltoable): RUSTFLAGS:=$(rustflags_override) $(rustflags_sancov) $(RUSTFLAGS) + +TARGET_RECIPES := $(target_rust_ltoable) $(target_rust_nonltoable) + +HOST_RECIPES := \ + $(foreach a,library program,$(foreach b,build check,force-cargo-host-$(a)-$(b))) + +$(HOST_RECIPES): RUSTFLAGS:=$(rustflags_override) + +# If this is a release build we want rustc to generate one codegen unit per +# crate. This results in better optimization and less code duplication at the +# cost of longer compile times. +ifndef DEVELOPER_OPTIONS +$(TARGET_RECIPES) $(HOST_RECIPES): RUSTFLAGS += -C codegen-units=1 +endif + +# We use the + prefix to pass down the jobserver fds to cargo, but we +# don't use the prefix when make -n is used, so that cargo doesn't run +# in that case) +define RUN_CARGO +$(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)$(CARGO) $(1) $(cargo_build_flags) +endef + +# This function is intended to be called by: +# +# $(call CARGO_BUILD,EXTRA_ENV_VAR1=X EXTRA_ENV_VAR2=Y ...) +# +# but, given the idiosyncracies of make, can also be called without arguments: +# +# $(call CARGO_BUILD) +define CARGO_BUILD +$(call RUN_CARGO,rustc) +endef + +define CARGO_CHECK +$(call RUN_CARGO,check) +endef + +cargo_host_linker_env_var := CARGO_TARGET_$(call varize,$(RUST_HOST_TARGET))_LINKER +cargo_linker_env_var := CARGO_TARGET_$(call varize,$(RUST_TARGET))_LINKER + +# Cargo needs the same linker flags as the C/C++ compiler, +# but not the final libraries. Filter those out because they +# cause problems on macOS 10.7; see bug 1365993 for details. +# Also, we don't want to pass PGO flags until cargo supports them. +export MOZ_CARGO_WRAP_LDFLAGS +export MOZ_CARGO_WRAP_LD +export MOZ_CARGO_WRAP_HOST_LDFLAGS +export MOZ_CARGO_WRAP_HOST_LD +# Exporting from make always exports a value. Setting a value per-recipe +# would export an empty value for the host recipes. When not doing a +# cross-compile, the --target for those is the same, and cargo will use +# CARGO_TARGET_*_LINKER for its linker, so we always pass the +# cargo-linker wrapper, and fill MOZ_CARGO_WRAP_{HOST_,}LD* more or less +# appropriately for all recipes. +ifeq (WINNT,$(HOST_OS_ARCH)) +# Use .bat wrapping on Windows hosts, and shell wrapping on other hosts. +# Like for CC/C*FLAGS, we want the target values to trump the host values when +# both variables are the same. +export $(cargo_host_linker_env_var):=$(topsrcdir)/build/cargo-host-linker.bat +export $(cargo_linker_env_var):=$(topsrcdir)/build/cargo-linker.bat +WRAP_HOST_LINKER_LIBPATHS:=$(HOST_LINKER_LIBPATHS_BAT) +else +export $(cargo_host_linker_env_var):=$(topsrcdir)/build/cargo-host-linker +export $(cargo_linker_env_var):=$(topsrcdir)/build/cargo-linker +WRAP_HOST_LINKER_LIBPATHS:=$(HOST_LINKER_LIBPATHS) +endif + +# Defining all of this for ASan/TSan builds results in crashes while running +# some crates's build scripts (!), so disable it for now. +# See https://github.com/rust-lang/cargo/issues/5754 +ifndef NATIVE_SANITIZERS +$(TARGET_RECIPES): MOZ_CARGO_WRAP_LDFLAGS:=$(filter-out -fsanitize=cfi% -framework Cocoa -lobjc AudioToolbox ExceptionHandling -fprofile-%,$(LDFLAGS)) +endif # NATIVE_SANITIZERS + +$(HOST_RECIPES): MOZ_CARGO_WRAP_LDFLAGS:=$(HOST_LDFLAGS) $(WRAP_HOST_LINKER_LIBPATHS) +$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LDFLAGS:=$(HOST_LDFLAGS) $(WRAP_HOST_LINKER_LIBPATHS) + +ifeq (,$(filter clang-cl,$(CC_TYPE))) +$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(CC) +else +$(TARGET_RECIPES): MOZ_CARGO_WRAP_LD:=$(LINKER) +endif + +ifeq (,$(filter clang-cl,$(HOST_CC_TYPE))) +$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_CC) +$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_CC) +else +$(HOST_RECIPES): MOZ_CARGO_WRAP_LD:=$(HOST_LINKER) +$(TARGET_RECIPES) $(HOST_RECIPES): MOZ_CARGO_WRAP_HOST_LD:=$(HOST_LINKER) +endif + +ifdef RUST_LIBRARY_FILE + +ifdef RUST_LIBRARY_FEATURES +rust_features_flag := --features '$(RUST_LIBRARY_FEATURES)' +endif + +# Assume any system libraries rustc links against are already in the target's LIBS. +# +# We need to run cargo unconditionally, because cargo is the only thing that +# has full visibility into how changes in Rust sources might affect the final +# build. +force-cargo-library-build: + $(REPORT_BUILD) + $(call CARGO_BUILD) --lib $(cargo_target_flag) $(rust_features_flag) -- $(cargo_rustc_flags) + +$(RUST_LIBRARY_FILE): force-cargo-library-build +# When we are building in --enable-release mode; we add an additional check to confirm +# that we are not importing any networking-related functions in rust code. This reduces +# the chance of proxy bypasses originating from rust code. +# The check only works when rust code is built with -Clto but without MOZ_LTO_RUST_CROSS. +# Sanitizers and sancov also fail because compiler-rt hooks network functions. +ifndef MOZ_PROFILE_GENERATE +ifeq ($(OS_ARCH), Linux) +ifeq (,$(rustflags_sancov)$(MOZ_ASAN)$(MOZ_TSAN)$(MOZ_UBSAN)) +ifndef MOZ_LTO_RUST_CROSS +ifneq (,$(filter -Clto,$(cargo_rustc_flags))) + $(call py_action,check_binary,--target --networking $@) +endif +endif +endif +endif +endif + +force-cargo-library-check: + $(call CARGO_CHECK) --lib $(cargo_target_flag) $(rust_features_flag) +else +force-cargo-library-check: + @true +endif # RUST_LIBRARY_FILE + +ifdef RUST_TESTS + +rust_test_options := $(foreach test,$(RUST_TESTS),-p $(test)) + +ifdef RUST_TEST_FEATURES +rust_test_features_flag := --features '$(RUST_TEST_FEATURES)' +endif + +# Don't stop at the first failure. We want to list all failures together. +rust_test_flag := --no-fail-fast + +force-cargo-test-run: + $(call RUN_CARGO,test $(cargo_target_flag) $(rust_test_flag) $(rust_test_options) $(rust_test_features_flag)) + +endif + +ifdef HOST_RUST_LIBRARY_FILE + +ifdef HOST_RUST_LIBRARY_FEATURES +host_rust_features_flag := --features '$(HOST_RUST_LIBRARY_FEATURES)' +endif + +force-cargo-host-library-build: + $(REPORT_BUILD) + $(call CARGO_BUILD) --lib $(cargo_host_flag) $(host_rust_features_flag) + +$(HOST_RUST_LIBRARY_FILE): force-cargo-host-library-build ; + +force-cargo-host-library-check: + $(call CARGO_CHECK) --lib $(cargo_host_flag) $(host_rust_features_flag) +else +force-cargo-host-library-check: + @true +endif # HOST_RUST_LIBRARY_FILE + +ifdef RUST_PROGRAMS + +force-cargo-program-build: $(call resfile,module) + $(REPORT_BUILD) + $(call CARGO_BUILD) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag) -- $(addprefix -C link-arg=$(CURDIR)/,$(call resfile,module)) + +$(RUST_PROGRAMS): force-cargo-program-build ; + +force-cargo-program-check: + $(call CARGO_CHECK) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag) +else +force-cargo-program-check: + @true +endif # RUST_PROGRAMS +ifdef HOST_RUST_PROGRAMS + +force-cargo-host-program-build: + $(REPORT_BUILD) + $(call CARGO_BUILD) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag) + +$(HOST_RUST_PROGRAMS): force-cargo-host-program-build ; + +force-cargo-host-program-check: + $(REPORT_BUILD) + $(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag) +else +force-cargo-host-program-check: + @true +endif # HOST_RUST_PROGRAMS diff --git a/config/makefiles/target_binaries.mk b/config/makefiles/target_binaries.mk new file mode 100644 index 0000000000..31b2c4367e --- /dev/null +++ b/config/makefiles/target_binaries.mk @@ -0,0 +1,43 @@ +# -*- makefile -*- +# vim:set ts=8 sw=8 sts=8 noet: +# +# 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/. + +ifndef NO_DIST_INSTALL + +ifneq (,$(strip $(SIMPLE_PROGRAMS)$(RUST_PROGRAMS))) +PROGRAMS_EXECUTABLES = $(SIMPLE_PROGRAMS) $(RUST_PROGRAMS) +PROGRAMS_DEST ?= $(FINAL_TARGET) +PROGRAMS_TARGET := target +INSTALL_TARGETS += PROGRAMS +endif + + +ifdef SHARED_LIBRARY +SHARED_LIBRARY_FILES = $(SHARED_LIBRARY) +SHARED_LIBRARY_DEST ?= $(FINAL_TARGET) +ifndef SHARED_LIBRARY_TARGET +SHARED_LIBRARY_TARGET = target +endif +INSTALL_TARGETS += SHARED_LIBRARY +endif # SHARED_LIBRARY + +ifdef WASM_LIBRARY +WASM_LIBRARY_FILES = $(WASM_LIBRARY) +WASM_LIBRARY_DEST ?= $(FINAL_TARGET) +WASM_LIBRARY_TARGET = target +INSTALL_TARGETS += WASM_LIBRARY +endif + +ifneq (,$(strip $(HOST_SIMPLE_PROGRAMS))) +HOST_PROGRAMS_EXECUTABLES = $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) +HOST_PROGRAMS_DEST ?= $(DIST)/host/bin +HOST_PROGRAMS_TARGET = host +INSTALL_TARGETS += HOST_PROGRAMS +endif + +endif # !NO_DIST_INSTALL + +# EOF diff --git a/config/makefiles/xpidl/Makefile.in b/config/makefiles/xpidl/Makefile.in new file mode 100644 index 0000000000..349820ea48 --- /dev/null +++ b/config/makefiles/xpidl/Makefile.in @@ -0,0 +1,90 @@ +# 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/. + +STANDALONE_MAKEFILE := 1 + +include $(topsrcdir)/config/rules.mk + +# Building XPIDLs effectively consists of two steps: +# +# 1) Staging all .idl files to a common directory. +# 2) Doing everything with the .idl files. +# +# Each .idl file is processed into a .h file and typelib information. +# The .h file shares the same stem as the input file and is installed +# in the common headers include directory. +# +# XPIDL files are logically grouped together by modules. The typelib +# information for all XPIDLs in the same module is linked together into +# an .xpt file having the name of the module. +# +# As an optimization to reduce overall CPU usage, we process all .idl +# belonging to a module with a single command invocation. This prevents +# redundant parsing of .idl files and significantly reduces CPU cycles. + +# For dependency files. +idl_deps_dir := .deps + +dist_idl_dir := $(DIST)/idl +dist_include_dir := $(DIST)/include +dist_xpcrs_dir := $(DIST)/xpcrs +stub_file := xptdata.stub +process_py := $(topsrcdir)/python/mozbuild/mozbuild/action/xpidl-process.py +target_file := $(topobjdir)/xpcom/reflect/xptinfo/xptdata.cpp +xptdata_h := $(dist_include_dir)/xptdata.h +generated_files := $(target_file) $(xptdata_h) +code_gen_py := $(topsrcdir)/xpcom/reflect/xptinfo/xptcodegen.py +code_gen_deps := $(topsrcdir)/xpcom/ds/tools/perfecthash.py + +# TODO we should use py_action, but that would require extra directories to be +# in the virtualenv. +%.xpt: + $(REPORT_BUILD) + $(PYTHON3) $(process_py) --depsdir $(idl_deps_dir) \ + --bindings-conf $(topsrcdir)/dom/bindings/Bindings.conf \ + $(foreach dir,$(all_idl_dirs),-I $(dir)) \ + $(dist_include_dir) $(dist_xpcrs_dir) $(@D) \ + $(basename $(notdir $@)) $($(basename $(notdir $@))_deps) +# When some IDL is added or removed, if the actual IDL file was already, or +# still is, in the tree, simple dependencies can't detect that the XPT needs +# to be rebuilt. +# Add the current value of $($(xpidl_module)_deps) in the depend file, such that +# we can later check if the value has changed since last build, which will +# indicate whether IDLs were added or removed. +# Note that removing previously built files is not covered. + @echo $(basename $(notdir $@))_deps_built = $($(basename $(notdir $@))_deps) >> $(idl_deps_dir)/$(basename $(notdir $@)).pp + +xpidl_modules := @xpidl_modules@ +xpt_files := $(addsuffix .xpt,$(xpidl_modules)) + +@xpidl_rules@ + +depends_files := $(foreach root,$(xpidl_modules),$(idl_deps_dir)/$(root).pp) + +ifdef COMPILE_ENVIRONMENT +xpidl:: $(generated_files) +endif + +# See bug 1420119 for why we need the semicolon. +$(target_file) $(xptdata_h) : $(stub_file) ; + +$(xpt_files): $(process_py) $(call mkdir_deps,$(idl_deps_dir) $(dist_include_dir) $(dist_xpcrs_dir)) + +$(stub_file) : $(xpt_files) $(code_gen_py) $(code_gen_deps) + $(REPORT_BUILD) + $(PYTHON3) $(code_gen_py) $(generated_files) $(xpt_files) + @touch $@ + +-include $(depends_files) + +define xpt_deps +$(1): $(call mkdir_deps,$(dir $(1))) +ifneq ($($(basename $(notdir $(1)))_deps),$($(basename $(notdir $(1)))_deps_built)) +$(1): FORCE +endif +endef + +$(foreach xpt,$(xpt_files),$(eval $(call xpt_deps,$(xpt)))) + +.PHONY: xpidl |