[developer] Always use in-development level for protocol compatibility check

Previously, Fuchsia builds used `__Fuchsia_API_level__`, which will
never match `CURRENT_SUPPORTED_API_LEVEL` in platform builds. To fix
this, use the same build variable as used for host tool builds.

Rename FUCHSIA_API_LEVEL to NEXT_STABLE_API_LEVEL to avoid confusion
and prepare for `NEXT` when the in-development level will not be
numbered. This name is consistent with the value of the GN variable
`platform_version.in_development_api_level` from which it gets its
value and avoids needing to adjust any logic in the header.

Also ensure NEXT_STABLE_API_LEVEL is not less than
`CURRENT_SUPPORTED_API_LEVEL` because the logic does not allow this.

This fixes the naming issue described in the bug. This entire mechanism
will be replaced in the future.

Bug: 308808613
Change-Id: I4eb893b2cce8147c008bba277e77357759274368
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1063701
Commit-Queue: David Dorwin <ddorwin@google.com>
Reviewed-by: Jacob Rutherford <jruthe@google.com>
diff --git a/src/developer/debug/ipc/BUILD.gn b/src/developer/debug/ipc/BUILD.gn
index dfc7dff..f48ac08 100644
--- a/src/developer/debug/ipc/BUILD.gn
+++ b/src/developer/debug/ipc/BUILD.gn
@@ -6,16 +6,13 @@
 
 import("//build/cpp/sdk_source_set.gni")
 
-if (current_os != "fuchsia") {
-  # TODO(https://fxbug.dev/308808613) Remove this along with FUCHSIA_API_LEVEL.
-  import("//build/config/fuchsia/platform_version.gni")
-  config("fuchsia_api_level_for_developer_tools") {
-    visibility = [ ":*" ]
-    defines = [
-      # Deprecated mechanism used for host tools compatibility versioning.
-      "FUCHSIA_API_LEVEL=${platform_version.in_development_api_level}",
-    ]
-  }
+# Deprecated mechanism used for host tools compatibility versioning.
+# This will be replaced with proper API-level based compatibility mechanisms.
+import("//build/config/fuchsia/platform_version.gni")
+config("fuchsia_api_level_for_developer_tools") {
+  visibility = [ ":*" ]
+  defines =
+      [ "NEXT_STABLE_API_LEVEL=${platform_version.in_development_api_level}" ]
 }
 
 sdk_source_set("ipc") {
@@ -51,9 +48,7 @@
     "//src/lib/unwinder",
   ]
 
-  if (current_os != "fuchsia") {
-    public_configs = [ ":fuchsia_api_level_for_developer_tools" ]
-  }
+  public_configs = [ ":fuchsia_api_level_for_developer_tools" ]
 }
 
 # Unit tests for this directory. These are intended to be referenced by unit
diff --git a/src/developer/debug/ipc/protocol.h b/src/developer/debug/ipc/protocol.h
index 57cfac1..d065794 100644
--- a/src/developer/debug/ipc/protocol.h
+++ b/src/developer/debug/ipc/protocol.h
@@ -35,7 +35,7 @@
 //   - More complex logic could be implemented by checking the protocol version before sending.
 //
 // NOTE: Before you want to bump the kCurrentProtocolVersion, please make sure that
-// CURRENT_SUPPORTED_API_LEVEL is equal to FUCHSIA_API_LEVEL specified in version_history.json.
+// CURRENT_SUPPORTED_API_LEVEL is equal to NEXT_STABLE_API_LEVEL.
 // If not, continue reading the comments below.
 
 constexpr uint32_t kCurrentProtocolVersion = 63;
@@ -44,46 +44,33 @@
 // -------------------------------------
 //
 // We want to maintain a compatibility window of 2 major releases, so that zxdb built with a given
