allow overriding {target,host}_link = ... in GN

This lets it be something other than cxx,
e.g. to compile with Goma but to link with the NDK locally,

    declare_args() {
      home = getenv("HOME")
      use_goma = true
      _target = "aarch64-linux-android21"
    }
    ndk = "$home/ndk"

    extra_asmflags = []
    extra_cflags = []
    extra_ldflags = []

    if (use_goma) {
      cc = "$home/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang"
      cxx = "$home/chromium/src/third_party/llvm-build/Release+Asserts/bin/clang++"
      cc_wrapper = "$home/depot_tools/.cipd_bin/gomacc"

      target_cc = cc
      target_cxx = cxx
      target_link = "$ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=$_target"

      extra_asmflags += [ "--target=$_target" ]
      extra_cflags += [ "--target=$_target" ]
    } else {
      cc_wrapper = "ccache"
    }

    is_debug = true
    if (is_debug) {
      extra_cflags += [ "-Os" ]
    }

Change-Id: I17b9c3f72bc308e40c1565536d04d0673efd4ef1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332616
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn
index e8e6ce4..8029086 100644
--- a/gn/toolchain/BUILD.gn
+++ b/gn/toolchain/BUILD.gn
@@ -47,6 +47,11 @@
   link_pool_depth = -1
 }
 
+declare_args() {
+  host_link = host_cxx
+  target_link = target_cxx
+}
+
 # For 'shell' see https://ninja-build.org/manual.html#ref_rule_command
 if (host_os == "win") {
   shell = "cmd.exe /c "
@@ -234,6 +239,7 @@
     ar = invoker.ar
     cc = invoker.cc
     cxx = invoker.cxx
+    link = invoker.link
     lib_switch = "-l"
     lib_dir_switch = "-L"
 
@@ -330,7 +336,7 @@
         _end_group = ""
       }
 
-      command = "$cxx -shared {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} $rpath -o {{output}}"
+      command = "$link -shared {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} $rpath -o {{output}}"
       outputs = [ "{{root_out_dir}}/$soname" ]
       output_prefix = "lib"
       default_output_extension = ".so"
@@ -357,7 +363,7 @@
         _start_group = ""
         _end_group = ""
       }
-      command = "$cxx {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} -o $exe_name"
+      command = "$link {{ldflags}} $_start_group @$rspfile {{frameworks}} {{solibs}} $_end_group {{libs}} -o $exe_name"
 
       outputs = [ "$exe_name" ]
       description = "link {{output}}"
@@ -402,6 +408,7 @@
   ar = target_ar
   cc = target_cc
   cxx = target_cxx
+  link = target_link
 }
 
 gcc_like_toolchain("gcc_like_host") {
@@ -410,4 +417,5 @@
   ar = host_ar
   cc = host_cc
   cxx = host_cxx
+  link = host_link
 }