Repository navigation
env: add zephyr support #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # | ||
| # West manifest for developing and testing Mini-XML on Zephyr. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| manifest: | ||
| self: | ||
| path: mxml | ||
|
|
||
| remotes: | ||
| - name: zephyrproject-rtos | ||
| url-base: https://github.com/zephyrproject-rtos | ||
|
|
||
| projects: | ||
| - name: zephyr | ||
| remote: zephyrproject-rtos | ||
| revision: v4.4.0 | ||
| import: | ||
| name-allowlist: | ||
| - cmsis_6 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # | ||
| # CMakeLists for building Mini-XML as a Zephyr module. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| if(CONFIG_MXML) | ||
| set(MXML_ROOT ${CMAKE_CURRENT_LIST_DIR}/..) | ||
| set(MXML_GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) | ||
|
|
||
| include(${CMAKE_CURRENT_LIST_DIR}/version.cmake) | ||
| if(CONFIG_POSIX_THREADS) | ||
| set(HAVE_PTHREAD_H 1) | ||
| endif() | ||
|
|
||
| configure_file( | ||
| ${CMAKE_CURRENT_LIST_DIR}/config.h.in | ||
| ${MXML_GENERATED_INCLUDE_DIR}/config.h | ||
| ) | ||
|
|
||
| zephyr_library() | ||
| zephyr_library_compile_definitions(_POSIX_C_SOURCE=200809L) | ||
| zephyr_library_sources( | ||
| ${MXML_ROOT}/mxml-attr.c | ||
| ${MXML_ROOT}/mxml-file.c | ||
| ${MXML_ROOT}/mxml-get.c | ||
| ${MXML_ROOT}/mxml-index.c | ||
| ${MXML_ROOT}/mxml-node.c | ||
| ${MXML_ROOT}/mxml-options.c | ||
| ${MXML_ROOT}/mxml-private.c | ||
| ${MXML_ROOT}/mxml-search.c | ||
| ${MXML_ROOT}/mxml-set.c | ||
| ) | ||
| zephyr_include_directories(${MXML_ROOT}) | ||
| zephyr_library_include_directories(${MXML_GENERATED_INCLUDE_DIR}) | ||
| endif() | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # | ||
| # Kconfig options for Mini-XML on Zephyr. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| menuconfig MXML | ||
| bool "Mini-XML library" | ||
| select COMMON_LIBC_MALLOC | ||
| select COMMON_LIBC_CALLOC | ||
| select POSIX_C_LIB_EXT | ||
| help | ||
| Enable Mini-XML, a small XML parsing and serialization library. | ||
| Mini-XML dynamically allocates its options, nodes, attributes, and | ||
| strings. Enabling this option therefore also enables the common libc | ||
| allocator and provides a default 4-KiB malloc arena. Applications can | ||
| override CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE when needed. | ||
|
|
||
| Mini-XML uses POSIX thread-local storage when CONFIG_POSIX_THREADS is | ||
| enabled. Otherwise, string allocator callbacks are shared globally. | ||
|
|
||
| config MXML_FILE_IO | ||
| bool "File-based XML input/output" | ||
| depends on MXML | ||
| depends on POSIX_FILE_SYSTEM | ||
| depends on FAT_FILESYSTEM_ELM || FILE_SYSTEM_LITTLEFS | ||
| help | ||
| Declare support for mxmlLoadFilename(), mxmlSaveFilename(), | ||
| mxmlLoadFile(), and mxmlSaveFile(). This option is available when the | ||
| POSIX file-system layer and a LittleFS or FAT backend are enabled. The | ||
| application must mount the file system before accessing XML files. | ||
|
|
||
| config COMMON_LIBC_MALLOC_ARENA_SIZE | ||
| default 4096 if MXML | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Mini-XML Zephyr (as external module) | ||
|
|
||
| ## Zephyr integration: Getting started | ||
|
|
||
| Add this project as an external module by appending it to your `west.yml` | ||
| project file: | ||
|
|
||
| ```yaml | ||
| manifest: | ||
| remotes: | ||
| - ... | ||
| - name: michaelrsweet | ||
| url-base: https://github.com/michaelrsweet | ||
|
|
||
| projects: | ||
| - ... | ||
| - name: mxml | ||
| remote: michaelrsweet | ||
| revision: master | ||
| path: modules/lib/mxml | ||
| ``` | ||
|
|
||
| Then update your Zephyr workspace: | ||
|
|
||
| ```console | ||
| west update | ||
| ``` | ||
|
|
||
| ## How to use Mini-XML in your Zephyr application | ||
|
|
||
| Enable the library in the application configuration: | ||
|
|
||
| ```kconfig | ||
| CONFIG_MXML=y | ||
| ``` | ||
|
|
||
| Applications can then include the public API with `#include <mxml.h>`. | ||
| Enabling Mini-XML also enables the libc allocator with a default 4-KiB malloc | ||
| arena. Applications can adjust it with | ||
| `CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE` according to their XML workload. | ||
|
|
||
| When `CONFIG_POSIX_THREADS=y`, Mini-XML keeps its string allocator callbacks | ||
| in POSIX thread-local storage. Without POSIX threads, those callbacks are | ||
| shared globally. | ||
|
|
||
| ## File input/output | ||
|
|
||
| To use `mxmlLoadFilename()`, `mxmlSaveFilename()`, or the `FILE`-based APIs, | ||
| enable a supported Zephyr file system and the optional integration: | ||
|
|
||
| ```kconfig | ||
| CONFIG_FILE_SYSTEM=y | ||
| CONFIG_FILE_SYSTEM_LITTLEFS=y | ||
| CONFIG_POSIX_API=y | ||
| CONFIG_MXML_FILE_IO=y | ||
| ``` | ||
|
|
||
| FAT can be selected with `CONFIG_FAT_FILESYSTEM_ELM=y` instead of LittleFS. | ||
| The application must configure and mount the selected backend before accessing | ||
| XML files. | ||
|
|
||
| A sample application is located in `zephyr/samples/basic` and the Zephyr test | ||
| suite is located in `zephyr/tests` (wrapper to the Mini-XML test suite). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // Configuration file for Mini-XML on Zephyr. | ||
| // | ||
| // Copyright © 2026 by Romain Pelletant. | ||
| // | ||
| // Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| // information. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #ifndef MXML_CONFIG_H | ||
| # define MXML_CONFIG_H | ||
|
|
||
| # define MXML_VERSION "@MXML_VERSION@" | ||
|
|
||
| #cmakedefine HAVE_PTHREAD_H 1 | ||
|
|
||
| #endif // !MXML_CONFIG_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # | ||
| # Zephyr module metadata for Mini-XML. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| name: mxml | ||
| build: | ||
| cmake: zephyr | ||
| kconfig: zephyr/Kconfig | ||
|
|
||
| security: | ||
| external-references: | ||
| - cpe:2.3:a:msweet:mini-xml:4.0.6:*:*:*:*:*:*:* | ||
| - pkg:github/michaelrsweet/mxml@v4.0.6 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the version number associated with a tag or just information that comes along with the source archive or checkout? Mainly asking because "makesrcdist" will check all of the files that need version numbers updated, and if this also needs to be updated I'll add a check there as well...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both references are static metadata and needs to be updated (release version for CPE and tag for PURL). |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # | ||
| # CMakeLists for basic sample program for Zephyr. | ||
| # | ||
| # https://www.msweet.org/mxml | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here we should have a copyright header. |
||
| # | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(mxml_basic) | ||
|
|
||
| target_sources(app PRIVATE src/main.c) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Mini-XML basic sample | ||
|
|
||
| ## Overview | ||
|
|
||
| This sample parses an XML document stored in memory, looks up and modifies the | ||
| `value` element, adds a `status` element, and prints the serialized XML. | ||
|
|
||
| ## Building and running | ||
|
|
||
| From a west workspace containing this module, run: | ||
|
|
||
| ```console | ||
| west build -b qemu_cortex_m3 mxml/zephyr/samples/basic | ||
| west build -t run | ||
| ``` | ||
|
|
||
| ## Expected output | ||
|
|
||
| ```console | ||
| Mini-XML parsed value: 42 | ||
| Modified XML: <settings><name>zephyr</name><value>84</value><status>updated</status></settings> | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # | ||
| # Configuration for the Mini-XML Zephyr sample. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| CONFIG_MXML=y | ||
| CONFIG_MAIN_STACK_SIZE=2048 | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # | ||
| # Twister metadata for the Mini-XML Zephyr sample. | ||
| # | ||
| # Copyright © 2026 by Romain Pelletant. | ||
| # | ||
| # Licensed under Apache License v2.0. See the file "LICENSE" for more | ||
| # information. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| sample: | ||
| name: Mini-XML basic example | ||
| description: Parse an XML string with the Mini-XML Zephyr module | ||
| tests: | ||
| sample.modules.mxml.basic: | ||
| tags: | ||
| - mxml | ||
| - xml | ||
| platform_allow: | ||
| - native_sim | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is necessary to restrict the supported platforms?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like a restriction, but it is only intended to select the platform used to test the sample with Twister/Ztest. Mini-XML itself is not restricted to native_sim and the sample can be built for other platforms as well (I’ve also tested it on an STM32G0). |
||
| - qemu_cortex_m3 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this needs to be in the root directory or present at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
west.yml (manifest) is not mandatory but -extremely- useful for zephyr use.
It makes the repo directly usable in two commands (west init -l . && west update) to compile/run library, sample test suite and CI.
That said, if you’d prefer not to have a west manifest in the upstream repository, I can remove it.