Skip to content
Merged
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ scripts/format.sh --fix # rewrite in place

### 1.2 Notes

- `meson setup` generates the optional `ppack_version.h` into the build directory; `ppack.h` does not include it.
- `include/ppack.h` defines the version macros, and `meson setup` fails when they differ from `project(version:)`, so a release updates both. `include/ppack_version.h` is a deprecated header that includes `ppack.h`.
- `PPACK_PAYLOAD_BITS` (default 64) sizes only the `PPACK_PAYLOAD_UNITS` buffer macro; every call takes the payload size explicitly. `PPACK_SIMULATE_16BIT_MAU` selects the 16-bit storage model on a host, for tests only. The only Meson option is `build_tests`.
- The test suite builds twice, native and with `PPACK_SIMULATE_16BIT_MAU`. `tests/compatibility` is a separate Meson project that compares against the pinned 2.4.0 source; the command is in `CONTRIBUTING.md`.

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Changed

- `ppack.h` defines `PPACK_VERSION_MAJOR`, `_MINOR`, `_PATCH`, `PPACK_VERSION`, `PPACK_VERSION_STRING` and a new `PPACK_VERSION_NUMBER` (`long`, `MAJOR * 10000 + MINOR * 100 + PATCH`), so a copied-in header carries its version. `ppack_version.h` is no longer generated; it is installed as a deprecated header that includes `ppack.h`. Meson fails to configure when the header and `project(version:)` disagree, and the build needs Meson 0.57 or later.
- CI installs Meson, Ninja and gcovr with `uv` instead of `pip` and `apt`.
- The README is a short landing page, with the integration guide, API reference and design record in `docs/integration.md`, `docs/api.md` and `docs/design.md`. The large-payload verification record is part of `docs/design.md`.

Expand Down
18 changes: 0 additions & 18 deletions config/ppack_version.h.in

This file was deleted.

22 changes: 22 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,25 @@ parameters_load(const ppack_byte_t record[1024u / PPACK_ADDR_UNIT_BITS])
### Other uses

The same table pattern serves I²C and SPI device frames, register images, fixed telemetry packets, and binary exchange between nodes of different addressing models, which see the same bytes.

## Version

`ppack.h` defines the release it belongs to, so a copied-in header still identifies itself:

<!-- snippet: skip -->
```c
#define PPACK_VERSION_MAJOR 2
#define PPACK_VERSION_MINOR 5
#define PPACK_VERSION_PATCH 0
#define PPACK_VERSION "2.5.0"
```

`PPACK_VERSION_NUMBER` is `MAJOR * 10000 + MINOR * 100 + PATCH` as a `long`, so it holds any version where `int` is 16 bits. Compare it in the preprocessor to require a minimum release:

```c
#if PPACK_VERSION_NUMBER < 20500L
#error "ppack 2.5.0 or later is required"
#endif
```

`PPACK_VERSION_STRING` is the same string as `PPACK_VERSION`. `ppack_version.h` is a deprecated header that includes `ppack.h`, kept so existing includes compile until the next major release.
5 changes: 2 additions & 3 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Keep both headers on the same include path, because `ppack.h` includes `ppack_pl
#include "ppack.h"
```

