diff options
Diffstat (limited to 'llvm/utils/gn/build')
-rw-r--r-- | llvm/utils/gn/build/BUILDCONFIG.gn | 7 | ||||
-rw-r--r-- | llvm/utils/gn/build/libs/pthread/BUILD.gn | 3 | ||||
-rw-r--r-- | llvm/utils/gn/build/toolchain/BUILD.gn | 58 | ||||
-rw-r--r-- | llvm/utils/gn/build/toolchain/compiler.gni | 4 |
4 files changed, 61 insertions, 11 deletions
diff --git a/llvm/utils/gn/build/BUILDCONFIG.gn b/llvm/utils/gn/build/BUILDCONFIG.gn index 1e5af9aeb4b..a46725c6d4a 100644 --- a/llvm/utils/gn/build/BUILDCONFIG.gn +++ b/llvm/utils/gn/build/BUILDCONFIG.gn @@ -25,6 +25,13 @@ set_defaults("source_set") { configs = shared_binary_target_configs } +if (target_os == "") { + target_os = host_os +} +if (current_os == "") { + current_os = target_os +} + if (host_os == "win") { host_toolchain = "//llvm/utils/gn/build/toolchain:win" } else { diff --git a/llvm/utils/gn/build/libs/pthread/BUILD.gn b/llvm/utils/gn/build/libs/pthread/BUILD.gn index 51e7f1f31fa..7708d314603 100644 --- a/llvm/utils/gn/build/libs/pthread/BUILD.gn +++ b/llvm/utils/gn/build/libs/pthread/BUILD.gn @@ -6,7 +6,8 @@ config("pthread_config") { } group("pthread") { - if (llvm_enable_threads && host_os != "win") { + # On Android, bionic has built-in support for pthreads. + if (llvm_enable_threads && current_os != "win" && current_os != "android") { public_configs = [ ":pthread_config" ] } } diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn index c53f753bf57..87276ea98fd 100644 --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -12,10 +12,16 @@ declare_args() { template("unix_toolchain") { toolchain(target_name) { forward_variables_from(invoker, "*") + if (!defined(target_cflags)) { + target_cflags = "" + } + if (!defined(target_ldflags)) { + target_ldflags = "" + } tool("cc") { depfile = "{{output}}.d" - command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}" + command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} $target_cflags" depsformat = "gcc" description = "CC {{output}}" outputs = [ @@ -25,7 +31,7 @@ template("unix_toolchain") { tool("cxx") { depfile = "{{output}}.d" - command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}" + command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $target_cflags" depsformat = "gcc" description = "CXX {{output}}" outputs = [ @@ -39,7 +45,8 @@ template("unix_toolchain") { } else { # Remove the output file first so that ar doesn't try to modify the # existing file. - command = "rm -f {{output}} && $ar rcsDT {{arflags}} {{output}} {{inputs}}" + command = + "rm -f {{output}} && $ar rcsDT {{arflags}} {{output}} {{inputs}}" } description = "AR {{output}}" outputs = [ @@ -52,11 +59,10 @@ template("unix_toolchain") { tool("solink") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" if (current_os == "mac") { - command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}" + command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags" default_output_extension = ".dylib" } else { - command = - "$ld -shared {{ldflags}} -Wl,-z,defs -o $outfile {{libs}} {{inputs}}" + command = "$ld -shared {{ldflags}} -Wl,-z,defs -o $outfile {{libs}} {{inputs}} $target_ldflags" default_output_extension = ".so" } description = "SOLINK $outfile" @@ -71,10 +77,10 @@ template("unix_toolchain") { tool("solink_module") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" if (current_os == "mac") { - command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}" + command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}} $target_ldflags" default_output_extension = ".dylib" } else { - command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}" + command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags" default_output_extension = ".so" } description = "SOLINK $outfile" @@ -88,9 +94,10 @@ template("unix_toolchain") { tool("link") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" if (current_os == "mac") { - command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}" + command = + "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags" } else { - command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group" + command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group $target_ldflags" } description = "LINK $outfile" outputs = [ @@ -137,6 +144,37 @@ unix_toolchain("unix") { } } +if (android_ndk_path != "") { + unix_toolchain("stage2_android_aarch64") { + cc = "bin/clang" + cxx = "bin/clang++" + ld = cxx + ar = "bin/llvm-ar" + + deps = [ + "//:clang($host_toolchain)", + "//:lld($host_toolchain)", + "//:llvm-ar($host_toolchain)", + ] + + toolchain_args = { + current_os = "android" + } + + libcxx_path = "$android_ndk_path/sources/cxx-stl/llvm-libc++" + platform_lib_path = + "$android_ndk_path/platforms/android-21/arch-arm64/usr/lib" + libgcc_path = "$android_ndk_path/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x" + + target_flags = + "--target=aarch64-linux-android21 --sysroot=$android_ndk_path/sysroot" + target_cflags = "$target_flags -isystem $libcxx_path/include" + target_ldflags = "$target_flags -fuse-ld=lld -B$platform_lib_path -L$platform_lib_path -L$libgcc_path" + target_ldflags += + " -nostdlib++ -L$libcxx_path/libs/arm64-v8a -l:libc++.a.21" + } +} + toolchain("win") { cl = "cl" link = "link" diff --git a/llvm/utils/gn/build/toolchain/compiler.gni b/llvm/utils/gn/build/toolchain/compiler.gni index 92d965ef967..c7e89b32a74 100644 --- a/llvm/utils/gn/build/toolchain/compiler.gni +++ b/llvm/utils/gn/build/toolchain/compiler.gni @@ -9,6 +9,10 @@ declare_args() { # On Windows, setting this also causes lld-link to be used as linker. # Example value: getenv("HOME") + "/src/llvm-build/Release+Asserts" clang_base_path = "" + + # Set this to the path to Android NDK r18b. If set, cross compilation targeting + # Android will be enabled. + android_ndk_path = "" } declare_args() { |