Support launching the VulkanUnitTests suite on Fuchsia.

This small CL allows one to build and run the VulkanUnitTests
suite for Fuchsia using the Chromium build system.

Note that the output library generated by the BUILD.gn file
is also renamed libvk_swiftshader.so to correspond to the name
used by other build systems (e.g. CMakeList.txt and Android.{mk,bp}).

This also avoids a Fuchsia-specific issue, where the packaging
scripts under //build/fuchsia/ (in the Chromium src/ tree), get
confused when a generated library has the same name as one of
the system libraries (in this case, libvulkan.so, which is the
Vulkan loader provided by the SDK, and which must be copied into
the final Fuchsia package along the ICD).

Note also that most tests crash inside the generated coroutine
machine code :-/

Instructions to properly rebuild and test this:

  - Have depot_tools in your path, and a valid Chromium source
    checkout.

  - Ensure that your .gclient file contains 'fuchsia' in its
    `target_os` list variable definition, otherwise add it
    and run `gclient sync` again to fetch the Fuchsia SDK
    and other dependencies.

  - Create an output directory configured for a Fuchsia/x64 build, then
    rebuild the test suite target, e.g.:

       gn gen out/Fuchsia --args 'target_os="fuchsia" target_cpu="x64" \
           use_goma = true \
           root_extra_deps = [ \
              "//third_party/swiftshader/tests/VulkanUnitTests:swiftshader_vulkan_unittests" \
	   ]'
       ninja -C out/Fuchsia swiftshader_vulkan_unittests

  - Run the test suite with the wrapper script:

       out/Fuchsia/bin/run_swiftshader_vulkan_unittests

    NOTE: This will start a QEMU instance running a Fuchsia system image
          automatically.

+ Define VK_USE_PLATFORM_FUCHSIA when building
  for Fuchsia. This will be used by future CLs that add
  support for Fuchsia-specific extensions.

Change-Id: I687f51e98ee3cb16f6d585f44f4bb5f0631b1cd8
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34911
Tested-by: David Turner <digit@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn
index 3fd343f..c3f15cc 100644
--- a/src/Vulkan/BUILD.gn
+++ b/src/Vulkan/BUILD.gn
@@ -22,6 +22,11 @@
       "VK_USE_PLATFORM_XLIB_KHR",
       "VK_EXPORT=__attribute__((visibility(\"default\")))",
     ]
+  } else if (is_fuchsia) {
+    defines = [
+      "VK_USE_PLATFORM_FUCHSIA=1",
+      "VK_EXPORT=__attribute__((visibility(\"default\")))",
+    ]
   } else {
     defines = [ "VK_EXPORT=" ]
   }
@@ -105,7 +110,7 @@
 
   configs = [ ":swiftshader_libvulkan_private_config" ]
 
-  output_name = "libvulkan"
+  output_name = "libvk_swiftshader"
   output_dir = "$root_out_dir/swiftshader"
 
   if (is_mac) {
@@ -114,7 +119,7 @@
       "-Wl,-exported_symbols_list," +
           rebase_path("libvk_swiftshader.exports", root_build_dir),
     ]
-  } else if (is_linux) {
+  } else if (is_linux || is_fuchsia) {
     inputs = [
       "libvk_swiftshader.lds",
     ]
diff --git a/tests/VulkanUnitTests/Driver.cpp b/tests/VulkanUnitTests/Driver.cpp
index abcb1ac..d5d40cd 100644
--- a/tests/VulkanUnitTests/Driver.cpp
+++ b/tests/VulkanUnitTests/Driver.cpp
@@ -26,6 +26,9 @@
 #elif defined(__linux__)
 #    include "dlfcn.h"
 #    define OS_LINUX 1
+#elif defined(__Fuchsia__)
+#    include <zircon/dlfcn.h>
+#    define OS_FUCHSIA 1
 #else
 #    error Unimplemented platform
 #endif
@@ -72,13 +75,13 @@
 	#endif
 #elif OS_MAC
 	return load("./build/Darwin/libvk_swiftshader.dylib") ||
-	       load("swiftshader/libvulkan.dylib") ||
+	       load("swiftshader/libvk_swiftshader.dylib") ||
 	       load("libvk_swiftshader.dylib");
 #elif OS_LINUX
 	return load("./build/Linux/libvk_swiftshader.so") ||
-	       load("swiftshader/libvulkan.so") ||
+	       load("swiftshader/libvk_swiftshader.so") ||
 	       load("libvk_swiftshader.so");
-#elif OS_ANDROID
+#elif OS_ANDROID || OS_FUCHSIA
 	return load("libvk_swiftshader.so");
 #else
 	#error Unimplemented platform
@@ -98,7 +101,7 @@
 {
 #if OS_WINDOWS
     dll = LoadLibraryA(path);
-#elif(OS_MAC || OS_LINUX || OS_ANDROID)
+#elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA)
     dll = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
 #else
     return false;
@@ -138,7 +141,7 @@
 
 #if OS_WINDOWS
     FreeLibrary((HMODULE)dll);
-#elif OS_LINUX
+#elif (OS_LINUX || OS_FUCHSIA)
     dlclose(dll);
 #endif
 
@@ -182,7 +185,7 @@
 {
 #if OS_WINDOWS
     return GetProcAddress((HMODULE)dll, name);
-#elif(OS_MAC || OS_LINUX || OS_ANDROID)
+#elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA)
     return dlsym(dll, name);
 #else
     return nullptr;