Replace target_cpu with current_cpu in Build.gn files

A recent change was made that failed when building nacl, because despite
the target_cpu being set to x86, current_cpu is x64 for nacl, as it is
cross-compiled to x64 using a different toolchain. As such, we were
building and linking the x86 version of Subzero with the x64 version of
nacl, resulting in a linker error.

See the following doc for more info:
https://chromium.googlesource.com/dart/dartium/src/+/refs/heads/master/tools/gn/docs/cross_compiles.md#as-a-build_gn-author

Bug: b/150008309
Change-Id: I581538cb7bb090e5b30819052eb7e245bc90ab12
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/41528
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 7d2a6f5..8ff1631 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -92,14 +92,14 @@
       ]
     }
 
-    if (target_cpu == "x64") {  # 64 bit version
+    if (current_cpu == "x64") {  # 64 bit version
       cflags += [
         "-m64",
         "-fPIC",
         "-march=x86-64",
         "-mtune=generic",
       ]
-    } else if (target_cpu == "x86") {  # 32 bit version
+    } else if (current_cpu == "x86") {  # 32 bit version
       cflags += [
         "-m32",
         "-msse2",
@@ -137,7 +137,7 @@
     if (is_linux) {
       ldflags = [ "-Wl,--gc-sections" ]
 
-      if (target_cpu == "mipsel") {
+      if (current_cpu == "mipsel") {
         ldflags += [
           "-Wl,--hash-style=sysv",
         ]
@@ -150,7 +150,7 @@
             "-mips32r2",
           ]
         }
-      } else if (target_cpu == "mips64el") {
+      } else if (current_cpu == "mips64el") {
         ldflags += [
           "-Wl,--hash-style=sysv",
           "-mips64r2",
@@ -160,7 +160,7 @@
       }
 
       # A bug in the gold linker prevents using ICF on 32-bit (crbug.com/729532)
-      if (use_gold && (target_cpu == "x86" || target_cpu == "mipsel")) {
+      if (use_gold && (current_cpu == "x86" || current_cpu == "mipsel")) {
         ldflags += [ "-Wl,--icf=none" ]
       }
     }
diff --git a/src/Common/BUILD.gn b/src/Common/BUILD.gn
index 87b7005..8cda8a1 100644
--- a/src/Common/BUILD.gn
+++ b/src/Common/BUILD.gn
@@ -21,7 +21,7 @@
       "/wd4201",  # nameless struct/union
       "/wd5030",  # attribute is not recognized
     ]
-  } else if (target_cpu == "x86" || target_cpu == "x64") {
+  } else if (current_cpu == "x86" || current_cpu == "x64") {
     cflags = [ "-msse2" ]
   }
 }
diff --git a/src/Main/BUILD.gn b/src/Main/BUILD.gn
index 61054d4..5e50ee8 100644
--- a/src/Main/BUILD.gn
+++ b/src/Main/BUILD.gn
@@ -29,7 +29,7 @@
         "-Wno-sign-compare",
       ]
     }
-  } else if (target_cpu == "x86" || target_cpu == "x64") {
+  } else if (current_cpu == "x86" || current_cpu == "x64") {
     cflags = [ "-msse2" ]
     defines =
         [ "NO_SANITIZE_FUNCTION=__attribute__((no_sanitize(\"function\")))" ]
diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
index 4d51c08..66b4bf1 100644
--- a/src/Reactor/BUILD.gn
+++ b/src/Reactor/BUILD.gn
@@ -18,7 +18,7 @@
   # Subzero produces smaller binaries, but doesn't support ARM64, MIPS64, and
   # PPC64.
   use_swiftshader_with_subzero =
-      target_cpu != "arm64" && target_cpu != "mips64el" && target_cpu != "ppc64"
+      current_cpu != "arm64" && current_cpu != "mips64el" && current_cpu != "ppc64"
   supports_llvm = is_linux || is_fuchsia || is_win || is_android || is_mac
 }
 
@@ -38,7 +38,7 @@
       "__STDC_LIMIT_MACROS",
     ]
 
-    if (target_cpu == "x86" || target_cpu == "x64") {
+    if (current_cpu == "x86" || current_cpu == "x64") {
       cflags += [ "-msse2" ]
     }
   }
@@ -71,22 +71,22 @@
       defines += [ "SUBZERO_USE_MICROSOFT_ABI" ]
     }
 
