| # 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/build_id.gni") |
| import("//build/config/clang/clang.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("//zircon/public/sysroot/rust.gni") |
| |
| assert(current_os == "fuchsia") |
| |
| # 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") { |
| cflags = [] |
| cflags_c = [] |
| cflags_cc = [] |
| ldflags = [] |
| configs = [ |
| ":compiler_sysroot", |
| ":compiler_target", |
| ":compiler_cpu", |
| ] |
| if (use_ccache) { |
| configs += [ ":ccache" ] |
| } |
| asmflags = cflags + cflags_c |
| |
| rustflags = [ |
| "-L", |
| rebase_path(rust_sysroot_dir, root_build_dir) + "/lib", |
| "-Clinker=" + rebase_path("$clang_prefix/lld", "", root_build_dir), |
| "-Clink-arg=--sysroot=" + rebase_path(rust_sysroot_dir, root_build_dir), |
| "-Clink-arg=-L" + clang_resource_dir + "/" + rust_target + "/lib", |
| "-Clink-arg=--pack-dyn-relocs=relr", |
| "-Clink-arg=-dynamic-linker=ld.so.1", |
| "-Clink-arg=--icf=all", |
| ] |
| |
| 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=$clang_target" ] |
| asmflags = cflags |
| ldflags = cflags |
| } |
| |
| config("compiler_cpu") { |
| cflags = [] |
| if (current_cpu == "x64") { |
| cflags += [ |
| "-march=x86-64", |
| "-mcx16", |
| ] |
| } |
| ldflags = cflags |
| asmflags = cflags |
| |
| if (current_cpu == "arm64") { |
| ldflags += [ "-Wl,--fix-cortex-a53-843419" ] |
| } |
| } |
| |
| config("shared_library_config") { |
| cflags = [ "-fPIC" ] |
| } |
| |
| # NOTE: Even though this config has been moved to //build/config:BUILD.gn, it |
| # is still referenced by third_party/{ICU,Vulkan-ValidationLayers}. This forces |
| # BUILDCONFIG.gn to still reference the //build/config/fuchsia version to avoid |
| # breaking their BUILD.gn files, and hence this definition below. |
| # |
| # TODO(fxbug.dev/54322): Remove this after build unification completes. |
| config("thread_safety_annotations") { |
| configs = [ "//build/config:thread_safety_annotations" ] |
| } |
| |
| 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("auto_var_init") { |
| # Automatically initialize variables with a pattern. |
| cflags = [ "-ftrivial-auto-var-init=pattern" ] |
| } |
| |
| 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++" ] |
| } |
| |
| 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", |
| ] |
| } |
| |
| 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", |
| "-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") { |
| } |