From: Peter Collingbourne Date: Tue, 15 Jan 2019 08:20:29 +0000 (+0000) Subject: gn build: Rename llvm_host_triple to llvm_current_triple and have it use current_... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42c9ee8c24755e61261cbfa6a4f230f4e045c56e;p=llvm 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351168 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/gn/build/BUILDCONFIG.gn b/utils/gn/build/BUILDCONFIG.gn index 721011699a3..cec736fd8fa 100644 --- a/utils/gn/build/BUILDCONFIG.gn +++ b/utils/gn/build/BUILDCONFIG.gn @@ -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 { diff --git a/utils/gn/build/toolchain/BUILD.gn b/utils/gn/build/toolchain/BUILD.gn index 7a2e584c3a4..dd4d0f9ee83 100644 --- a/utils/gn/build/toolchain/BUILD.gn +++ b/utils/gn/build/toolchain/BUILD.gn @@ -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 } } diff --git a/utils/gn/secondary/clang/test/BUILD.gn b/utils/gn/secondary/clang/test/BUILD.gn index 5929eec3353..681b07cb860 100644 --- a/utils/gn/secondary/clang/test/BUILD.gn +++ b/utils/gn/secondary/clang/test/BUILD.gn @@ -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", diff --git a/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn index 56cae143c20..a85435d41e9 100644 --- a/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ b/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -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", diff --git a/utils/gn/secondary/llvm/test/BUILD.gn b/utils/gn/secondary/llvm/test/BUILD.gn index 8a1d17c6c40..b6f75746781 100644 --- a/utils/gn/secondary/llvm/test/BUILD.gn +++ b/utils/gn/secondary/llvm/test/BUILD.gn @@ -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. diff --git a/utils/gn/secondary/llvm/triples.gni b/utils/gn/secondary/llvm/triples.gni index 7c6aaf72a8d..1987afa0f08 100644 --- a/utils/gn/secondary/llvm/triples.gni +++ b/utils/gn/secondary/llvm/triples.gni @@ -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 }