From 11313c8d174081baf635fce139870577479699af Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr@google.com>
Date: Mon, 13 May 2019 19:42:10 +0000
Subject: [PATCH] [zircon][gn] Fix $zx/system/ulib/zircon deps from fuzzer
 environment

The libc++ support changes refactored the GN magic around the vDSO
($zx/system/ulib/zircon) target and broke the semantics for derived
environments of the user environment, i.e. user.fuzzer.  Fix that.

Bug: BLD-430 #comment Fix GN build regression introduced by libc++ support.
Bug: ZX-1751 #comment Fix GN build regression introduced by libc++ support.
Change-Id: I47bd7683e97aedb7b2ab7c8ab05a136cd936ff26
---
 zircon/system/ulib/zircon/BUILD.gn | 38 ++++++++++++++++--------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/zircon/system/ulib/zircon/BUILD.gn b/zircon/system/ulib/zircon/BUILD.gn
index 66f7bc58411..6764b26bbac 100644
--- a/zircon/system/ulib/zircon/BUILD.gn
+++ b/zircon/system/ulib/zircon/BUILD.gn
@@ -8,13 +8,10 @@ import("$zx/public/gn/toolchain/environment_redirect.gni")
 # The vDSO can't be built with instrumentation.
 exclude_tags = [ "instrumented" ]
 
-if (toolchain.environment != "user") {
-  # References from other environments only get the headers.
-  group("zircon") {
-    public_deps = [
-      ":headers",
-    ]
-  }
+# References from instrumented variants just redirect.  This prevents extra
+# abigen runs in other toolchains just to get identical generated headers.
+if (toolchain.tags + exclude_tags - exclude_tags != toolchain.tags ||
+    toolchain.environment != "user") {
   environment_redirect("headers") {
     environment_label = "$zx/public/gn/toolchain:user"
     direct = true
@@ -24,21 +21,26 @@ if (toolchain.environment != "user") {
       ":headers",
     ]
   }
-} else if (toolchain.tags + exclude_tags - exclude_tags != toolchain.tags) {
-  # References from instrumented variants just redirect.  This prevents
-  # extra abigen runs in other toolchains just to get identical generated
-  # headers.
-  foreach(target,
-          [
-            "zircon",
-            "headers",
-          ]) {
-    environment_redirect(target) {
+  if (toolchain.base_environment == "user") {
+    # Instrumented variants, and all variants of derived environments,
+    # link against the uninstrumented library.
+    environment_redirect("zircon") {
+      environment_label = "$zx/public/gn/toolchain:user"
       direct = true
       shlib = true
       exclude_variant_tags = exclude_tags
       deps = [
-        ":$target",
+        ":zircon",
+      ]
+    }
+  } else {
+    # References from other environments only get the headers.  This
+    # makes it easy to have "$zx/system/ulib/zircon" deps in common
+    # libraries that need to link against it in userland but that in
+    # other contexts like kernel or userboot are just using the headers.
+    group("zircon") {
+      public_deps = [
+        ":headers",
       ]
     }
   }
-- 
GitLab