Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ jobs:
uses: microsoft/setup-msbuild@v1.0.2
- name: Build Mini-XML
run: msbuild vcnet\mxml.sln

build-zephyr:

runs-on: ubuntu-latest

steps:
- name: Checkout Mini-XML sources
uses: actions/checkout@v4
with:
path: mxml
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up Zephyr project
uses: zephyrproject-rtos/action-zephyr-setup@v1
with:
app-path: mxml
toolchains: arm-zephyr-eabi
- name: Build Mini-XML sample
run: west build -b qemu_cortex_m3 mxml/zephyr/samples/basic
- name: Test Mini-XML
run: west twister -T mxml/zephyr/tests -p qemu_cortex_m3 --inline-logs
10 changes: 10 additions & 0 deletions makesrcdist
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ if test "$(grep MXML_VERSION xcode/config.h | awk '{print $5}')" != "v$version\"
status=1
fi

if ! grep -Fq "cpe:2.3:a:msweet:mini-xml:$version:" zephyr/module.yml; then
echo "Update CPE version in zephyr/module.yml."
status=1
fi

if ! grep -Fq "pkg:github/michaelrsweet/mxml@v$version" zephyr/module.yml; then
echo "Update PURL version in zephyr/module.yml."
status=1
fi

if test $status = 1; then
exit 1
fi
Expand Down
26 changes: 26 additions & 0 deletions west.yml
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

Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

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.

#

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
42 changes: 42 additions & 0 deletions zephyr/CMakeLists.txt
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()

40 changes: 40 additions & 0 deletions zephyr/Kconfig
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

63 changes: 63 additions & 0 deletions zephyr/README.md
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).
19 changes: 19 additions & 0 deletions zephyr/config.h.in
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
19 changes: 19 additions & 0 deletions zephyr/module.yml
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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).
I didn't see the makesrcdist: new commit to implement the check added to save you time.

19 changes: 19 additions & 0 deletions zephyr/samples/basic/CMakeLists.txt
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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)

22 changes: 22 additions & 0 deletions zephyr/samples/basic/README.md
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>
```
14 changes: 14 additions & 0 deletions zephyr/samples/basic/prj.conf
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

23 changes: 23 additions & 0 deletions zephyr/samples/basic/sample.yaml
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to restrict the supported platforms?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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

Loading