blob: 7be6d1d91d41c10e20f0ce9e5ffa5056e7496597 [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/board.gni")
import("//build/config/build_id.gni")
import("//build/config/clang/clang.gni")
import("//build/config/current_target_tuple.gni")
import("//build/config/fuchsia/platform_version.gni")
import("//build/config/sanitizers/sanitizer_default_options.gni")
import("//build/config/sysroot.gni")
import("//build/rust/config.gni")
import("//build/toolchain/ccache.gni")
import("//build/toolchain/rbe.gni")
import("//zircon/public/sysroot/rust.gni")
# Deprecated.
# TODO(fxbug.dev/44795): Remove once none of the petals depend on this.
config("werror") {
configs = [ "//build/config:werror" ]
}
# 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") {
configs = [
":compiler_sysroot",
":compiler_target",
":compiler_fuchsia_api_level",
]
if (!is_debug || rust_rbe_enable) {
# fxbug.dev/85921#c15: forcing one codegen unit produces
# smaller binaries but makes builds slower.
# Enforce one codegen unit only when we really care about
# size (release builds), or when RBE is enabled (and then
# the benefits of parallelized codegen are diminished).
configs += [ "//build/config/rust:one_codegen_unit" ]
}
if (board_configs != []) {
configs += board_configs
} else {
configs += [ "//build/config:cpu_baseline" ]
}
if (use_ccache) {
configs += [ ":ccache" ]
}
ldflags = []
rustflags = [
"-L",
rebase_path(rust_sysroot_dir, root_build_dir) + "/lib",
"-Clinker=$rebased_clang_prefix/lld",
"-Clink-arg=--sysroot=" + rebase_path(rust_sysroot_dir, root_build_dir),
# These could alternatively come from clang's '--print-search-dirs', but that would require an
# exec_script and post-processing of the output or a JSON file generated during the toolchain
# build.
"-Clink-arg=-L" + rebased_clang_prefix + "/../lib/" + current_target_tuple,
"-Clink-arg=-L" + clang_resource_dir + "/lib/" + current_target_tuple,
"-Clink-arg=--pack-dyn-relocs=relr",
"-Clink-arg=-dynamic-linker=ld.so.1",
"-Clink-arg=--icf=all",
]
# TODO(fxbug.dev/53078): Eventually the default in the compler driver.
rustflags += [ "-Clink-arg=-zrel" ]
if (build_id_format != "") {
ldflags += [ "-Wl,--build-id=$build_id_format" ]
}
}
config("compiler_sysroot") {
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
asmflags = cflags
ldflags = cflags
}
config("compiler_target") {
cflags = [ "--target=$current_target_tuple" ]
asmflags = cflags
ldflags = cflags
}
config("compiler_fuchsia_api_level") {
cflags = [ "-ffuchsia-api-level=$current_fuchsia_api_level" ]
asmflags = cflags
ldflags = cflags
}
config("shared_library_config") {
cflags = [ "-fPIC" ]
# Ensure assembly code can use `#ifdef __PIC__`
asmflags = cflags
ldflags = cflags
}
config("fdio_config") {
# This config is only a marker that is used to signal that a given executable
# should link with fdio. With fdio now getting built in this very build, there
# need to be a proper dependency.
# See the override of the `executable` template in
# //build/config/BUILDCONFIG.gni where that build edge is added.
}
config("executable_config") {
}
config("enable_zircon_asserts") {
defines = [ "ZX_ASSERT_LEVEL=2" ]
}
declare_args() {
zircon_asserts = is_debug
}
config("zircon_asserts") {
if (zircon_asserts) {
configs = [ ":enable_zircon_asserts" ]
}
}
config("no_cpp_standard_library") {
ldflags = [ "-nostdlib++" ]
}
config("static_cpp_standard_library") {
ldflags = [ "-static-libstdc++" ]
# -static-libstdc++ is only supported by the compiler drivers (clang/clang++), whereas these
# link-args get passed straight to lld by rustc
rustflags =
[ "-Clink-args=--push-state -Bstatic -lc++ -Bdynamic -lm --pop-state" ]
}
config("dynamic_rust_standard_library") {
# -Cprefer-dynamic is incompatible with (Thin)LTO.
if (toolchain_variant.tags + [ "lto" ] - [ "lto" ] ==
toolchain_variant.tags) {
rustflags = [ "-Cprefer-dynamic" ]
}
}
# Configure a larger (2MB) stack size for Rust binaries.
#
# Currently, threads created by Rust's libstd have a hardcoded default stack
# size of 2MB on Fuchsia. This can create overflows when moving code to the
# main thread, whose default stack size is 256kB. To remove this wrinkle, the
# default stack size is changed to 2MB for Rust binaries.
config("large_rust_stack") {
rustflags = [ "-Clink-args=-zstack-size=0x200000" ]
}
# Enable additional integer-math sanitizers
config("integer-paranoia") {
cflags = [
"-fsanitize=integer-divide-by-zero,signed-integer-overflow",
"-fsanitize-undefined-trap-on-error",
]
}
# clang_libunwind is only available on fuchsia.
# See the definition in //build/config/clang/clang.gni.
if (is_fuchsia) {
config("libunwind") {
libs = [ clang_libunwind ]
}
}
# NOTE: This config's label is hard-coded in //build/config/BUILDCONFIG.gn
# so don't rename it without updating that file too!
config("static-pie-config") {
cflags = [
"-fno-sanitize=all",
"-fno-stack-protector",
]
ldflags = [
"-nostdlib",
"-nostartfiles",
"-Wl,-no-dynamic-linker",
]
}
group("maybe_scudo_default_options") {
if (scudo_default_options != "" && scudo_default_options != []) {
public_deps = [ ":scudo_default_options" ]
}
}
sanitizer_default_options("scudo_default_options") {
}