From 88febad4a694387fbd02069c6f03a254e8eb62ae Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 8 Jan 2025 00:00:24 +0100 Subject: [PATCH] Reduce headers processed through C2Rust to minimum --- riot-bindgen.h | 157 +++++++++++++++++++++++++++++++- riot-c2rust.h | 35 ++++++- riot-headers.h | 241 ------------------------------------------------- riot-periph.h | 69 ++++++++++++++ 4 files changed, 256 insertions(+), 246 deletions(-) delete mode 100644 riot-headers.h create mode 100644 riot-periph.h diff --git a/riot-bindgen.h b/riot-bindgen.h index d765b2e..fe4d9d5 100644 --- a/riot-bindgen.h +++ b/riot-bindgen.h @@ -5,4 +5,159 @@ #define UINT16_MAX 0xffff #define UINT32_MAX 0xffffffff -#include "riot-headers.h" + +/* core libraries */ +#include +#ifdef MODULE_CORE_MSG +#include +#endif +#include +#include +#ifdef MODULE_CORE_THREAD_FLAGS +#include +#endif +#include + +/* board include */ +#include + +#include "riot-periph.h" + +/* sys libraries */ +#ifdef MODULE_BLUETIL_AD +#include +#endif +#ifdef MODULE_CORD_COMMON +#include +#endif +#ifdef MODULE_CORD_EP +#include +#endif +#ifdef MODULE_CORD_EP_STANDALONE +#include +#endif +#ifdef MODULE_CORD_EPSIM +#include +#endif +#ifdef MODULE_GCOAP +#include +#endif +#include +#include +#include +#include +#include +#include +#ifdef MODULE_GNRC_ICMPV6 +#include "net/gnrc/icmpv6.h" +#endif +#ifdef MODULE_HASHES +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#ifdef MODULE_NANOCOAP +#include +#endif +#ifdef MODULE_NANOCOAP_SOCK +#include +#endif +#ifdef MODULE_RANDOM +#include +#endif +#ifdef MODULE_SOCK +#include +#endif +#ifdef MODULE_SOCK_UDP +#include +#endif +#ifdef MODULE_SOCK_ASYNC +#include +#endif +#include +#include +#include +#ifdef MODULE_SHELL +#include +#endif +#ifdef MODULE_SOCK_UTIL +#include +#endif +#ifdef MODULE_PTHREAD +#include +#endif +#ifdef MODULE_SUIT +#include "suit.h" +#include "suit/conditions.h" +#include "suit/transport/worker.h" +#endif +#ifdef MODULE_SUIT_TRANSPORT_COAP +#include "suit/transport/coap.h" +#endif +#ifdef MODULE_RIOTBOOT_SLOT +#include "riotboot/slot.h" +#endif +#ifdef MODULE_TINY_STRERROR +#include "tiny_strerror.h" +#endif +#ifdef MODULE_UUID +#include "uuid.h" +#endif +#ifdef MODULE_XTIMER +// Uses C11 generics since https://github.com/RIOT-OS/RIOT/pull/20494 +#include +#endif +#ifdef MODULE_ZTIMER +#include +#endif +#ifdef MODULE_ZTIMER64 +#include +#endif +#ifdef MODULE_ZTIMER_PERIODIC +#include +#endif +#ifdef MODULE_VFS +// Actually using VFS needs constants like O_RDONLY +#include +#include +#endif +#ifdef MODULE_AUTO_INIT +#include "auto_init_utils.h" +#endif + +/* packages */ +#ifdef MODULE_NIMBLE_AUTOADV +# include "nimble_autoadv.h" +# include "nimble_autoadv_params.h" +#endif +#ifdef MODULE_NIMBLE_HOST +# include "host/ble_gatt.h" +# include "host/ble_gap.h" +# include "host/ble_hs_adv.h" +#endif +#ifdef MODULE_NIMBLE_SVC_GAP +#include "services/gap/ble_svc_gap.h" +#endif + +/* drivers */ +#ifdef MODULE_MICROBIT +#include "microbit.h" +#endif +#ifdef MODULE_WS281X +#include "ws281x_params.h" +#include "ws281x.h" +#endif + +/* wolfSSL */ +#if defined(MODULE_WOLFSSL) +#include +#include +#include +#include +#endif diff --git a/riot-c2rust.h b/riot-c2rust.h index 9337b04..e9858fe 100644 --- a/riot-c2rust.h +++ b/riot-c2rust.h @@ -136,8 +136,35 @@ static inline void __masked_builtin_arm_set_fpscr(int fpscr){ #undef atomic_intmax_t #undef atomic_uintmax_t -// Allow header files that pull in lots of odd stuff but don't depend on -// inlines -- like nimble's host/ble_gap.h -- to opt out of C2Rust altogether -#define IS_C2RUST +/* core libraries */ +/* for mutex_MUTEX_INIT */ +#include -#include "riot-headers.h" +/* board include */ +#include + +/* All peripherals are also built through C2Rust because the macro_SPI_DEV etc need them */ +#include "riot-periph.h" + +/* sys libraries */ +#ifdef MODULE_BLUETIL_AD +#include +#endif +#include +#include +#ifdef MODULE_NANOCOAP +#include +#endif +#ifdef MODULE_SHELL +#include +#endif +#ifdef MODULE_SOCK +#include +#endif +#ifdef MODULE_ZTIMER +#include +#endif + +/* This defines the fallback macros in the LED macros' absence from board.h; + * needed for macro_LED_TOGGLE etc */ +#include diff --git a/riot-headers.h b/riot-headers.h deleted file mode 100644 index e0329f0..0000000 --- a/riot-headers.h +++ /dev/null @@ -1,241 +0,0 @@ -/* core libraries */ -#include -#ifdef MODULE_CORE_MSG -#include -#endif -#include -#include -#ifdef MODULE_CORE_THREAD_FLAGS -#include -#endif -#include - -/* board include */ -#include - -/* periph drivers */ -#ifdef MODULE_PERIPH_ADC -#include -#endif -#ifdef MODULE_PERIPH_CAN -#include -#endif -#ifdef MODULE_PERIPH_CPUID -#include -#endif -#ifdef MODULE_PERIPH_DAC -#include -#endif -#ifdef MODULE_PERIPH_EEPROM -#include -#endif -#ifdef MODULE_PERIPH_FLASHPAGE -#include -#endif -#ifdef MODULE_PERIPH_GPIO -#include -#include -#endif -#ifdef MODULE_PERIPH_HWRNG -#include -#endif -#ifdef MODULE_PERIPH_I2C -#include -#endif -#ifdef MODULE_PERIPH_INIT -#include -#endif -#ifdef MODULE_PERIPH_PM -#include -#endif -#ifdef MODULE_PERIPH_PWM -#include -#endif -#ifdef MODULE_PERIPH_QDEC -#include -#endif -#ifdef MODULE_PERIPH_RTC -#include -#endif -#ifdef MODULE_PERIPH_RTT -#include -#endif -#ifdef MODULE_PERIPH_SPI -#include -#endif -#ifdef MODULE_PERIPH_TIMER -#include -#endif -#ifdef MODULE_PERIPH_UART -#include -#endif -// Disabled as it'd trigger the USB_H_USER_IS_RIOT_INTERNAL checks. -// -// The right way to enable it would be to add a Rust feature to riot-sys, -// off-by-default, that an application pulls in (probably via an equivalent -// flag in riot-wrappers) that enables access to usbdev. Once anything in the -// dependency tree does that, that pulls the whole build into the "needs a -// declared USB ID, and if it's only testing" territory. -// -// #ifdef MODULE_PERIPH_USBDEV -// #include -// #endif -#ifdef MODULE_PERIPH_WDT -#include -#endif - -/* sys libraries */ -#ifdef MODULE_BLUETIL_AD -#include -#endif -#ifdef MODULE_CORD_COMMON -#include -#endif -#ifdef MODULE_CORD_EP -#include -#endif -#ifdef MODULE_CORD_EP_STANDALONE -#include -#endif -#ifdef MODULE_CORD_EPSIM -#include -#endif -#ifdef MODULE_GCOAP -#include -#endif -#include -#include -#include -#include -#include -#include -#ifdef MODULE_GNRC_ICMPV6 -#include "net/gnrc/icmpv6.h" -#endif -#ifdef MODULE_HASHES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif -#ifdef MODULE_NANOCOAP -#include -#endif -#ifdef MODULE_NANOCOAP_SOCK -#include -#endif -#ifdef MODULE_RANDOM -#include -#endif -#ifdef MODULE_SOCK -#include -#endif -#ifdef MODULE_SOCK_UDP -#include -#endif -#ifdef MODULE_SOCK_ASYNC -#include -#endif -#include -#include -#include -#ifdef MODULE_SHELL -#include -#endif -#ifdef MODULE_SOCK_UTIL -#include -#endif -#ifdef MODULE_PTHREAD -#include -#endif -#ifdef MODULE_SUIT -#include "suit.h" -#include "suit/conditions.h" -#include "suit/transport/worker.h" -#endif -#ifdef MODULE_SUIT_TRANSPORT_COAP -#include "suit/transport/coap.h" -#endif -#ifdef MODULE_RIOTBOOT_SLOT -#include "riotboot/slot.h" -#endif -#ifdef MODULE_TINY_STRERROR -#include "tiny_strerror.h" -#endif -#ifdef MODULE_UUID -#include "uuid.h" -#endif -#ifdef MODULE_XTIMER -// Uses C11 generics since https://github.com/RIOT-OS/RIOT/pull/20494 -#ifndef IS_C2RUST -#include -#endif -#endif -#ifdef MODULE_ZTIMER -#include -#endif -#ifdef MODULE_ZTIMER64 -#ifndef IS_C2RUST -#include -#endif -#endif -#ifdef MODULE_ZTIMER_PERIODIC -#include -#endif -#ifdef MODULE_VFS -// Touches atomics, but we don't need macro expansions or static inlines from this one -#ifndef IS_C2RUST -// Actually using VFS needs constants like O_RDONLY -#include -#include -#endif -#endif -#ifdef MODULE_AUTO_INIT -#include "auto_init_utils.h" -#endif - -/* packages */ -#ifdef MODULE_NIMBLE_AUTOADV -# ifndef IS_C2RUST -/* These contain variadic functions ... and besides, let's only use C2Rust where we need it */ -# include "nimble_autoadv.h" -# include "nimble_autoadv_params.h" -# endif -#endif -#ifdef MODULE_NIMBLE_HOST -# include "host/ble_gatt.h" -# ifndef IS_C2RUST -# include "host/ble_gap.h" -# endif -# include "host/ble_hs_adv.h" -#endif -#ifdef MODULE_NIMBLE_SVC_GAP -#include "services/gap/ble_svc_gap.h" -#endif - -/* drivers */ -#ifdef MODULE_MICROBIT -#include "microbit.h" -#endif -#ifdef MODULE_WS281X -#include "ws281x_params.h" -#include "ws281x.h" -#endif - -/* wolfSSL */ -#if defined(MODULE_WOLFSSL) && !defined(IS_C2RUST) -#include -#include -#include -#include -#endif - -// Note that while the actual definitions are always in board.h, this defines -// the fallback macros that make sure that in the LED macros' absence, -// fallbacks are there. -#include diff --git a/riot-periph.h b/riot-periph.h new file mode 100644 index 0000000..86a4b67 --- /dev/null +++ b/riot-periph.h @@ -0,0 +1,69 @@ +#ifdef MODULE_PERIPH_ADC +#include +#endif +#ifdef MODULE_PERIPH_CAN +#include +#endif +#ifdef MODULE_PERIPH_CPUID +#include +#endif +#ifdef MODULE_PERIPH_DAC +#include +#endif +#ifdef MODULE_PERIPH_EEPROM +#include +#endif +#ifdef MODULE_PERIPH_FLASHPAGE +#include +#endif +#ifdef MODULE_PERIPH_GPIO +#include +#include +#endif +#ifdef MODULE_PERIPH_HWRNG +#include +#endif +#ifdef MODULE_PERIPH_I2C +#include +#endif +#ifdef MODULE_PERIPH_INIT +#include +#endif +#ifdef MODULE_PERIPH_PM +#include +#endif +#ifdef MODULE_PERIPH_PWM +#include +#endif +#ifdef MODULE_PERIPH_QDEC +#include +#endif +#ifdef MODULE_PERIPH_RTC +#include +#endif +#ifdef MODULE_PERIPH_RTT +#include +#endif +#ifdef MODULE_PERIPH_SPI +#include +#endif +#ifdef MODULE_PERIPH_TIMER +#include +#endif +#ifdef MODULE_PERIPH_UART +#include +#endif +// Disabled as it'd trigger the USB_H_USER_IS_RIOT_INTERNAL checks. +// +// The right way to enable it would be to add a Rust feature to riot-sys, +// off-by-default, that an application pulls in (probably via an equivalent +// flag in riot-wrappers) that enables access to usbdev. Once anything in the +// dependency tree does that, that pulls the whole build into the "needs a +// declared USB ID, and if it's only testing" territory. +// +// #ifdef MODULE_PERIPH_USBDEV +// #include +// #endif +#ifdef MODULE_PERIPH_WDT +#include +#endif