blob: 4d8ff8ced086d7aea477bc251c4f063637658ea3 [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")
config("compiler") {
cflags = []
ldflags = [
# Use static C++ standard library.
"-static-libstdc++",
# Set rpath to find dynamically linked libraries placed next to executables
# in the host build directory.
"-Wl,-rpath=\$ORIGIN/",
]
configs = [
":sysroot",
":target",
":clang_defaults",
]
rustflags = [
"-Clinker=" + rebase_path("$clang_prefix/clang++", "", root_build_dir),
"-Cdefault-linker-libraries",
]
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
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.
cflags = [ "-fPIE" ]
# Since we're compiling as PIE, link as PIE too.
# This makes `#ifdef __PIE__` checks comport with link-time behavior.
ldflags += cflags + [ "-pie" ]
}
# TODO(fxbug.dev/26846) The implicitly linked static libc++.a depends on these.
libs = [
"dl",
"pthread",
]
asmflags = cflags
}
config("sysroot") {
cflags = [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
ldflags = cflags
asmflags = cflags
rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}
config("target") {
cflags = [ "--target=$clang_target" ]
asmflags = cflags
ldflags = cflags
rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}
# These flags are enabled by default in Fuchsia's Clang toolchain, but we set
# them explicitly to support other Clang toolchains and Clang-based tools.
config("clang_defaults") {
cflags_cc = [
# Use libc++ as the C++ standard library.
"-stdlib=libc++",
]
ldflags = [
# Use libc++ as the C++ standard library.
"-stdlib=libc++",
# Use unwinder provided by the C++ standard library.
"-unwindlib=",
# Use compiler-rt as the compiler runtime.
"-rtlib=compiler-rt",
# Use lld as the linker.
"-fuse-ld=lld",
# Generate build ID for all binaries.
"-Wl,--build-id",
]
rustflags = []
foreach(flag, ldflags) {
rustflags += [ "-Clink-arg=$flag" ]
}
}