Skip to content

Commit

Permalink
pw_tokenizer: add Zephyr support
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/109475
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Wyatt Hepler <[email protected]>
  • Loading branch information
yperess authored and CQ Bot Account committed Sep 8, 2022
1 parent aa32c67 commit 4184768
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rsource "pw_stream/Kconfig"
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
8 changes: 7 additions & 1 deletion pw_tokenizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "")
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"
Expand Down Expand Up @@ -239,3 +239,9 @@ pw_add_test(pw_tokenizer.tokenize_test
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()
33 changes: 33 additions & 0 deletions pw_tokenizer/Kconfig
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions pw_tokenizer/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ These steps can be adapted as needed.
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
------------
Expand Down

0 comments on commit 4184768

Please sign in to comment.