blob: 4f14a2813541fe11bc5f87168e0e451495c12bfe [file] [log] [blame]
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/compiler.gni")
import("//build/toolchain/goma.gni")
declare_args() {
# Clang crash reports directory path. Use empty path to disable altogether.
crash_diagnostics_dir = "$root_build_dir/clang-crashreports"
if (is_fuchsia) {
# Controls whether the compiler emits full stack frames for function calls.
# This reduces performance but increases the ability to generate good
# stack traces, especially when we have bugs around unwind table generation.
# It applies only for Fuchsia targets (see below where it is unset).
#
# TODO(ZX-2361): Theoretically unwind tables should be good enough so we can
# remove this option when the issues are addressed.
enable_frame_pointers = is_debug
}
}
# No frame pointers for host compiles.
if (!is_fuchsia) {
enable_frame_pointers = false
}
config("compiler") {
asmflags = []
cflags = [ "-fcolor-diagnostics" ]
cflags_c = []
cflags_cc = [ "-fvisibility-inlines-hidden" ]
cflags_objc = []
cflags_objcc = [ "-fvisibility-inlines-hidden" ]
ldflags = []
defines = []
configs = []
if (current_os == "fuchsia") {
configs += [ "//build/config/fuchsia:compiler" ]
} else {
cflags_c += [ "-std=c11" ]
cflags_cc += [
"-std=c++17",
"-stdlib=libc++",
]
if (current_os == "linux") {
configs += [ "//build/config/linux:compiler" ]
} else if (current_os == "mac") {
configs += [ "//build/config/mac:compiler" ]
}
}
# Linker on macOS does not support `color-diagnostics`
if (current_os != "mac") {
ldflags += [ "-Wl,--color-diagnostics" ]
}
if (crash_diagnostics_dir != "") {
cflags += [ "-fcrash-diagnostics-dir=" +
rebase_path(crash_diagnostics_dir, root_build_dir) ]
}
asmflags += cflags
asmflags += cflags_c
}
config("relative_paths") {
# Make builds independent of absolute file path. The file names
# embedded in debugging information will be expressed as relative to
# the build directory, e.g. "../.." for an "out/subdir" under //.
#
# This is consistent with the file names in __FILE__ expansions
# (e.g. in assertion messages), which the compiler doesn't provide a
# way to remap. That way source file names in logging and
# symbolization can all be treated the same way. This won't go well
# if $root_build_dir is not a subdirectory of //, but there isn't
# a better option to keep all source file name references uniformly
# relative to a single root. Stripping out per-user or per-config
# path information additionally allows caching compilers (like Goma)
# to reuse compilation results amongst users/configs.
#
# Given a build directory of of the form
# "/xxx/yyy/fuchsia/out/my-config-name", we want to normalize as
# follows:
#
# /xxx/yyy/fuchsia/out/my-config-name → .
# /xxx/yyy/fuchsia/out/my-config-name.zircon → ../my-config-name.zircon
# /xxx/yyy/fuchsia/out → ..
# /xxx/yyy/fuchsia/src → ../src
#
# GCC and Clang only perform naïve prefix matching, so we need to
# match replace multiple prefixes
# ("/xxx/yyy/fuchsia/out/my-config-name", "/xxx/yyy/fuchsia/out",
# "/xxx/yyy/fuchsia") to avoid excess path information leaking into
# the debug symbols.
if (use_goma) {
# TODO(TC-585): `-fdebug-prefix-map` is also used by Goma to canonicalize
# build commands, allowing it to reuse compilation results for users running
# out of different working directories. However, it only supports a single
# "-fdebug-prefix-map" prefix. Attempting to provide more than one causes
# canonicalization to fail, meaning that builds running out of different
# directories won't share cache results. For now, we just provide a single
# debug-prefix-map, even though more would be ideal.
# Map "/some/dir/fuchsia" to "../..".
cflags = [ "-fdebug-prefix-map=" + rebase_path("//") + "=" +
rebase_path("//", root_build_dir) ]
} else {
cflags = [
# Map "/some/dir/fuchsia/out/my-build.my-arch" to ".".
"-fdebug-prefix-map=" + rebase_path(root_build_dir) + "=.",
# Map "/some/dir/fuchsia/out" to "..".
"-fdebug-prefix-map=" + rebase_path("$root_build_dir/..") + "=..",
# Map "/some/dir/fuchsia" to "../..".
"-fdebug-prefix-map=" + rebase_path("//.") + "=" +
rebase_path("//.", root_build_dir),
]
}
cflags += [
# This makes sure that include directories in the toolchain are
# represented as relative to the build directory (because that's how
# we invoke the compiler), rather than absolute. This can affect
# __FILE__ expansions (e.g. assertions in system headers). We
# normally run a compiler that's someplace within the source tree
# (//prebuilt/...), so its absolute installation path will have a
# prefix matching absolute_path and hence be mapped to relative_path
# in the debugging information, so this should actually be
# superfluous for purposes of the debugging information.
"-no-canonical-prefixes",
]
}
config("debug") {
cflags = [ "-O0" ]
ldflags = cflags
}
config("release") {
defines = [ "NDEBUG=1" ]
cflags = [
"-O3",
"-fdata-sections",
"-ffunction-sections",
]
ldflags = cflags
if (current_os == "mac") {
ldflags += [ "-Wl,-dead_strip" ]
} else {
ldflags += [ "-Wl,--gc-sections" ]
}
}
config("exceptions") {
cflags_cc = [ "-fexceptions" ]
cflags_objcc = cflags_cc
}
config("no_exceptions") {
cflags_cc = [ "-fno-exceptions" ]
cflags_objcc = cflags_cc
}
config("rtti") {
cflags_cc = [ "-frtti" ]
cflags_objcc = cflags_cc
}
config("no_rtti") {
cflags_cc = [ "-fno-rtti" ]
cflags_objcc = cflags_cc
}
config("default_include_dirs") {
include_dirs = [
"//",
root_gen_dir,
]
}
config("minimal_symbols") {
cflags = [ "-gline-tables-only" ]
asmflags = cflags
ldflags = cflags
}
config("symbols") {
cflags = [ "-g3" ]
asmflags = cflags
ldflags = cflags
}
config("no_symbols") {
cflags = [ "-g0" ]
asmflags = cflags
ldflags = cflags
}
# Default symbols.
config("default_symbols") {
if (symbol_level == 0) {
configs = [ ":no_symbols" ]
} else if (symbol_level == 1) {
configs = [ ":minimal_symbols" ]
} else if (symbol_level == 2) {
configs = [ ":symbols" ]
} else {
assert(symbol_level >= 0 && symbol_level <= 2)
}
}
config("default_frame_pointers") {
if (enable_frame_pointers) {
configs = [ ":frame_pointers" ]
} else {
configs = [ ":no_frame_pointers" ]
}
}
config("frame_pointers") {
cflags = [ "-fno-omit-frame-pointer" ]
}
config("no_frame_pointers") {
cflags = [ "-fomit-frame-pointer" ]
}
config("default_warnings") {
cflags = [
"-Wall",
"-Wextra",
"-Wnewline-eof",
"-Wno-unused-parameter",
# TODO(TC-620): disable -Wimplicit-int-float-conversion which has been
# introduced in https://reviews.llvm.org/D64666 until our source is clean.
"-Wno-unknown-warning-option",
"-Wno-implicit-int-float-conversion",
# TODO(34837): disable -Wdangling until we clear all instances.
"-Wno-dangling",
]
}
config("symbol_visibility_hidden") {
# Disable libc++ visibility annotations to make sure that the compiler option
# has effect on symbols defined in libc++ headers. Note that we don't want to
# disable these annotations altogether to ensure that our toolchain is usable
# outside of our build since not every user uses hidden visibility by default.
defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
cflags = [ "-fvisibility=hidden" ]
}
config("symbol_no_undefined") {
if (current_os == "mac") {
ldflags = [ "-Wl,-undefined,error" ]
} else {
ldflags = [ "-Wl,--no-undefined" ]
}
}
config("shared_library_config") {
configs = []
cflags = []
if (current_os == "fuchsia") {
configs += [ "//build/config/fuchsia:shared_library_config" ]
} else if (current_os == "linux") {
cflags += [ "-fPIC" ]
} else if (current_os == "mac") {
configs += [ "//build/config/mac:mac_dynamic_flags" ]
}
}
config("executable_config") {
configs = []
if (current_os == "fuchsia") {
configs += [
"//build/config/fuchsia:executable_config",
"//build/config/fuchsia:fdio_config",
]
} else if (current_os == "mac") {
configs += [
"//build/config/mac:mac_dynamic_flags",
"//build/config/mac:mac_executable_flags",
]
}
}
config("default_libs") {
configs = []
if (current_os == "mac") {
configs += [ "//build/config/mac:default_libs" ]
}
}