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}} $target_cflags"
+ command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
depsformat = "gcc"
description = "CC {{output}}"
outputs = [
tool("cxx") {
depfile = "{{output}}.d"
- command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} $target_cflags"
+ command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}"
depsformat = "gcc"
description = "CXX {{output}}"
outputs = [
tool("asm") {
depfile = "{{output}}.d"
- command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}} $target_cflags"
+ command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}}"
depsformat = "gcc"
description = "ASM {{output}}"
outputs = [
tool("solink") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (current_os == "mac") {
- command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib"
} else {
- command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-z,defs -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".so"
}
description = "SOLINK $outfile"
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}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".dylib"
} else {
- command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld -shared {{ldflags}} -Wl,-soname,{{target_output_name}}{{output_extension}} -o $outfile {{libs}} {{inputs}}"
default_output_extension = ".so"
}
description = "SOLINK $outfile"
tool("link") {
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
if (current_os == "mac") {
- command =
- "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}} $target_ldflags"
+ command = "$ld {{ldflags}} -o $outfile {{libs}} {{inputs}}"
} else {
- command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group $target_ldflags"
+ command = "$ld {{ldflags}} -o $outfile {{libs}} -Wl,--start-group {{inputs}} -Wl,--end-group"
}
description = "LINK $outfile"
outputs = [
toolchain_args = {
current_os = "android"
current_cpu = "arm64"
+ use_lld = true
}
-
- 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"
}
}
--- /dev/null
+import("//llvm/triples.gni")
+import("//llvm/utils/gn/build/toolchain/compiler.gni")
+
+target_flags = []
+target_cflags = []
+target_ldflags = []
+
+if (current_os == "android") {
+ assert(current_cpu == "arm64", "current_cpu not supported")
+
+ 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=$llvm_current_triple",
+ "--sysroot=$android_ndk_path/sysroot",
+ ]
+ target_cflags += [
+ "-isystem",
+ "$libcxx_path/include",
+ ]
+ target_ldflags += [
+ "-B$platform_lib_path",
+ "-L$platform_lib_path",
+ "-L$libgcc_path",
+ ]
+ target_ldflags += [
+ "-nostdlib++",
+ "-L$libcxx_path/libs/arm64-v8a",
+ "-l:libc++.a.21",
+ ]
+}