From c198457a117a0ac0c25153cde447b0cb3f4062f9 Mon Sep 17 00:00:00 2001 From: Elliot Date: Sun, 21 Sep 2025 20:24:24 -0400 Subject: [PATCH] libcbor: add 0.13.0 --- ci_config.json | 5 + releases.json | 8 + subprojects/libcbor.wrap | 9 + subprojects/packagefiles/libcbor/meson.build | 161 ++++++++++++++++++ .../packagefiles/libcbor/meson_options.txt | 26 +++ .../libcbor/src/cbor/cbor_export.h | 17 ++ .../packagefiles/libcbor/src/cbor/meson.build | 19 +++ tools/sanity_checks.py | 3 + 8 files changed, 248 insertions(+) create mode 100644 subprojects/libcbor.wrap create mode 100644 subprojects/packagefiles/libcbor/meson.build create mode 100644 subprojects/packagefiles/libcbor/meson_options.txt create mode 100644 subprojects/packagefiles/libcbor/src/cbor/cbor_export.h create mode 100644 subprojects/packagefiles/libcbor/src/cbor/meson.build diff --git a/ci_config.json b/ci_config.json index a4c64b527..0aaaf5b92 100644 --- a/ci_config.json +++ b/ci_config.json @@ -610,6 +610,11 @@ "libattr1-dev" ] }, + "libcbor": { + "build_options": [ + "libcbor:tests=enabled" + ] + }, "libdrm": { "_comment": "- relies on Linux and BSD specific APIs", "build_on": { diff --git a/releases.json b/releases.json index 1202ecc3e..c4777b301 100644 --- a/releases.json +++ b/releases.json @@ -1874,6 +1874,14 @@ "2.76-1" ] }, + "libcbor": { + "dependency_names": [ + "libcbor" + ], + "versions": [ + "0.13.0-1" + ] + }, "libccp4c": { "dependency_names": [ "libccp4c" diff --git a/subprojects/libcbor.wrap b/subprojects/libcbor.wrap new file mode 100644 index 000000000..b56851b24 --- /dev/null +++ b/subprojects/libcbor.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = libcbor-0.13.0 +source_url = https://github.com/PJK/libcbor/archive/refs/tags/v0.13.0.tar.gz +source_filename = libcbor-0.13.0.tar.gz +source_hash = 95a7f0dd333fd1dce3e4f92691ca8be38227b27887599b21cd3c4f6d6a7abb10 +patch_directory = libcbor + +[provide] +dependency_names = libcbor diff --git a/subprojects/packagefiles/libcbor/meson.build b/subprojects/packagefiles/libcbor/meson.build new file mode 100644 index 000000000..46e524f43 --- /dev/null +++ b/subprojects/packagefiles/libcbor/meson.build @@ -0,0 +1,161 @@ +project( + 'libcbor', + 'c', + version: '0.13.0', + meson_version: '>=0.59.0', + default_options: ['warning_level=3'], + license: 'MIT', +) + +cc = meson.get_compiler('c') + +tests_opt = get_option('tests').disable_auto_if(meson.is_subproject()) + +subdir('src/cbor') + +src = [ + 'src/cbor.c', + 'src/allocators.c', + 'src/cbor/streaming.c', + 'src/cbor/internal/encoders.c', + 'src/cbor/internal/builder_callbacks.c', + 'src/cbor/internal/loaders.c', + 'src/cbor/internal/memory_utils.c', + 'src/cbor/internal/stack.c', + 'src/cbor/internal/unicode.c', + 'src/cbor/encoding.c', + 'src/cbor/serialization.c', + 'src/cbor/arrays.c', + 'src/cbor/common.c', + 'src/cbor/floats_ctrls.c', + 'src/cbor/bytestrings.c', + 'src/cbor/callbacks.c', + 'src/cbor/strings.c', + 'src/cbor/maps.c', + 'src/cbor/tags.c', + 'src/cbor/ints.c', +] + +inc = include_directories('src') + +c_args = ['-DCBOR_BUILD=1'] + +if get_option('default_library') == 'static' + c_args += ['-DCBOR_BUILD_STATIC=1'] +endif + +libcbor = library( + 'cbor', + src, + config_file, + c_args: c_args, + include_directories: inc, + install: true, + version: meson.project_version(), + override_options: ['c_std=c11'], +) + +libcbor_dep = declare_dependency( + link_with: libcbor, + include_directories: inc, +) + +meson.override_dependency('libcbor', libcbor_dep) + +headers = [ + config_file, + 'src/cbor/streaming.h', + 'src/cbor/cbor_export.h', + 'src/cbor/data.h', + 'src/cbor/encoding.h', + 'src/cbor/serialization.h', + 'src/cbor/arrays.h', + 'src/cbor/common.h', + 'src/cbor/floats_ctrls.h', + 'src/cbor/bytestrings.h', + 'src/cbor/callbacks.h', + 'src/cbor/strings.h', + 'src/cbor/maps.h', + 'src/cbor/tags.h', + 'src/cbor/ints.h', +] + +install_headers('src/cbor.h') +install_headers( + headers, + subdir: 'cbor', +) + +tests = [ + 'test/array_encoders_test.c', + 'test/array_test.c', + 'test/bad_inputs_test.c', + 'test/bytestring_encoders_test.c', + 'test/bytestring_test.c', + 'test/cbor_serialize_test.c', + 'test/cbor_stream_decode_test.c', + 'test/copy_test.c', + 'test/fuzz_test.c', + 'test/map_encoders_test.c', + 'test/map_test.c', + 'test/negint_encoders_test.c', + 'test/negint_test.c', + 'test/pretty_printer_test.c', + 'test/stack_over_limit_test.c', + 'test/string_encoders_test.c', + 'test/string_test.c', + 'test/tag_encoders_test.c', + 'test/tag_test.c', + 'test/uint_encoders_test.c', + 'test/uint_test.c', +] + +if host_machine.system() != 'windows' + tests += [ + 'test/callbacks_test.c', + 'test/memory_utils_test.c', + 'test/unicode_test.c', + ] +endif + +if cc.get_id() != 'clang-cl' + tests += ['test/float_ctrl_encoders_test.c', 'test/float_ctrl_test.c'] +endif + +cmocka = dependency( + 'cmocka', + required: tests_opt, +) +m = cc.find_library( + 'm', + required: false, +) + +if cmocka.found() and tests_opt.allowed() + libcbor_test = static_library( + 'cbor_test', + ['test/assertions.c', 'test/stream_expectations.c', 'test/test_allocator.c'], + include_directories: inc, + dependencies: [libcbor_dep, cmocka, m], + c_args: c_args, + ) + + foreach path : tests + name = path.split('/')[1].replace('.c', '') + test_exe = executable( + name, + path, + include_directories: inc, + link_with: libcbor_test, + dependencies: [libcbor_dep, cmocka, m], + override_options: ['c_std=c11'], + ) + + test( + name, + test_exe, + suite: 'libcbor', + should_fail: false, + ) + endforeach +endif diff --git a/subprojects/packagefiles/libcbor/meson_options.txt b/subprojects/packagefiles/libcbor/meson_options.txt new file mode 100644 index 000000000..d10bae8a3 --- /dev/null +++ b/subprojects/packagefiles/libcbor/meson_options.txt @@ -0,0 +1,26 @@ +option( + 'tests', + type: 'feature', + description: 'Build libcbor tests', +) + +option( + 'buffer_growth', + type: 'integer', + description: 'Growth factor for buffer resizing', + value: 2, +) + +option( + 'max_stack_size', + type: 'integer', + description: 'Maximum stack size for nested structures', + value: 2048, +) + +option( + 'pretty_printer', + type: 'boolean', + description: 'Enable the pretty printer', + value: true, +) diff --git a/subprojects/packagefiles/libcbor/src/cbor/cbor_export.h b/subprojects/packagefiles/libcbor/src/cbor/cbor_export.h new file mode 100644 index 000000000..3e0e76292 --- /dev/null +++ b/subprojects/packagefiles/libcbor/src/cbor/cbor_export.h @@ -0,0 +1,17 @@ +#ifndef CBOR_EXPORT +# if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__ICC) +# define CBOR_EXPORT __attribute__ ((visibility("default"))) +# elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) +# define CBOR_EXPORT __global +/* Windows is special and you cannot just define entry points unconditionally. */ +# elif defined(_WIN32) && !defined(CBOR_BUILD_STATIC) +# ifdef CBOR_BUILD +# define CBOR_EXPORT __declspec(dllexport) +# else +# define CBOR_EXPORT __declspec(dllimport) +# endif +# else +/* nothing else worked, give up and do nothing */ +# define CBOR_EXPORT +# endif +#endif \ No newline at end of file diff --git a/subprojects/packagefiles/libcbor/src/cbor/meson.build b/subprojects/packagefiles/libcbor/src/cbor/meson.build new file mode 100644 index 000000000..891e7f855 --- /dev/null +++ b/subprojects/packagefiles/libcbor/src/cbor/meson.build @@ -0,0 +1,19 @@ +version = meson.project_version().split('.') +config = configuration_data() +config.set('CBOR_VERSION_MAJOR', version[0]) +config.set('CBOR_VERSION_MINOR', version[1]) +config.set('CBOR_VERSION_PATCH', version[2]) +config.set('CBOR_BUFFER_GROWTH', get_option('buffer_growth')) +config.set('CBOR_MAX_STACK_SIZE', get_option('max_stack_size')) +config.set('CBOR_PRETTY_PRINTER', get_option('pretty_printer')) +config.set('CBOR_RESTRICT_SPECIFIER', cc.get_id() == 'msvc' ? '' : 'restrict') +config.set('CBOR_INLINE_SPECIFIER', '') + +config_file = configure_file( + input: 'configuration.h.in', + output: 'configuration.h', + format: 'cmake', + configuration: config, + install: true, + install_dir: get_option('includedir') / 'cbor', +) diff --git a/tools/sanity_checks.py b/tools/sanity_checks.py index 2086ca009..3474f1528 100755 --- a/tools/sanity_checks.py +++ b/tools/sanity_checks.py @@ -72,6 +72,9 @@ 'libcap': { 'gen_cap_names.py', }, + 'libcbor': { + 'cbor_export.h', + }, 'libexif': { 'def.py', },