xref: /aosp_15_r20/external/angle/build/config/coverage/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2017 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Workerimport("//build/buildflag_header.gni")
6*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/coverage/coverage.gni")
7*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/rust.gni")
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Workerconfig("default_coverage") {
10*8975f5c5SAndroid Build Coastguard Worker  if (use_clang_coverage) {
11*8975f5c5SAndroid Build Coastguard Worker    configs = []
12*8975f5c5SAndroid Build Coastguard Worker    ldflags = []
13*8975f5c5SAndroid Build Coastguard Worker    rustflags = []
14*8975f5c5SAndroid Build Coastguard Worker    if (!is_win) {
15*8975f5c5SAndroid Build Coastguard Worker      ldflags += [ "-fprofile-instr-generate" ]
16*8975f5c5SAndroid Build Coastguard Worker    } else {
17*8975f5c5SAndroid Build Coastguard Worker      # Windows directly calls link.exe instead of the compiler driver when
18*8975f5c5SAndroid Build Coastguard Worker      # linking, and embeds the path to the profile runtime library as
19*8975f5c5SAndroid Build Coastguard Worker      # dependent library into each object file.
20*8975f5c5SAndroid Build Coastguard Worker      #
21*8975f5c5SAndroid Build Coastguard Worker      # However... some build targets have no C++ object file (they have Rust
22*8975f5c5SAndroid Build Coastguard Worker      # instead), and thus the linker ends up not pulling in the profile
23*8975f5c5SAndroid Build Coastguard Worker      # library. So we add an edge to it directly.
24*8975f5c5SAndroid Build Coastguard Worker      if (toolchain_has_rust) {
25*8975f5c5SAndroid Build Coastguard Worker        configs += [ "//build/config/clang:compiler_profile" ]
26*8975f5c5SAndroid Build Coastguard Worker      }
27*8975f5c5SAndroid Build Coastguard Worker    }
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker    cflags = [
30*8975f5c5SAndroid Build Coastguard Worker      "-fprofile-instr-generate",
31*8975f5c5SAndroid Build Coastguard Worker      "-fcoverage-mapping",
32*8975f5c5SAndroid Build Coastguard Worker      "-mllvm",
33*8975f5c5SAndroid Build Coastguard Worker      "-runtime-counter-relocation=true",
34*8975f5c5SAndroid Build Coastguard Worker
35*8975f5c5SAndroid Build Coastguard Worker      # Following experimental flags removes unused header functions from the
36*8975f5c5SAndroid Build Coastguard Worker      # coverage mapping data embedded in the test binaries, and the reduction
37*8975f5c5SAndroid Build Coastguard Worker      # of binary size enables building Chrome's large unit test targets on
38*8975f5c5SAndroid Build Coastguard Worker      # MacOS. Please refer to crbug.com/796290 for more details.
39*8975f5c5SAndroid Build Coastguard Worker      "-mllvm",
40*8975f5c5SAndroid Build Coastguard Worker      "-limited-coverage-experimental=true",
41*8975f5c5SAndroid Build Coastguard Worker    ]
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker    # Rust coverage is gated on using the Chromium-built Rust toolchain as it
44*8975f5c5SAndroid Build Coastguard Worker    # needs to have a compatible LLVM version with the C++ compiler and the LLVM
45*8975f5c5SAndroid Build Coastguard Worker    # tools that will be used to process the coverage output. This is because
46*8975f5c5SAndroid Build Coastguard Worker    # the coverage file format is not stable.
47*8975f5c5SAndroid Build Coastguard Worker    if (use_chromium_rust_toolchain) {
48*8975f5c5SAndroid Build Coastguard Worker      rustflags += [
49*8975f5c5SAndroid Build Coastguard Worker        "-Cinstrument-coverage",
50*8975f5c5SAndroid Build Coastguard Worker        "-Cllvm-args=-runtime-counter-relocation",
51*8975f5c5SAndroid Build Coastguard Worker      ]
52*8975f5c5SAndroid Build Coastguard Worker    }
53*8975f5c5SAndroid Build Coastguard Worker
54*8975f5c5SAndroid Build Coastguard Worker    if (is_linux || is_chromeos) {
55*8975f5c5SAndroid Build Coastguard Worker      # TODO(crbug.com/40175589): Remove this flag.
56*8975f5c5SAndroid Build Coastguard Worker      cflags += [ "-fno-use-cxa-atexit" ]
57*8975f5c5SAndroid Build Coastguard Worker    }
58*8975f5c5SAndroid Build Coastguard Worker  }
59*8975f5c5SAndroid Build Coastguard Worker}
60*8975f5c5SAndroid Build Coastguard Worker
61*8975f5c5SAndroid Build Coastguard Workerbuildflag_header("buildflags") {
62*8975f5c5SAndroid Build Coastguard Worker  header = "buildflags.h"
63*8975f5c5SAndroid Build Coastguard Worker  flags = [ "USE_JAVASCRIPT_COVERAGE=$use_javascript_coverage" ]
64*8975f5c5SAndroid Build Coastguard Worker}
65