pw_tokenizer: add Zephyr support

Adds zephyr build support using Kconfigs for:
- pw_tokenizer
- pw_tokenizer.base64
- pw_tokenizer.decoder

Bug: b/236263182
Change-Id: Ie02a1ad085adb24890dfbcb765e83a58e5beeb23
Signed-off-by: Yuval Peress <peress@google.com>
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/109475
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/Kconfig.zephyr b/Kconfig.zephyr
index d0c43d0..afb0c68 100644
--- a/Kconfig.zephyr
+++ b/Kconfig.zephyr
@@ -38,6 +38,7 @@
 rsource "pw_string/Kconfig"
 rsource "pw_sync_zephyr/Kconfig"
 rsource "pw_sys_io_zephyr/Kconfig"
+rsource "pw_tokenizer/Kconfig"
 rsource "pw_varint/Kconfig"
 
 endif # ZEPHYR_PIGWEED_MODULE
diff --git a/pw_tokenizer/CMakeLists.txt b/pw_tokenizer/CMakeLists.txt
index a0c4484..7928248 100644
--- a/pw_tokenizer/CMakeLists.txt
+++ b/pw_tokenizer/CMakeLists.txt
@@ -59,7 +59,7 @@
     PUBLIC
       "-T${CMAKE_CURRENT_SOURCE_DIR}/pw_tokenizer_linker_sections.ld"
   )
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR Zephyr_FOUND)
   target_link_options(pw_tokenizer
     PUBLIC
       "-T${CMAKE_CURRENT_SOURCE_DIR}/add_tokenizer_sections_to_default_script.ld"
@@ -239,3 +239,9 @@
     modules
     pw_tokenizer
 )
+
+if(Zephyr_FOUND)
+  zephyr_link_libraries_ifdef(CONFIG_PIGWEED_TOKENIZER pw_tokenizer)
+  zephyr_link_libraries_ifdef(CONFIG_PIGWEED_TOKENIZER_BASE64 pw_tokenizer.base64)
+  zephyr_link_libraries_ifdef(CONFIG_PIGWEED_DETOKENIZER pw_tokenizer.decoder)
+endif()
diff --git a/pw_tokenizer/Kconfig b/pw_tokenizer/Kconfig
new file mode 100644
index 0000000..99d1280
--- /dev/null
+++ b/pw_tokenizer/Kconfig
@@ -0,0 +1,33 @@
+# Copyright 2022 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+config PIGWEED_TOKENIZER
+  bool "Enable the pw_tokenizer library"
+  select PIGWEED_CONTAINERS
+  select PIGWEED_PREPROCESSOR
+  select PIGWEED_SPAN
+  select PIGWEED_VARINT
+
+config PIGWEED_TOKENIZER_BASE64
+  bool "Enable the pw_tokenizer.base64 library"
+  select PIGWEED_TOKENIZER
+  select PIGWEED_BASE64
+  select PIGWEED_SPAN
+
+config PIGWEED_DETOKENIZER
+  bool "Enable the pw_tokenizer.decoder library"
+  select PIGWEED_TOKENIZER
+  select PIGWEED_SPAN
+  select PIGWEED_BYTES
+  select PIGWEED_VARINT
\ No newline at end of file
diff --git a/pw_tokenizer/docs.rst b/pw_tokenizer/docs.rst
index 0cd336a..b1cfcc5 100644
--- a/pw_tokenizer/docs.rst
+++ b/pw_tokenizer/docs.rst
@@ -137,6 +137,23 @@
 8. Integrate ``detokenize.py`` or the C++ detokenization library with your tools
    to decode tokenized logs. See `Detokenization`_.
 
+Using with Zephyr
+=================
+When building ``pw_tokenizer`` with Zephyr, 3 Kconfigs can be used currently:
+
+* ``CONFIG_PIGWEED_TOKENIZER`` will automatically link ``pw_tokenizer`` as well
+  as any dependencies.
+* ``CONFIG_PIGWEED_TOKENIZER_BASE64`` will automatically link
+  ``pw_tokenizer.base64`` as well as any dependencies.
+* ``CONFIG_PIGWEED_DETOKENIZER`` will automatically link
+  ``pw_tokenizer.decoder`` as well as any dependencies.
+
+Once enabled, the tokenizer headers can be included like any Zephyr headers:
+
+.. code-block:: cpp
+
+   #include <pw_tokenizer/tokenize.h>
+
 ------------
 Tokenization
 ------------