| # 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/target_api_level.gni") |
| import("//build/config/sanitizers/sanitizer_default_options.gni") |
| import("//build/config/sysroot.gni") |
| import("//build/icu/third_party_icu_headers.gni") |
| import("//build/toolchain/ccache.gni") |
| import("//build/toolchain/rbe.gni") |
| import("//src/lib/icu/third_party_icu_headers.gni") |
| |
| if (support_rust) { |
| import("//build/rust/config.gni") |
| import("//zircon/public/sysroot/rust.gni") |
| } |
| |
| # 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 (board_configs != []) { |
| configs += board_configs |
| } else { |
| configs += [ "//build/config:cpu_baseline" ] |
| } |
| |
| if (use_ccache) { |
| configs += [ ":ccache" ] |
| } |
| |
| ldflags = [] |
| if (build_id_format != "") { |
| ldflags += [ "-Wl,--build-id=$build_id_format" ] |
| } |
| |
| if (support_rust) { |
| if (!is_debug) { |
| # https://fxbug.dev/42166874#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). |
| configs += [ "//build/config/rust:one_codegen_unit" ] |
| } |
| |
| # TODO(phosek): this is inefficient, rather this should come from a JSON file. |
| # Relative path makes command-lines remote-portable. |
| _clang_resource_dir = |
| rebase_path(exec_script("$clang_prefix/clang", |
| [ |
| "--target=$current_target_tuple", |
| "-print-resource-dir", |
| ], |
| "trim string", |
| []), |
| root_build_dir) |
| |
| # When linking C++ runtime libraries into Rust binaries, we should use |
| # the correct multilib variant. |
| # |
| # TODO(https://fxbug.dev/42177702): Rather then hardcoding the directory names here, |
| # these should ideally come from runtime.json. |
| _multilib_dir = "" |
| if (toolchain_variant.tags + [ "asan" ] - [ "asan" ] != |
| toolchain_variant.tags) { |
| _multilib_dir = "/asan+noexcept" |
| } else if (toolchain_variant.tags + [ "hwasan" ] - [ "hwasan" ] != |
| toolchain_variant.tags) { |
| _multilib_dir = "/hwasan+noexcept" |
| } else { |
| _multilib_dir = "/noexcept" |
| } |
| |
| # Which libc++ to link: |
| _libcxx_dir = |
| "${rebased_clang_prefix}/../lib/${current_target_tuple}${_multilib_dir}" |
| |
| 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${_libcxx_dir}", |
| "-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", |
| ] |
| |
| if (rust_rbe_enable) { |
| rustflags += [ "--remote-flag=--cxx-stdlibdir=${_libcxx_dir}" ] |
| } |
| |
| # TODO(https://fxbug.dev/42130451): Eventually the default in the compler driver. |
| rustflags += [ "-Clink-arg=-zrel" ] |
| } |
| } |
| |
| config("compiler_sysroot") { |
| if (defined(sysroot) && 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") { |
| if (is_gcc || !is_fuchsia) { |
| defines = [ "__Fuchsia_API_level__=${clang_fuchsia_api_level}" ] |
| } else { |
| cflags = [ "-ffuchsia-api-level=${clang_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 = [ |
| # Use libc++ as the C++ standard library. |
| "-stdlib=libc++", |
| |
| # Use libunwind as the unwinder. |
| "-unwindlib=libunwind", |
| |
| # Request static linking for standard C++ library. Despite the name, this |
| # option applies to both libstdc++ and libc++, whichever is used by Clang. |
| "-static-libstdc++", |
| |
| # Request static linking for unwinder. Despite the name, this option |
| # applies to both libgcc and libunwind, whichever is used by Clang. |
| "-static-libgcc", |
| ] |
| |
| # -static-libstdc++ and -static-libgcc options are handled by the C++ |
| # compiler driver (that is clang), whereas these link-args get passed |
| # straight to lld by rustc and need to be expanded manually. |
| rustflags = [ "-Clink-args=--push-state -Bstatic -lc++ -Bdynamic -lm --pop-state -l:libunwind.a" ] |
| } |
| |
| config("dynamic_rust_standard_library") { |
| rustflags = [ "-Cprefer-dynamic" ] |
| } |
| |
| config("static_rust_standard_library") { |
| rustflags = [ "-Cprefer-dynamic=no" ] |
| } |
| |
| # 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) { |
| # TODO(https://fxbug.dev/42135607): Get this information from runtime.json instead. |
| _clang_libunwind = exec_script("$clang_prefix/clang++", |
| [ |
| "--target=$current_target_tuple", |
| "-print-file-name=libunwind.so", |
| ], |
| "trim string", |
| []) |
| |
| 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") { |
| } |
| |
| # TODO(https://fxbug.dev/42180987): This works around a toolchain issue in LTO builds |
| # where code generation results in a dependency on a Zircon vDSO call but |
| # doesn't link -lzircon to supply it at link time. This is added to deps of |
| # the few targets where this has caused link failures to just explicitly link |
| # it in. As soon as the toolchain issues are resolved, this and the deps on it |
| # will all be removed. |
| group("uses-outline-atomics-fxbug98632") { |
| visibility = [ |
| "${icu_root}:*", |
| "//src/developer/debug/debug_agent/test_data:*", |
| "//src/developer/debug/e2e_tests/inferiors:*", |
| "//src/graphics/examples/vkproto:*", |
| "//src/graphics/examples/vkproto/cmd-buf-benchmark:*", |
| "//third_party/ffmpeg:*", |
| "//third_party/icu/default:*", |
| "//third_party/icu/latest:*", |
| "//third_party/icu/stable:*", |
| ] |
| if (current_cpu == "arm64" && is_fuchsia) { |
| deps = [ "//src/zircon/lib/zircon" ] |
| } |
| } |