Explicitly trigger rebuilds of all targets built for fuchsia when toolchain updates

This adds a define line with the toolchain version (from the stamp file
written out by jiri) to the compilation line for all targets built for
Fuchsia, so we always rebuild when the compiler or other parts of the
toolchain update. Today this is (mostly) redundant with the sysroot
stamp file, but since that is going away soon we need a mechanism to
trigger rebuilds for compiler changes that don't change headers or
libraries in the sysroot proper.

Change-Id: Icf9798002e7537b74dadc1bb9dff4da662e2201d
diff --git a/config/fuchsia/BUILD.gn b/config/fuchsia/BUILD.gn
index f6072c1..7f9432a 100644
--- a/config/fuchsia/BUILD.gn
+++ b/config/fuchsia/BUILD.gn
@@ -68,6 +68,7 @@
     ":icf",
     ":safestack",
     ":thread_safety_annotations",
+    ":toolchain_version_stamp",
     ":werror",
   ]
   if (use_ccache) {
@@ -77,6 +78,21 @@
   asmflags = cflags + cflags_c
 }
 
+config("toolchain_version_stamp") {
+  # We want to force a recompile and relink of the world whenever our toolchain changes since
+  # artifacts from an older version of the toolchain may or may not be compatible with newer ones.
+  # To achieve this, we insert a synthetic define into the compile line.
+  if (host_os == "linux") {
+    toolchain_stamp_file = "//buildtools/linux64/toolchain.stamp"
+  } else if (host_os == "mac") {
+    toolchain_stamp_file = "//buildtools/mac/toolchain.stamp"
+  } else {
+    assert(false, "Unsupported host OS")
+  }
+  toolchain_version = read_file(toolchain_stamp_file, "trim string")
+  defines = [ "TOOLCHAIN_VERSION=$toolchain_version" ]
+}
+
 config("compiler_sysroot") {
   # The sole purpose of SYSROOT_VERSION is to change the command line on every
   # sysroot update so as to force rebuilds.