blob: 7f9432a8b70f03e66b92ce352167a40cc98602c1 [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/sysroot.gni")
import("//build/toolchain/ccache.gni")
assert(current_os == "fuchsia")
config("werror") {
cflags = [
"-Werror",
# Declarations marked as deprecated should cause build failures, rather
# they should emit warnings to notify developers about the use of
# deprecated interfaces.
"-Wno-error=deprecated-declarations",
# Do not add additional -Wno-error to this config.
]
}
config("icf") {
# This changes C/C++ semantics and might be incompatible with third-party
# code that relies on function pointers comparison.
ldflags = [ "-Wl,--icf=all" ]
}
config("safestack") {
# This may cause issues in code that makes assumptions about stack layout
# such as garbage collectors.
cflags = [
"-fsanitize=safe-stack",
"-fstack-protector-strong",
]
asmflags = cflags
ldflags = cflags
}
# ccache, at least in some configurations, caches preprocessed content. This
# means that by the time the compiler sees it, macros are unrolled. A number
# of gcc and clang diagnostics are conditioned on whether the source is part
# of a macro or not. This is because a "reasonable" looking macro invocation
# may end up doing something silly internally. This can mean self assignment
# and tautological comparisons, since macros are not typed. Macros also tend
# to over-parenthesize, and so on. This particular list of options was found
# via trial and error, and might be the best way of keeping the build quiet.
config("ccache") {
cflags = [
"-Wno-error",
"-Qunused-arguments",
"-Wno-parentheses-equality",
"-Wno-self-assign",
"-Wno-tautological-compare",
"-Wno-unused-command-line-argument",
]
asmflags = cflags
}
config("compiler") {
cflags = []
cflags_c = [ "-std=c11" ]
cflags_cc = [ "-std=c++14" ]
ldflags = [ "-Wl,--threads" ]
configs = [
":compiler_sysroot",
":compiler_target",
":icf",
":safestack",
":thread_safety_annotations",
":toolchain_version_stamp",
":werror",
]
if (use_ccache) {
configs += [ ":ccache" ]
configs -= [ ":werror" ]
}
asmflags = cflags + cflags_c
}
config("toolchain_version_stamp") {
# We want to force a recompile and relink of the world whenever our toolchain changes since
# artifacts from an older version of the toolchain may or may not be compatible with newer ones.
# To achieve this, we insert a synthetic define into the compile line.
if (host_os == "linux") {
toolchain_stamp_file = "//buildtools/linux64/toolchain.stamp"
} else if (host_os == "mac") {
toolchain_stamp_file = "//buildtools/mac/toolchain.stamp"
} else {
assert(false, "Unsupported host OS")
}
toolchain_version = read_file(toolchain_stamp_file, "trim string")
defines = [ "TOOLCHAIN_VERSION=$toolchain_version" ]
}
config("compiler_sysroot") {
# The sole purpose of SYSROOT_VERSION is to change the command line on every
# sysroot update so as to force rebuilds.
defines = [ "SYSROOT_VERSION=$sysroot_version" ]
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
ldflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
asmflags = cflags
}
config("compiler_target") {
cflags = []
ldflags = []
if (current_cpu == "arm64") {
cflags += [ "--target=aarch64-fuchsia" ]
ldflags += [ "--target=aarch64-fuchsia" ]
} else if (current_cpu == "x64") {
cflags += [ "--target=x86_64-fuchsia" ]
ldflags += [ "--target=x86_64-fuchsia" ]
} else {
assert(false, "Unsupported architecture")
}
asmflags = cflags
}
config("shared_library_config") {
cflags = [ "-fPIC" ]
}
config("mxio_config") {
libs = [ "mxio" ]
}
config("executable_config") {
}
config("thread_safety_annotations") {
cflags_cc = [ "-Wthread-safety" ]
defines = [ "_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" ]
}