[loader] merge linux and fuchsia loader defs

This change also generates the linux variant with the correct name,
libvulkan.so. A subsequent change will remove the libvulkan_linux.so
target.

Test: CQ
Change-Id: I1e724178ee33ade6e4babdae4c7d23da11dd810a
diff --git a/BUILD.gn b/BUILD.gn
index 13ab04d..c0fe6f8 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -21,16 +21,24 @@
 
 config("vulkan_build_config") {
   include_dirs = [ "include" ]
-  defines = [
-    "VK_USE_PLATFORM_FUCHSIA=1",
-    "VULKAN_HPP_NO_SMART_HANDLE",
-  ]
+  defines = [ "VULKAN_HPP_NO_SMART_HANDLE" ]
+  if (is_fuchsia) {
+    defines += [ "VK_USE_PLATFORM_FUCHSIA=1" ]
+  }
+  if (is_linux) {
+    defines += [ "VK_USE_PLATFORM_XLIB_KHR=1" ]
+  }
 }
 
 group("vulkan") {
   public_configs = [ ":vulkan_build_config" ]
-  # vulkan.h depends on zircon/types.h
-  public_deps = [ "//zircon/public/lib/zx" ]
+
+  if (is_fuchsia) {
+    # vulkan.h depends on zircon/types.h when VK_USE_PLATFORM_FUCHSIA is defined
+    public_deps = [
+      "//zircon/public/lib/zx",
+    ]
+  }
   deps = [
     # the loader is libvulkan
     "loader",
diff --git a/loader/BUILD.gn b/loader/BUILD.gn
index 4e93286..c4d47a4 100644
--- a/loader/BUILD.gn
+++ b/loader/BUILD.gn
@@ -26,17 +26,8 @@
   vk_loader_debug = "warn,error"
 }
 
-sdk_shared_library("loader") {
-  # The Vulkan loader is named libvulkan
-  output_name = "vulkan"
-
-  category = "partner"
-
-  # The Vulkan loader's interface is defined by standard Khronos vulkan headers
-  # which can be obtained separately from the loader implementation itself.
-  no_headers = true
-
-  configs += [
+source_set("loader_static") {
+  public_configs = [
     "../:vulkan_build_config",
     "../:include_extra_vulkan_headers",
   ]
@@ -48,11 +39,23 @@
 
     # TODO(DX-1059): Remove this when -Wextra-semi clean.
     "-Wno-extra-semi",
-
-    "-DSYSCONFDIR=\"/config\"",
-    "-DEXTRASYSCONFDIR=\"/pkg/data\"",
-    "-DDATADIR=\"/usr/share\"",
   ]
+  if (is_fuchsia) {
+    cflags_c += [
+      "-DSYSCONFDIR=\"/config\"",
+      "-DEXTRASYSCONFDIR=\"/pkg/data\"",
+      "-DDATADIR=\"/usr/share\"",
+    ]
+  }
+  if (is_linux) {
+    # Copied from ../CMakeLists.txt and ./loader_cmake_config.h.in
+    cflags_c += [
+      "-DSYSCONFDIR=\"/etc\"",
+      "-DFALLBACK_CONFIG_DIRS=\"/etc/xdg\"",
+      "-DFALLBACK_DATA_DIRS=\"/usr/local/share:/usr/share\"",
+      "-DHAVE_SECURE_GETENV",
+    ]
+  }
 
   defines = [ "VK_LOADER_DEBUG=\"$vk_loader_debug\"" ]
 
@@ -60,7 +63,6 @@
     "cJSON.c",
     "debug_utils.c",
     "dev_ext_trampoline.c",
-    "dlopen_fuchsia.c",
     "extension_manual.c",
     "loader.c",
     "murmurhash.c",
@@ -69,79 +71,70 @@
     "unknown_ext_chain.c",
     "wsi.c",
   ]
+  if (is_fuchsia) {
+    sources += [ "dlopen_fuchsia.c" ]
+  }
 
-  deps = [
-    "//sdk/fidl/fuchsia.vulkan.loader:fuchsia.vulkan.loader_c_client",
-    "//zircon/public/lib/fdio",
-  ]
-
-  # TODO(MA-488) - while these shared libraries are needed by vulkan icd
-  # the app must provide them, so we add the deps here.
-  deps += [ "//zircon/public/lib/trace-engine" ]
-  deps += [ "//zircon/public/lib/async-default" ]
-
-  # TODO(MA-488): The //zircon/public/lib/async-default dep gives us a dep
-  # on //zircon/public/lib/async, which uses the C++ standard library and
-  # is linked statically (built from source, though async-default is a
-  # prebuilt shared library).  So link in the C++ standard library
-  # statically just to satisfy those references.  When the async-default
-  # dep is dropped, this can change to "none" (i.e. be removed).
-  libcxx_linkage = "static"
-
-  libs = [ "zircon" ]
-
-  runtime_deps = [ "//zircon/public/lib/fdio:fdio_sdk" ]
-
-  # TODO(MA-488): remove this too
-  runtime_deps += [ "//zircon/public/lib/trace-engine:trace-engine_sdk" ]
-  runtime_deps += [ "//zircon/public/lib/async-default:async-default_sdk" ]
+  if (is_fuchsia) {
+    deps = [
+      "//sdk/fidl/fuchsia.vulkan.loader:fuchsia.vulkan.loader_c_client",
+      "//zircon/public/lib/fdio",
+    ]
+  }
 }
 
-# Loader config and definition for building with the linux toolchain.
-# This is intended for use with VM guest binaries. Guest binaries are
-# not required to use this loader; it is used here only to avoid
-# creating a duplicate instance of the vulkan loader repo.
-config("vulkan_linux_build_config") {
-  include_dirs = [
-    "../include",
-    "../build-fuchsia/generated/include",
-  ]
-  defines = [
-    "VK_USE_PLATFORM_XLIB_KHR=1",
-  ]
+if (is_fuchsia) {
+  sdk_shared_library("loader") {
+    # The Vulkan loader is named libvulkan
+    output_name = "vulkan"
+
+    category = "partner"
+
+    # The Vulkan loader's interface is defined by standard Khronos vulkan headers
+    # which can be obtained separately from the loader implementation itself.
+    no_headers = true
+
+    deps = [
+      ":loader_static",
+    ]
+
+    # TODO(MA-488) - while these shared libraries are needed by vulkan icd
+    # the app must provide them, so we add the deps here.
+    deps += [ "//zircon/public/lib/trace-engine" ]
+    deps += [ "//zircon/public/lib/async-default" ]
+
+    # TODO(MA-488): The //zircon/public/lib/async-default dep gives us a dep
+    # on //zircon/public/lib/async, which uses the C++ standard library and
+    # is linked statically (built from source, though async-default is a
+    # prebuilt shared library).  So link in the C++ standard library
+    # statically just to satisfy those references.  When the async-default
+    # dep is dropped, this can change to "none" (i.e. be removed).
+    libcxx_linkage = "static"
+
+    libs = [ "zircon" ]
+
+    runtime_deps = [ "//zircon/public/lib/fdio:fdio_sdk" ]
+
+    # TODO(MA-488): remove this too
+    runtime_deps += [ "//zircon/public/lib/trace-engine:trace-engine_sdk" ]
+    runtime_deps += [ "//zircon/public/lib/async-default:async-default_sdk" ]
+  }
 }
 
+if (is_linux) {
+  shared_library("loader_lib") {
+    # The Vulkan loader is named libvulkan
+    output_name = "vulkan"
+    deps = [
+      ":loader_static",
+    ]
+  }
+}
+
+# Temporary roller staging
 shared_library("loader_linux") {
   output_name = "vulkan_linux"
-
-  public_configs = [
-    ":vulkan_linux_build_config"
-  ]
-
-  # Copied from ../CMakeLists.txt and ./loader_cmake_config.h.in
-  cflags_c = [
-    "-DSYSCONFDIR=\"/etc\"",
-    "-DFALLBACK_CONFIG_DIRS=\"/etc/xdg\"",
-    "-DFALLBACK_DATA_DIRS=\"/usr/local/share:/usr/share\"",
-    "-DHAVE_SECURE_GETENV",
-  ]
-
-  defines = [ "VK_LOADER_DEBUG=\"$vk_loader_debug\"" ]
-
-  include_dirs = [
-    ".",
-  ]
-
-  sources = [
-    "cJSON.c",
-    "debug_utils.c",
-    "dev_ext_trampoline.c",
-    "extension_manual.c",
-    "loader.c",
-    "murmurhash.c",
-    "phys_dev_ext.c",
-    "trampoline.c",
-    "unknown_ext_chain.c",
-    "wsi.c",
+  deps = [
+    ":loader_static",
   ]
 }