blob: 8ea309cc75cd60a901ef2645ac48358e4cc3ce3a [file] [log] [blame]
# Copyright 2017 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/clang/clang.gni")
import("//build/config/sysroot.gni")
import("//build/rust/config.gni")
config("compiler") {
cflags = []
cflags_c = []
cflags_cc = []
ldflags = [
"-static-libstdc++",
# Generate build ID for all binaries so we can use the .build-id directory
# scheme for debugging information. This flag is enabled by default for our
# toolchain and many native host toolchains, but we set it explicitly to
# support arbitrary host toolchains.
"-Wl,--build-id",
# Set rpath to find dynamically linked libraries placed next to executables
# in the host build directory.
"-Wl,-rpath=\$ORIGIN/",
]
if (host_os == "mac") {
# TODO(TC-325): When building binaries for Linux on macOS, we need to use
# lld as a linker, hence this flag. This is not needed on Linux since our
# Clang is configured to use lld as a default linker, but we cannot use the
# same option on macOS since default linker is currently a per-toolchain,
# not a per-target option and on macOS, Clang should default to ld64. We
# should change Clang to make the default linker a per-target option.
ldflags += [ "-fuse-ld=lld" ]
}
configs = [
":sysroot",
":target",
]
rustflags = [
"-Clinker=" + rebase_path("$clang_prefix/clang++", "", root_build_dir),
"-Clink-arg=--target=$clang_target",
"-Clink-arg=--sysroot=" + rebase_path(sysroot, root_build_dir),
"-Cdefault-linker-libraries",
]
if (!toolchain_variant.is_pic_default) {
# Rust links are always PIE on Linux. C/C++ static library code that is
# linked into Rust programs must be compiled as PIE too. Since there's no
# good way to distinguish code going into Rust links from other code, just
# do it for everything. Note this doesn't cause linking as PIE, just code
# generation that's compatible. Non-PIE links of Linux binaries will apply
# the relocations statically and just pay a little runtime overhead.
cflags = [ "-fPIE" ]
}
# TODO(TC-74) The implicitly linked static libc++.a depends on these.
libs = [
"dl",
"pthread",
]
asmflags = cflags + cflags_c
}
config("sysroot") {
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
ldflags = cflags
asmflags = cflags
}
config("target") {
cflags = [ "--target=$clang_target" ]
asmflags = cflags
ldflags = cflags
}