[linux] Explicitly set the Clang target for Linux
This is necessary when cross-compiling for other architectures, but
doesn't hurt even when building for host.
Test: CQ
Change-Id: I1c04efb2d7c694b94dd3b7013f7f5fa714e56127
diff --git a/config/clang/clang.gni b/config/clang/clang.gni
index 9240c4d..4945ee3 100644
--- a/config/clang/clang.gni
+++ b/config/clang/clang.gni
@@ -13,9 +13,16 @@
clang_cpu = "aarch64"
} else if (current_cpu == "x64") {
clang_cpu = "x86_64"
-}
-if (defined(clang_cpu)) {
- clang_target = "${clang_cpu}-${current_os}"
} else {
- assert(current_cpu != target_cpu, "Unsupported architecture")
+ assert(false, "CPU not supported")
+}
+
+if (is_fuchsia) {
+ clang_target = "${clang_cpu}-fuchsia"
+} else if (is_linux) {
+ clang_target = "${clang_cpu}-linux-gnu"
+} else if (is_mac) {
+ clang_target = "${clang_cpu}-apple-darwin"
+} else {
+ assert(false, "OS not supported")
}
diff --git a/config/linux/BUILD.gn b/config/linux/BUILD.gn
index 2f00ca0..244b3f4 100644
--- a/config/linux/BUILD.gn
+++ b/config/linux/BUILD.gn
@@ -2,9 +2,13 @@
# 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 = []
+ cflags_c = []
+ cflags_cc = []
ldflags = [
"-static-libstdc++",
@@ -19,6 +23,10 @@
# in the host build directory.
"-Wl,-rpath=\$ORIGIN/",
]
+ configs = [
+ ":sysroot",
+ ":target",
+ ]
# TODO(TC-74) The implicitly linked static libc++.a depends on these.
libs = [
@@ -26,7 +34,7 @@
"pthread",
]
lib_dirs = [ rebase_path("//buildtools/${host_platform}/clang/lib") ]
- configs = [ ":sysroot" ]
+ asmflags = cflags + cflags_c
}
config("sysroot") {
@@ -34,3 +42,9 @@
ldflags = cflags
asmflags = cflags
}
+
+config("target") {
+ cflags = [ "--target=$clang_target" ]
+ asmflags = cflags
+ ldflags = cflags
+}