gn build: Rename llvm_host_triple to llvm_current_triple and have it use current_{cpu,os}.

This makes e.g. ToolChain::isCrossCompiling() in
clang/lib/Driver/ToolChain.cpp return the correct result
if the compiler was cross-compiled. This change also affects
llvm_default_target_triple, so cross-compiled compilers default to
targeting the cross-compilation target, which makes more sense than
the host that the compiler was compiled on.

This change will also be necessary in order for the correct triples
to appear in generated lit files for non-native targets.

Differential Revision: https://reviews.llvm.org/D56696

llvm-svn: 351168
This commit is contained in:
Peter Collingbourne 2019-01-15 08:20:29 +00:00
parent fddd6a3f69
commit 4d0f6e1a1a
6 changed files with 29 additions and 13 deletions

View File

@ -33,6 +33,13 @@ if (current_os == "") {
current_os = target_os
}
if (target_cpu == "") {
target_cpu = host_cpu
}
if (current_cpu == "") {
current_cpu = target_cpu
}
if (host_os == "win") {
host_toolchain = "//llvm/utils/gn/build/toolchain:win"
} else {

View File

@ -153,6 +153,7 @@ unix_toolchain("unix") {
toolchain_args = {
current_os = host_os
current_cpu = host_cpu
}
}
@ -171,6 +172,7 @@ if (android_ndk_path != "") {
toolchain_args = {
current_os = "android"
current_cpu = "arm64"
}
libcxx_path = "$android_ndk_path/sources/cxx-stl/llvm-libc++"
@ -293,5 +295,6 @@ toolchain("win") {
toolchain_args = {
current_os = "win"
current_cpu = host_cpu
}
}

View File

@ -52,7 +52,7 @@ write_lit_config("lit_site_cfg") {
# builds exist, to make sure it's a toolchain var.
"CMAKE_CXX_COMPILER=c++",
"ENABLE_BACKTRACES=1",
"LLVM_HOST_TRIPLE=$llvm_host_triple",
"LLVM_HOST_TRIPLE=$llvm_current_triple",
"LLVM_LIT_TOOLS_DIR=", # Intentionally empty, matches cmake build.
"LLVM_USE_SANITIZER=",
"PYTHON_EXECUTABLE=$python_path",

View File

@ -322,7 +322,7 @@ write_cmake_config("llvm-config") {
"LINK_POLLY_INTO_TOOLS=",
"LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple",
"LLVM_HAS_ATOMICS=1",
"LLVM_HOST_TRIPLE=$llvm_host_triple",
"LLVM_HOST_TRIPLE=$llvm_current_triple",
"LLVM_NATIVE_ARCH=$native_target",
"LLVM_NATIVE_ASMPARSER=1",
"LLVM_NATIVE_ASMPRINTER=1",

View File

@ -54,7 +54,7 @@ write_lit_config("lit_site_cfg") {
"LLVM_ENABLE_FFI=0",
"LLVM_HAVE_OPT_VIEWER_MODULES=0",
"LLVM_HOST_TRIPLE=$llvm_host_triple",
"LLVM_HOST_TRIPLE=$llvm_current_triple",
"LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib"),
"LLVM_LINK_LLVM_DYLIB=0",
"LLVM_LIT_TOOLS_DIR=", # Intentionally empty, matches cmake build.

View File

@ -1,16 +1,22 @@
if (host_cpu == "x64") {
if (host_os == "linux") {
llvm_host_triple = "x86_64-unknown-linux-gnu"
} else if (host_os == "mac") {
llvm_host_triple = "x86_64-apple-darwin"
} else if (host_os == "win") {
llvm_host_triple = "x86_64-pc-windows"
if (current_cpu == "x64") {
if (current_os == "linux") {
llvm_current_triple = "x86_64-unknown-linux-gnu"
} else if (current_os == "mac") {
llvm_current_triple = "x86_64-apple-darwin"
} else if (current_os == "win") {
llvm_current_triple = "x86_64-pc-windows"
}
} else {
assert(false, "unimplemented host_cpu " + host_cpu)
} else if (current_cpu == "arm64") {
if (current_os == "android") {
llvm_current_triple = "aarch64-linux-android21"
}
}
if (!defined(llvm_current_triple)) {
assert(false, "unimplemented cpu/os " + current_cpu + "/" + current_os)
}
declare_args() {
# The default target triple.
llvm_target_triple = llvm_host_triple
llvm_target_triple = llvm_current_triple
}