[avb] Add a target without sysdeps

Add an avb gn target without sysdeps for in-tree build. This allows
different fuchsia toolchains/applications to provide their own
implementation accordingly and not have to be compatible with the
default posix implementation.

Bug: b/236039205
Change-Id: Ie9889c5222ff333c4d9cc323e9ec6777cc1460db
diff --git a/BUILD.gn b/BUILD.gn
index 2e6bf5f..2e8d23b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -3,20 +3,8 @@
 # found in the LICENSE file.
 
 import("//build/zircon/zx_library.gni")
-import("//third_party/android/platform/external/avb/sysdeps.gni")
 
-# SDK library.
-zx_library("avb") {
-  sdk_publishable = true
-  sdk = "source"
-
-  # Headers of this library live with the source directly instead of in
-  # a "include" folder. Therefore we use |public| directly to specify the
-  # paths of the public header files.
-  public = [
-    "libavb/libavb.h",
-    "libavb_atx/libavb_atx.h",
-  ]
+common_vars = {
   sources = [
     "libavb/avb_chain_partition_descriptor.c",
     "libavb/avb_chain_partition_descriptor.h",
@@ -58,23 +46,52 @@
     "libavb_atx/avb_atx_validate.h",
   ]
 
-  if (use_posix_libavb_sysdeps) {
-    sources += [ "libavb/avb_sysdeps_posix.c" ]
-  } else {
-    # Allow avb_sysdeps.h to be included since depending targets will need to implement
-    # them.
-    public += [ "libavb/avb_sysdeps.h" ]
-  }
-
   cflags_c = [
     "-DAVB_COMPILATION",
     "-Wno-implicit-int-conversion",
     "-Wno-shorten-64-to-32",
     "-Wno-strict-prototypes",
   ]
+
+  # Headers of this library live with the source directly instead of in
+  # a "include" folder. Therefore we use |public| directly to specify the
+  # paths of the public header files.
+  public = [
+    "libavb/libavb.h",
+    "libavb_atx/libavb_atx.h",
+  ]
+
   public_configs = [ ":public_include_dirs" ]
 }
 
+# SDK library.
+zx_library("avb") {
+  sdk_publishable = true
+  sdk = "source"
+
+  forward_variables_from(common_vars, "*")
+
+  # For publishable avb sdk target, add the posix implementation as a reference
+  sources += [ "libavb/avb_sysdeps_posix.c" ]
+}
+
+# A target for posix implementation for avb sysdeps.
+source_set("sysdeps-posix") {
+  sources = [ "libavb/avb_sysdeps_posix.c" ]
+  cflags_c = [ "-DAVB_COMPILATION" ]
+}
+
+# A library target for in-tree use. Sysdeps implementation is not given and
+# need to be provided by the final executable target or the toolchain.
+source_set("lib") {
+  forward_variables_from(common_vars, "*")
+  public += [ "libavb/avb_sysdeps.h" ]
+
+  if (is_kernel) {
+    public_deps = [ "//zircon/kernel/lib/libc" ]
+  }
+}
+
 config("public_include_dirs") {
   include_dirs = [ "." ]
 }
diff --git a/sysdeps.gni b/sysdeps.gni
deleted file mode 100644
index a114ab4..0000000
--- a/sysdeps.gni
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2022 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-declare_args() {
-  # Specify whether to use the posix sysdeps implementation provided by
-  # by libavb. This assumes that toolchain has support for stderr, stdin,
-  # malloc()/free() etc. See libavb/avb_sysdeps_posix.c for detail.
-  # If set to false, application must provide an implementation.
-  use_posix_libavb_sysdeps = true
-}