[lavapipe] Conditionalize logging/tracing around USE_MAGMA.

Change-Id: I3c0c1f0411af641cd9097785ebe716a6d6d194a1
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/1015476
Reviewed-by: Josh Gargus <jjosh@google.com>
Commit-Queue: John Rosasco <rosasco@google.com>
diff --git a/src/gallium/frontends/lavapipe/BUILD.gn b/src/gallium/frontends/lavapipe/BUILD.gn
index b8ba591..b30def4 100644
--- a/src/gallium/frontends/lavapipe/BUILD.gn
+++ b/src/gallium/frontends/lavapipe/BUILD.gn
@@ -104,7 +104,7 @@
     "$mesa_build_root/src/compiler/nir",
     "$mesa_build_root/src/gallium/auxiliary",
     "$mesa_build_root/src/gallium/auxiliary/pipe-loader:pipe-loader-llvmpipe",
-    "$mesa_build_root/src/util",
+    "$mesa_build_root/src/util:zircon_util",
     "$mesa_build_root/src/vulkan/util",
   ]
 
@@ -130,7 +130,6 @@
     "lvp_execute.c",
     "lvp_formats.c",
     "lvp_fuchsia.c",
-    "lvp_fuchsia_magma_stubs.c",
     "lvp_fuchsia_memory.c",
     "lvp_image.c",
     "lvp_inline_uniforms.c",
diff --git a/src/gallium/frontends/lavapipe/lvp_fuchsia_magma_stubs.c b/src/gallium/frontends/lavapipe/lvp_fuchsia_magma_stubs.c
deleted file mode 100644
index 317b834..0000000
--- a/src/gallium/frontends/lavapipe/lvp_fuchsia_magma_stubs.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright © 2024 Google, LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include <lib/magma/magma.h>
-
-/* fuchsia_init() calls this, which is unavailable on Lavapipe, which uses Magma sysmem utils,
-   but nothing else (in particular, no Magma IPC to communicate with a Magma System Driver). */
-magma_status_t magma_initialize_logging(magma_handle_t channel) {
-    return MAGMA_STATUS_UNIMPLEMENTED;
-}
-
-/* fuchsia_init() calls this, which is unavailable on Lavapipe, which uses Magma sysmem utils,
-   but nothing else (in particular, no Magma IPC to communicate with a Magma System Driver). */
-magma_status_t magma_initialize_tracing(magma_handle_t channel) {
-    return MAGMA_STATUS_UNIMPLEMENTED;
-}
diff --git a/src/os/BUILD.gn b/src/os/BUILD.gn
index f75d487..533d717 100644
--- a/src/os/BUILD.gn
+++ b/src/os/BUILD.gn
@@ -28,11 +28,22 @@
       "fuchsia.h",
     ]
 
+    defines = [ "USE_MAGMA=1" ]
+
     # Don't depend on libmagma here, do that on executable targets only
     deps = [ "//sdk/lib/magma_client:magma_headers" ]
   }
 }
 
+mesa_source_set("zircon_os") {
+  if (current_os == "fuchsia") {
+    sources = [
+      "fuchsia.cpp",
+      "fuchsia.h",
+    ]
+  }
+}
+
 mesa_source_set("fuchsia_libc_static") {
   sources = [
     "fuchsia_cstubs.c",
diff --git a/src/os/fuchsia.cpp b/src/os/fuchsia.cpp
index e30f871..aca5ff6 100644
--- a/src/os/fuchsia.cpp
+++ b/src/os/fuchsia.cpp
@@ -23,7 +23,10 @@
 
 #include "fuchsia.h"
 
+#if defined(USE_MAGMA)
 #include <lib/magma/magma.h>
+#endif
+
 #include <pthread.h>
 #include <zircon/syscalls.h>
 
@@ -32,6 +35,7 @@
 
 static bool initialize_logging()
 {
+#if defined(USE_MAGMA)
    zx_handle_t channel;
    if (!fuchsia_open("/svc/fuchsia.logger.LogSink", &channel)) {
       // This may go nowhere
@@ -45,12 +49,16 @@
       FUCHSIA_DLOG("magma_initialize_logging failed: %d", status);
       return false;
    }
+#else
+   FUCHSIA_DLOG("initialize_logging: not implemented");
+#endif  // defined(USE_MAGMA)
 
    return true;
 }
 
 static void initialize_tracing()
 {
+#if defined(USE_MAGMA)
    zx_handle_t channel;
    if (!fuchsia_open("/svc/fuchsia.tracing.provider.Registry", &channel)) {
       FUCHSIA_DLOG("Connecting to trace provider failed");
@@ -61,6 +69,9 @@
       FUCHSIA_DLOG("magma_initialize_tracing failed: %d", status);
       return;
    }
+#else
+   FUCHSIA_DLOG("initialize_tracing: not implemented");
+#endif  // defined(USE_MAGMA)
 }
 
 static void initialize()
diff --git a/src/util/BUILD.gn b/src/util/BUILD.gn
index 2580664..8a9c40d 100644
--- a/src/util/BUILD.gn
+++ b/src/util/BUILD.gn
@@ -253,7 +253,6 @@
       "os_dirent_fuchsia.cpp",
     ]
     deps += [
-      "$mesa_build_root/src/os",
       "//sdk/lib/syslog/structured_backend",
       "//sdk/lib/zxio",
       "//zircon/system/ulib/zx",
@@ -286,6 +285,7 @@
 mesa_source_set("magma_util") {
   public_deps = [
     ":util",
+    "$mesa_build_root/src/os",
     "$mesa_build_root/src/util/magma",
   ]
 
@@ -294,6 +294,15 @@
   public_configs = [ ":util_public_config" ]
 }
 
+mesa_source_set("zircon_util") {
+  public_deps = [
+    ":util",
+    "$mesa_build_root/src/os:zircon_os",
+  ]
+
+  public_configs = [ ":util_public_config" ]
+}
+
 mesa_source_set("xmlconfig") {
   sources = [
     "xmlconfig.c",