2018-11-17 03:21:53 +01:00
|
|
|
import("//llvm/utils/gn/build/buildflags.gni")
|
|
|
|
import("//llvm/utils/gn/build/mac_sdk.gni")
|
2021-02-17 20:47:02 +01:00
|
|
|
import("//llvm/utils/gn/build/sysroot.gni")
|
2018-11-17 03:21:53 +01:00
|
|
|
import("//llvm/utils/gn/build/toolchain/compiler.gni")
|
2019-01-15 22:24:00 +01:00
|
|
|
import("//llvm/utils/gn/build/toolchain/target_flags.gni")
|
2018-11-17 03:21:53 +01:00
|
|
|
|
2019-05-29 22:00:36 +02:00
|
|
|
declare_args() {
|
|
|
|
# Whether to build everything with coverage information.
|
|
|
|
# After building with this, run tests and then run
|
|
|
|
# llvm/utils/prepare-code-coverage-artifact.py \
|
|
|
|
# .../llvm-profdata .../llvm-cov out/gn/profiles/ report/ \
|
|
|
|
# out/gn/bin/llvm-undname ...`
|
|
|
|
# to generate a HTML report for the binaries passed in the last line.
|
|
|
|
llvm_build_instrumented_coverage = false
|
2020-02-15 03:55:33 +01:00
|
|
|
|
|
|
|
# If set, puts relative paths in debug info.
|
|
|
|
# Makes the build output independent of the build directory, but makes
|
|
|
|
# most debuggers harder to use. See "Getting to local determinism" and
|
|
|
|
# "Getting debuggers to work well with locally deterministic builds" in
|
|
|
|
# http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
|
|
|
|
# for more information.
|
|
|
|
use_relative_paths_in_debug_info = false
|
2020-06-04 14:10:16 +02:00
|
|
|
|
|
|
|
# The version of host gcc. Ignored if is_clang is true.
|
|
|
|
gcc_version = 9
|
2019-05-29 22:00:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(!llvm_build_instrumented_coverage || is_clang,
|
|
|
|
"llvm_build_instrumented_coverage requires clang as host compiler")
|
|
|
|
|
2018-11-17 03:21:53 +01:00
|
|
|
config("compiler_defaults") {
|
2018-12-13 00:57:21 +01:00
|
|
|
defines = []
|
|
|
|
|
2018-11-17 03:21:53 +01:00
|
|
|
if (!llvm_enable_assertions) {
|
|
|
|
defines += [ "NDEBUG" ]
|
|
|
|
}
|
|
|
|
|
2020-08-15 02:09:23 +02:00
|
|
|
if (llvm_enable_expensive_checks) {
|
|
|
|
defines += [ "EXPENSIVE_CHECKS" ]
|
|
|
|
}
|
|
|
|
|
2019-02-21 21:35:31 +01:00
|
|
|
asmflags = target_flags
|
2019-02-05 06:10:19 +01:00
|
|
|
cflags = target_flags
|
2019-01-15 22:24:00 +01:00
|
|
|
ldflags = target_flags + target_ldflags
|
2018-11-17 03:21:53 +01:00
|
|
|
|
2020-10-12 21:20:58 +02:00
|
|
|
# Mostly for compiler-rt, see compiler-rt/cmake/config-ix.cmake
|
|
|
|
if (current_os == "ios") {
|
|
|
|
asmflags += [ "-miphoneos-version-min=8.0" ]
|
|
|
|
cflags += [ "-miphoneos-version-min=8.0" ]
|
|
|
|
ldflags += [ "-miphoneos-version-min=8.0" ]
|
|
|
|
}
|
|
|
|
if (current_os == "mac") {
|
|
|
|
asmflags += [ "-mmacosx-version-min=10.10" ]
|
|
|
|
cflags += [ "-mmacosx-version-min=10.10" ]
|
|
|
|
ldflags += [ "-mmacosx-version-min=10.10" ]
|
|
|
|
}
|
|
|
|
|
2020-12-09 20:51:00 +01:00
|
|
|
assert(symbol_level == 0 || symbol_level == 1 || symbol_level == 2,
|
|
|
|
"Unexpected symbol_level")
|
2018-11-17 03:21:53 +01:00
|
|
|
if (host_os != "win") {
|
2020-12-09 20:51:00 +01:00
|
|
|
if (symbol_level == 2) {
|
2018-11-17 03:21:53 +01:00
|
|
|
cflags += [ "-g" ]
|
2020-12-08 15:35:58 +01:00
|
|
|
|
|
|
|
# For full debug-info -g builds, --gdb-index makes links ~15% slower, and
|
|
|
|
# gdb symbol reading time 1500% faster (lld links in 4.4 instead of 3.9s,
|
|
|
|
# and gdb loads and runs it in 2s instead of in 30s). It's likely that
|
|
|
|
# people doing symbol_level=2 want to run a debugger (since
|
|
|
|
# symbol_level=2 isn't the default). So this seems like the right
|
|
|
|
# tradeoff.
|
|
|
|
if (host_os != "mac" && use_lld) {
|
|
|
|
cflags += [ "-ggnu-pubnames" ] # PR34820
|
|
|
|
ldflags += [ "-Wl,--gdb-index" ]
|
|
|
|
}
|
2020-12-09 20:51:00 +01:00
|
|
|
} else if (symbol_level == 1) {
|
|
|
|
cflags += [ "-g1" ]
|
2020-12-08 15:35:58 +01:00
|
|
|
# For linetable-only -g1 builds, --gdb-index makes links ~8% slower, but
|
|
|
|
# links are 4x faster than -g builds so it's a fairly small absolute cost.
|
|
|
|
# On the other hand, gdb startup is well below 1s with and without the
|
|
|
|
# index, and people using -g1 likely don't use a debugger. So don't use
|
|
|
|
# the flag here.
|
2019-02-12 23:24:45 +01:00
|
|
|
}
|
|
|
|
if (is_optimized) {
|
2018-11-17 03:21:53 +01:00
|
|
|
cflags += [ "-O3" ]
|
|
|
|
}
|
|
|
|
cflags += [ "-fdiagnostics-color" ]
|
2019-08-26 21:22:41 +02:00
|
|
|
if (use_lld) {
|
|
|
|
ldflags += [ "-Wl,--color-diagnostics" ]
|
|
|
|
}
|
2018-11-17 03:21:53 +01:00
|
|
|
cflags_cc = [
|
2019-08-14 14:38:43 +02:00
|
|
|
"-std=c++14",
|
2018-11-17 03:21:53 +01:00
|
|
|
"-fvisibility-inlines-hidden",
|
|
|
|
]
|
|
|
|
} else {
|
2020-12-09 20:51:00 +01:00
|
|
|
if (symbol_level != 0) {
|
2019-02-04 22:13:43 +01:00
|
|
|
cflags += [
|
|
|
|
"/Zi",
|
|
|
|
"/FS",
|
|
|
|
]
|
2020-12-09 20:51:00 +01:00
|
|
|
if (symbol_level == 1 && is_clang) {
|
|
|
|
cflags += [ "-gline-tables-only" ]
|
|
|
|
}
|
2020-01-22 18:54:19 +01:00
|
|
|
ldflags += [ "/DEBUG" ]
|
2020-03-06 23:41:48 +01:00
|
|
|
|
|
|
|
# Speed up links with ghash on windows.
|
|
|
|
if (use_lld && is_clang) {
|
|
|
|
cflags += [ "-gcodeview-ghash" ]
|
|
|
|
ldflags += [ "/DEBUG:GHASH" ]
|
|
|
|
}
|
2019-02-12 23:24:45 +01:00
|
|
|
}
|
|
|
|
if (is_optimized) {
|
2018-11-17 03:21:53 +01:00
|
|
|
cflags += [
|
|
|
|
"/O2",
|
[windows] Add /Gw to compiler flags
This is like -fdata-sections, and it's not part of /O2 by default for some reason.
In the cmake build, reduces the size of clang.exe from 70,358,016 bytes to 69,982,720 bytes.
clang-format.exe goes from 3,703,296 bytes to 3,331,072 bytes.
Differential Revision: https://reviews.llvm.org/D74573
2020-02-14 21:15:00 +01:00
|
|
|
"/Gw",
|
2018-11-17 03:21:53 +01:00
|
|
|
"/Zc:inline",
|
|
|
|
]
|
2019-02-12 23:24:45 +01:00
|
|
|
ldflags += [
|
|
|
|
"/OPT:REF",
|
|
|
|
"/OPT:ICF",
|
|
|
|
]
|
2018-11-17 03:21:53 +01:00
|
|
|
}
|
|
|
|
defines += [
|
|
|
|
"_CRT_SECURE_NO_DEPRECATE",
|
|
|
|
"_CRT_SECURE_NO_WARNINGS",
|
|
|
|
"_CRT_NONSTDC_NO_DEPRECATE",
|
|
|
|
"_CRT_NONSTDC_NO_WARNINGS",
|
|
|
|
"_SCL_SECURE_NO_DEPRECATE",
|
|
|
|
"_SCL_SECURE_NO_WARNINGS",
|
|
|
|
|
|
|
|
"_HAS_EXCEPTIONS=0",
|
|
|
|
"_UNICODE",
|
|
|
|
"UNICODE",
|
|
|
|
]
|
2019-01-15 03:43:33 +01:00
|
|
|
cflags += [ "/EHs-c-" ]
|
2018-11-17 03:21:53 +01:00
|
|
|
|
|
|
|
# The MSVC default value (1 MB) is not enough for parsing recursive C++
|
|
|
|
# templates in Clang.
|
2019-02-04 22:13:43 +01:00
|
|
|
ldflags += [ "/STACK:10000000" ]
|
2018-11-17 03:21:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Warning setup.
|
|
|
|
if (host_os == "win" && !is_clang) {
|
|
|
|
cflags += [
|
|
|
|
# Suppress ''modifier' : used more than once' (__forceinline and inline).
|
|
|
|
"-wd4141",
|
|
|
|
|
|
|
|
# Suppress 'conversion from 'type1' to 'type2', possible loss of data'.
|
|
|
|
"-wd4244",
|
|
|
|
|
|
|
|
# Suppress 'conversion from 'size_t' to 'type', possible loss of data'.
|
|
|
|
"-wd4267",
|
|
|
|
|
|
|
|
# Suppress 'no matching operator delete found'.
|
|
|
|
"-wd4291",
|
|
|
|
|
|
|
|
# Suppress 'noexcept used with no exception handling mode specified'.
|
|
|
|
"-wd4577",
|
|
|
|
|
|
|
|
# Suppress 'destructor was implicitly defined as deleted'.
|
|
|
|
"-wd4624",
|
|
|
|
|
|
|
|
# Suppress 'unsafe mix of type <type> and type <type> in operation'.
|
|
|
|
"-wd4805",
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
if (host_os == "win") {
|
|
|
|
cflags += [ "/W4" ]
|
|
|
|
} else {
|
|
|
|
cflags += [
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
]
|
|
|
|
}
|
2019-01-25 01:29:17 +01:00
|
|
|
cflags += [ "-Wno-unused-parameter" ]
|
2018-11-17 03:21:53 +01:00
|
|
|
if (is_clang) {
|
2019-01-25 01:29:17 +01:00
|
|
|
cflags += [
|
|
|
|
"-Wdelete-non-virtual-dtor",
|
|
|
|
"-Wstring-conversion",
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
cflags += [
|
|
|
|
# GCC's -Wcomment complains about // comments ending with '\' if the
|
|
|
|
# next line is also a // comment.
|
|
|
|
"-Wno-comment",
|
|
|
|
|
|
|
|
# Disable gcc's potentially uninitialized use analysis as it presents
|
|
|
|
# lots of false positives.
|
|
|
|
"-Wno-maybe-uninitialized",
|
|
|
|
]
|
|
|
|
cflags_cc += [
|
|
|
|
# The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not
|
|
|
|
# useful.
|
|
|
|
"-Wno-noexcept-type",
|
|
|
|
]
|
2020-06-04 14:10:16 +02:00
|
|
|
if (gcc_version >= 8) {
|
|
|
|
cflags_cc += [
|
|
|
|
# Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires
|
|
|
|
# on LLVM's ADT classes.
|
|
|
|
"-Wno-class-memaccess",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
if (gcc_version >= 9) {
|
|
|
|
cflags_cc += [
|
|
|
|
# Disable -Wredundant-move on GCC>=9. GCC wants to remove std::move
|
|
|
|
# in code like "A foo(ConvertibleToA a) { return std::move(a); }",
|
|
|
|
# but this code does not compile (or uses the copy constructor
|
|
|
|
# instead) on clang<=3.8. Clang also has a -Wredundant-move, but it
|
|
|
|
# only fires when the types match exactly, so we can keep it here.
|
|
|
|
"-Wno-redundant-move",
|
|
|
|
]
|
|
|
|
}
|
2018-11-17 03:21:53 +01:00
|
|
|
}
|
|
|
|
if (is_clang && use_goma) {
|
|
|
|
# goma converts all paths to lowercase on the server, breaking this
|
|
|
|
# warning.
|
|
|
|
cflags += [ "-Wno-nonportable-include-path" ]
|
|
|
|
}
|
|
|
|
}
|
2019-01-15 22:24:00 +01:00
|
|
|
|
2019-01-28 20:32:52 +01:00
|
|
|
# On Windows, the linker is not invoked through the compiler driver.
|
|
|
|
if (use_lld && host_os != "win") {
|
2021-03-01 18:30:10 +01:00
|
|
|
ldflags += [ "-fuse-ld=lld" ]
|
2019-01-15 22:24:00 +01:00
|
|
|
}
|
2019-05-29 22:00:36 +02:00
|
|
|
|
|
|
|
if (llvm_build_instrumented_coverage) {
|
|
|
|
cflags += [
|
|
|
|
"-fcoverage-mapping",
|
|
|
|
|
|
|
|
# Using an absolute path here is lame, but it's used at test execution
|
|
|
|
# time to generate the profiles, and lit doesn't specify a fixed folder
|
|
|
|
# for test execution -- so this is the only way to get all profiles into
|
|
|
|
# a single folder like llvm/utils/prepare-code-coverage-artifact.py
|
|
|
|
# expects.
|
|
|
|
"-fprofile-instr-generate=" +
|
|
|
|
rebase_path("$root_build_dir/profiles/%4m.profraw"),
|
|
|
|
]
|
2021-05-14 01:03:01 +02:00
|
|
|
if (host_os != "win") {
|
|
|
|
ldflags += [ "-fprofile-instr-generate" ]
|
|
|
|
}
|
2019-05-29 22:00:36 +02:00
|
|
|
}
|
2020-02-15 03:55:33 +01:00
|
|
|
|
|
|
|
# Deterministic build setup, see
|
|
|
|
# http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
|
|
|
|
if (current_os == "win") {
|
|
|
|
ldflags += [ "/pdbaltpath:%_PDB%" ]
|
|
|
|
}
|
|
|
|
if (is_clang) {
|
|
|
|
cflags += [
|
|
|
|
"-no-canonical-prefixes",
|
|
|
|
"-Werror=date-time",
|
|
|
|
]
|
|
|
|
if (current_os == "win") {
|
2020-02-15 12:25:21 +01:00
|
|
|
cflags += [ "-fmsc-version=1916" ]
|
|
|
|
if (use_lld) {
|
|
|
|
cflags += [ "/Brepro" ]
|
|
|
|
ldflags += [ "/Brepro" ]
|
|
|
|
}
|
2020-02-15 03:55:33 +01:00
|
|
|
}
|
|
|
|
if (use_relative_paths_in_debug_info) {
|
|
|
|
cflags += [
|
|
|
|
"-fdebug-compilation-dir",
|
|
|
|
".",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 16:03:02 +01:00
|
|
|
if (sysroot != "") {
|
2021-02-17 19:48:10 +01:00
|
|
|
if (current_os == "win") {
|
|
|
|
assert(is_clang, "sysroot only works with clang-cl as host compiler")
|
|
|
|
cflags += [ "/winsysroot" + rebase_path(sysroot, root_build_dir) ]
|
2021-02-18 15:30:47 +01:00
|
|
|
} else if (current_os != "ios" && current_os != "mac") {
|
2021-02-17 19:48:10 +01:00
|
|
|
cflags += [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
|
|
|
|
}
|
2021-02-17 16:03:02 +01:00
|
|
|
}
|
2021-02-18 15:30:47 +01:00
|
|
|
if ((current_os == "ios" || current_os == "mac") &&
|
|
|
|
(clang_base_path != "" || sysroot != "")) {
|
|
|
|
if (current_os == "ios" && current_cpu == "arm64") {
|
|
|
|
sdk_path = ios_sdk_path
|
|
|
|
} else if (current_os == "ios" && current_cpu == "x64") {
|
|
|
|
sdk_path = iossim_sdk_path
|
|
|
|
} else if (current_os == "mac") {
|
|
|
|
sdk_path = mac_sdk_path
|
|
|
|
}
|
|
|
|
cflags += [
|
|
|
|
"-isysroot",
|
2021-02-18 20:40:14 +01:00
|
|
|
rebase_path(sdk_path, root_build_dir),
|
2021-02-18 15:30:47 +01:00
|
|
|
]
|
|
|
|
ldflags += [
|
|
|
|
"-isysroot",
|
2021-02-18 20:40:14 +01:00
|
|
|
rebase_path(sdk_path, root_build_dir),
|
2021-02-18 15:30:47 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
if (sysroot != "" && current_os != "win" && is_clang) {
|
|
|
|
cflags += [ "-Wpoison-system-directories" ]
|
|
|
|
}
|
2021-02-19 00:30:13 +01:00
|
|
|
assert(
|
|
|
|
!use_goma || sysroot != "",
|
|
|
|
"goma needs a sysroot: run `llvm/utils/sysroot.py make-fake --out-dir=sysroot` and add `sysroot = \"//sysroot\"` to your args.gn")
|
2020-09-22 01:28:21 +02:00
|
|
|
|
|
|
|
if (use_ubsan) {
|
|
|
|
assert(is_clang && current_os == "linux",
|
|
|
|
"ubsan only supported on Linux/Clang")
|
2021-05-28 05:00:20 +02:00
|
|
|
cflags += [ "-fsanitize=undefined", "-fno-sanitize-recover=all" ]
|
2020-09-22 01:28:21 +02:00
|
|
|
ldflags += [ "-fsanitize=undefined" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_asan) {
|
|
|
|
assert(is_clang && current_os == "linux",
|
|
|
|
"asan only supported on Linux/Clang")
|
|
|
|
cflags += [ "-fsanitize=address" ]
|
|
|
|
ldflags += [ "-fsanitize=address" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_tsan) {
|
|
|
|
assert(is_clang && current_os == "linux",
|
|
|
|
"tsan only supported on Linux/Clang")
|
|
|
|
cflags += [ "-fsanitize=thread" ]
|
|
|
|
ldflags += [ "-fsanitize=thread" ]
|
|
|
|
}
|
2020-09-30 01:06:32 +02:00
|
|
|
|
|
|
|
if (use_thinlto) {
|
|
|
|
assert(is_clang, "ThinLTO only supported on Clang")
|
|
|
|
|
|
|
|
lto_opt_level = 2
|
|
|
|
|
|
|
|
cflags += [ "-flto=thin" ]
|
|
|
|
|
|
|
|
if (host_os == "win") {
|
|
|
|
ldflags += [
|
|
|
|
"/opt:lldlto=" + lto_opt_level,
|
|
|
|
"/opt:lldltojobs=" + max_jobs_per_lto_link,
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
ldflags += [
|
|
|
|
"-flto=thin",
|
|
|
|
"-Wl,--thinlto-jobs=" + max_jobs_per_lto_link,
|
|
|
|
"-Wl,--lto-O" + lto_opt_level,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2018-11-17 03:21:53 +01:00
|
|
|
}
|
|
|
|
|
2019-04-05 21:12:37 +02:00
|
|
|
config("no_exceptions") {
|
2019-04-09 16:02:02 +02:00
|
|
|
if (host_os != "win") {
|
|
|
|
cflags_cc = [ "-fno-exceptions" ]
|
|
|
|
}
|
2019-04-05 21:12:37 +02:00
|
|
|
}
|
|
|
|
|
2019-01-15 03:43:33 +01:00
|
|
|
config("no_rtti") {
|
|
|
|
if (current_os == "win") {
|
|
|
|
cflags_cc = [ "/GR-" ]
|
|
|
|
} else {
|
|
|
|
cflags_cc = [ "-fno-rtti" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-01 21:34:43 +01:00
|
|
|
# To make an archive that can be distributed, you need to remove this config and
|
|
|
|
# set complete_static_lib.
|
|
|
|
config("thin_archive") {
|
2020-10-12 21:20:58 +02:00
|
|
|
if (current_os != "ios" && current_os != "mac" && current_os != "win") {
|
2019-02-01 21:34:43 +01:00
|
|
|
arflags = [ "-T" ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-17 03:21:53 +01:00
|
|
|
config("llvm_code") {
|
|
|
|
include_dirs = [
|
|
|
|
"//llvm/include",
|
|
|
|
"$root_gen_dir/llvm/include",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
config("lld_code") {
|
|
|
|
include_dirs = [
|
|
|
|
"//lld/include",
|
|
|
|
"$root_gen_dir/lld/include",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
config("clang_code") {
|
2019-01-25 01:29:17 +01:00
|
|
|
if (host_os != "win") {
|
|
|
|
cflags = [ "-fno-strict-aliasing" ]
|
|
|
|
}
|
2018-11-17 03:21:53 +01:00
|
|
|
include_dirs = [
|
|
|
|
"//clang/include",
|
|
|
|
"$root_gen_dir/clang/include",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-01-15 22:08:21 +01:00
|
|
|
config("crt_code") {
|
|
|
|
include_dirs = [ "//compiler-rt/lib" ]
|
|
|
|
cflags = [
|
|
|
|
"-fPIC",
|
|
|
|
"-funwind-tables",
|
|
|
|
"-gline-tables-only",
|
2019-10-19 00:52:17 +02:00
|
|
|
"-fvisibility=hidden",
|
2019-01-15 22:08:21 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2018-11-17 03:21:53 +01:00
|
|
|
config("warn_covered_switch_default") {
|
|
|
|
if (is_clang) {
|
|
|
|
cflags = [ "-Wcovered-switch-default" ]
|
|
|
|
}
|
|
|
|
}
|