-// FUCHSIA_API_LEVEL could support debug_agent built between FUCHSIA_API_LEVEL-2 (inclusive) and
-// FUCHSIA_API_LEVEL+2 (inclusive). This exceeds the minimum compatibility required by RFC-0169,
-// which only requires forward compatibility (older zxdb with newer debug_agent).
+// NEXT_STABLE_API_LEVEL could support debug_agent built between NEXT_STABLE_API_LEVEL-2 (inclusive)
+// and NEXT_STABLE_API_LEVEL+2 (inclusive). This exceeds the minimum compatibility required by
+// RFC-0169, which only requires forward compatibility (older zxdb with newer debug_agent).
 //
 // To achieve this, kMinimumProtocolVersion must be set to the initial protocol version used in
-// FUCHSIA_API_LEVEL-2. The following macros are used to ensure that kMinimumProtocolVersion is
-// set based on FUCHSIA_API_LEVEL.
+// NEXT_STABLE_API_LEVEL-2. The following macros are used to ensure that kMinimumProtocolVersion is
+// set based on NEXT_STABLE_API_LEVEL.
 //
-// To avoid blocking FUCHSIA_API_LEVEL bumps, we allow CURRENT_SUPPORTED_API_LEVEL to be out of
-// sync with FUCHSIA_API_LEVEL, as long as the kCurrentProtocolVersion stays the same.
-// When FUCHSIA_API_LEVEL changes, we need to update those macros as the following:
+// To avoid blocking NEXT_STABLE_API_LEVEL bumps, we allow CURRENT_SUPPORTED_API_LEVEL to be out of
+// sync with NEXT_STABLE_API_LEVEL, as long as the kCurrentProtocolVersion stays the same.
+// When NEXT_STABLE_API_LEVEL changes, we need to update those macros as the following:
 //
 //   - INITIAL_VERSION_FOR_API_LEVEL_MINUS_2 = INITIAL_VERSION_FOR_API_LEVEL_MINUS_1
 //   - INITIAL_VERSION_FOR_API_LEVEL_MINUS_1 = INITIAL_VERSION_FOR_API_LEVEL_CURRENT
 //   - INITIAL_VERSION_FOR_API_LEVEL_CURRENT = kCurrentProtocolVersion
-//   - CURRENT_SUPPORTED_API_LEVEL = FUCHSIA_API_LEVEL
+//   - CURRENT_SUPPORTED_API_LEVEL = NEXT_STABLE_API_LEVEL
 
 #define INITIAL_VERSION_FOR_API_LEVEL_MINUS_2 56
 #define INITIAL_VERSION_FOR_API_LEVEL_MINUS_1 58
 #define INITIAL_VERSION_FOR_API_LEVEL_CURRENT 60
 #define CURRENT_SUPPORTED_API_LEVEL 19
 
-#if defined(__Fuchsia__) == defined(FUCHSIA_API_LEVEL)
-#error FUCHSIA_API_LEVEL should be defind only and always for non-Fuchsia platforms.
-#endif
-
-#if !defined(FUCHSIA_API_LEVEL)
-// This is a workaround when using this library in the @internal_sdk, as the SDK
-// metadata surface has no way to indicate that a library requires a specific
-// compilation define.
-// When building for host using the @internal_sdk, if __Fuchsia_API_level__ is
-// not defined, the user of this library will need to explicitly define
-// FUCHSIA_API_LEVEL.
-#if !defined(__Fuchsia_API_level__)
-#error FUCHSIA_API_LEVEL or __Fuchsia_API_level__ must be defined
-#endif
-#define FUCHSIA_API_LEVEL __Fuchsia_API_level__
-#endif
-
-#if FUCHSIA_API_LEVEL == CURRENT_SUPPORTED_API_LEVEL
+#if !defined(NEXT_STABLE_API_LEVEL)
+#error `NEXT_STABLE_API_LEVEL` must be defined
+#elif NEXT_STABLE_API_LEVEL < CURRENT_SUPPORTED_API_LEVEL
+#error `NEXT_STABLE_API_LEVEL` must be at least CURRENT_SUPPORTED_API_LEVEL
+#elif NEXT_STABLE_API_LEVEL == CURRENT_SUPPORTED_API_LEVEL
 constexpr uint32_t kMinimumProtocolVersion = INITIAL_VERSION_FOR_API_LEVEL_MINUS_2;
 #else
 // If this branch is chosen, please update as above.