-    if (target_cpu == "x64") {
+    if (current_cpu == "x64") {
       defines += [
         "SZTARGET=X8664",
         "SUBZERO_TARGET=X8664",
       ]
-    } else if (target_cpu == "x86") {
+    } else if (current_cpu == "x86") {
       defines += [
         "SZTARGET=X8632",
         "SUBZERO_TARGET=X8632",
       ]
-    } else if (target_cpu == "mipsel") {
+    } else if (current_cpu == "mipsel") {
       defines += [
         "SZTARGET=MIPS32",
         "SUBZERO_TARGET=MIPS32",
       ]
-    } else if (target_cpu == "arm") {
+    } else if (current_cpu == "arm") {
       defines += [
         "SZTARGET=ARM32",
         "SUBZERO_TARGET=ARM32",
@@ -272,23 +272,23 @@
       "$subzero_llvm_dir/lib/Support/regstrlcpy.c",
     ]
 
-    if (target_cpu == "x64") {
+    if (current_cpu == "x64") {
       sources += [
         "$subzero_dir/src/IceInstX8664.cpp",
         "$subzero_dir/src/IceTargetLoweringX8664.cpp",
       ]
-    } else if (target_cpu == "x86") {
+    } else if (current_cpu == "x86") {
       sources += [
         "$subzero_dir/src/IceInstX8632.cpp",
         "$subzero_dir/src/IceTargetLoweringX8632.cpp",
       ]
-    } else if (target_cpu == "mipsel") {
+    } else if (current_cpu == "mipsel") {
       sources += [
         "$subzero_dir/src/IceAssemblerMIPS32.cpp",
         "$subzero_dir/src/IceInstMIPS32.cpp",
         "$subzero_dir/src/IceTargetLoweringMIPS32.cpp",
       ]
-    } else if (target_cpu == "arm") {
+    } else if (current_cpu == "arm") {
       sources += [
         "$subzero_dir/src/IceAssemblerARM32.cpp",
         "$subzero_dir/src/IceInstARM32.cpp",
diff --git a/src/Renderer/BUILD.gn b/src/Renderer/BUILD.gn
index 6b95b11..364a1a1 100644
--- a/src/Renderer/BUILD.gn
+++ b/src/Renderer/BUILD.gn
@@ -22,7 +22,7 @@
       "/wd4324",  # structure was padded due to alignment specifier
       "/wd5030",  # attribute is not recognized
     ]
-  } else if (target_cpu == "x86" || target_cpu == "x64") {
+  } else if (current_cpu == "x86" || current_cpu == "x64") {
     cflags = [
       "-msse2",
       "-Wno-sign-compare",
diff --git a/third_party/llvm-7.0/BUILD.gn b/third_party/llvm-7.0/BUILD.gn
index 08ec2b0..baa6578 100644
--- a/third_party/llvm-7.0/BUILD.gn
+++ b/third_party/llvm-7.0/BUILD.gn
@@ -69,7 +69,7 @@
       "-Wno-unused-result",
       "-Wno-unused-variable",
     ]
-    if (target_cpu == "x86" || target_cpu == "x64") {
+    if (current_cpu == "x86" || current_cpu == "x64") {
       cflags += [ "-msse2" ]
     }
   }
@@ -325,25 +325,25 @@
     ":swiftshader_llvm_transforms",
   ]
 
-  if (target_cpu == "x86" || target_cpu == "x64") {
+  if (current_cpu == "x86" || current_cpu == "x64") {
     deps += [":swiftshader_llvm_x86"]
-  } else if (target_cpu == "arm") {
+  } else if (current_cpu == "arm") {
     deps += [":swiftshader_llvm_arm"]
-  } else if (target_cpu == "arm64") {
+  } else if (current_cpu == "arm64") {
     deps += [":swiftshader_llvm_aarch64"]
-  } else if (target_cpu == "mipsel" || target_cpu == "mips64el") {
+  } else if (current_cpu == "mipsel" || current_cpu == "mips64el") {
     deps += [":swiftshader_llvm_mips"]
-  } else if (target_cpu == "ppc64") {
+  } else if (current_cpu == "ppc64") {
     deps += [":swiftshader_llvm_ppc"]
   } else {
-    assert(false, "Unsupported target_cpu")
+    assert(false, "Unsupported current_cpu")
   }
 
-  if (target_cpu != current_cpu &&
+  if (current_cpu != current_cpu &&
       (current_cpu == "x86" || current_cpu == "x64") ||
       # Windows ARM64 does cross compilation on Windows x64 host, and requires native
       # x86 target.
-      (is_win && target_cpu == "arm64")) {
+      (is_win && current_cpu == "arm64")) {
     deps += [ ":swiftshader_llvm_x86" ]
   }
 }