`ppack_version.h` exists only in Meson builds.
`ppack.h` defines the version macros described in [api.md](api.md#version).

## Meson subproject

Expand Down Expand Up @@ -58,10 +58,9 @@ The headers install to a `ppack/` subdirectory, and the `pkg-config` flags add t
<!-- snippet: skip -->
```c
#include <ppack/ppack.h>
#include <ppack/ppack_version.h>
```

`ppack_version.h` defines `PPACK_VERSION` and `PPACK_VERSION_STRING` as the version string, and `PPACK_VERSION_MAJOR`, `PPACK_VERSION_MINOR` and `PPACK_VERSION_PATCH` as integers.
`ppack_version.h` is installed beside it as a deprecated header that includes `ppack.h`.

## Buffer sizing

Expand Down
26 changes: 26 additions & 0 deletions include/ppack.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ extern "C" {

#include "ppack_platform.h"

/* ================ VERSION ================================================= */

/**
* @name Version
* @brief Release of this header, for diagnostics and @c #if checks.
*
* @details
* @c PPACK_VERSION_NUMBER is @c MAJOR*10000 @c + @c MINOR*100
* @c + @c PATCH with type @c long, so it cannot overflow where @c int is
* 16 bits. The Meson build fails to configure when these values differ
* from the project version.
* @{
*/
/* cppcheck-suppress-begin misra-c2012-2.5 ; @deviation Public version macros
* for consumer diagnostics and #if checks; the library does not use them. */
#define PPACK_VERSION_MAJOR 2
#define PPACK_VERSION_MINOR 5
#define PPACK_VERSION_PATCH 0
#define PPACK_VERSION "2.5.0"
#define PPACK_VERSION_STRING PPACK_VERSION
#define PPACK_VERSION_NUMBER \
((PPACK_VERSION_MAJOR * 10000L) + (PPACK_VERSION_MINOR * 100L) \
+ PPACK_VERSION_PATCH)
/* cppcheck-suppress-end misra-c2012-2.5 ; @deviation As above. */
/** @} */

/*
* Re-export the platform abstraction so users picking up ppack.h get
* ppack_byte_t and PPACK_PAYLOAD_UNITS for portable buffer declarations
Expand Down
19 changes: 19 additions & 0 deletions include/ppack_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* SPDX-License-Identifier: MIT
*
* @file ppack_version.h
*
* @brief
* Deprecated: the version macros are defined in ppack.h.
*
* @details
* This header includes ppack.h so that existing includes keep compiling.
* It will be removed in the next major release.
*/

#ifndef PPACK_VERSION_H
#define PPACK_VERSION_H

#include "ppack.h"

#endif /* PPACK_VERSION_H */
48 changes: 26 additions & 22 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@ project(
'ppack',
'c',
version: '2.5.0',
meson_version: '>=0.57.0',
default_options: [
'c_std=c11',
'warning_level=3',
],
license: 'MIT',
)

# === Version header ===========================================================

ver = meson.project_version().split('.')

major = ver[0].to_int()
minor = ver[1].to_int()
patch = ver[2].to_int()

conf = configuration_data()
conf.set_quoted('VERSION', meson.project_version())
conf.set('MAJOR', major)
conf.set('MINOR', minor)
conf.set('PATCH', patch)

configure_file(
input: 'config' / 'ppack_version.h.in',
output: 'ppack_version.h',
configuration: conf,
install: true,
install_dir: get_option('includedir') / 'ppack',
)
# === Version ==================================================================
# include/ppack.h defines the version macros, so a copy-in build has them.
# Configuration fails when they differ from the project version.

fs = import('fs')
version_parts = meson.project_version().split('.')
version_macros = {
'PPACK_VERSION_MAJOR': version_parts[0],
'PPACK_VERSION_MINOR': version_parts[1],
'PPACK_VERSION_PATCH': version_parts[2],
'PPACK_VERSION': '"' + meson.project_version() + '"',
}
header_lines = []
foreach line : fs.read('include' / 'ppack.h').split('\n')
header_lines += ' '.join(line.split())
endforeach
foreach name, value : version_macros
if '#define @0@ @1@'.format(name, value) not in header_lines
error('include/ppack.h must define @0@ as @1@'.format(name, value))
endif
endforeach

# === Include directories ======================================================

Expand All @@ -52,7 +53,10 @@ ppack_lib = static_library(
)

# Install public header
install_headers(['include/ppack.h', 'include/ppack_platform.h'], subdir: 'ppack')
install_headers(
['include/ppack.h', 'include/ppack_platform.h', 'include/ppack_version.h'],
subdir: 'ppack',
)

ppack_dep = declare_dependency(
include_directories: public_headers,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "ppack.h"
#include "ppack_version.h"
#include "test_fixtures.h"
#include "test_harness.h"
#include <ppack_platform.h>
Expand Down Expand Up @@ -424,6 +425,15 @@ TEST_CASE(test_full_payload)
TEST_ASSERT(unpacked.field_uint32 == 0x9ABCDEF0);
}

/* The deprecated version header still exposes the macros from ppack.h. */
TEST_CASE(test_version_macros)
{
TEST_ASSERT(PPACK_VERSION_NUMBER
== ((PPACK_VERSION_MAJOR * 10000L)
+ (PPACK_VERSION_MINOR * 100L) + PPACK_VERSION_PATCH));
TEST_ASSERT(PPACK_VERSION_STRING[0] != '\0');
}

void
run_edge_tests(void)
{
Expand All @@ -446,4 +456,5 @@ run_edge_tests(void)
run_test(test_1bit_field_zero, "test_1bit_field_zero");
run_test(test_overlapping_fields, "test_overlapping_fields");
run_test(test_full_payload, "test_full_payload");
run_test(test_version_macros, "test_version_macros");
}
Loading