Skip to content

Commit 0f45658

Browse files
committed
Reduce headers processed through C2Rust to minimum
1 parent eaa84f9 commit 0f45658

File tree

5 files changed

+258
-247
lines changed

5 files changed

+258
-247
lines changed

build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ fn main() {
269269
let headercopy = out_path.join(c2rust_infile);
270270
println!("cargo:rerun-if-changed=riot-c2rust.h");
271271

272-
std::fs::copy("riot-headers.h", out_path.join("riot-headers.h"))
272+
// C2Rust needs this in the output location next to the headercopy
273+
std::fs::copy("riot-periph.h", out_path.join("riot-periph.h"))
273274
.expect("Failed to copy over header file");
274275

275276
// These constant initializers are unusable without knowledge of which type they're for; adding

riot-bindgen.h

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,159 @@
55
#define UINT16_MAX 0xffff
66
#define UINT32_MAX 0xffffffff
77

8-
#include "riot-headers.h"
8+
9+
/* core libraries */
10+
#include <irq.h>
11+
#ifdef MODULE_CORE_MSG
12+
#include <msg.h>
13+
#endif
14+
#include <mutex.h>
15+
#include <panic.h>
16+
#ifdef MODULE_CORE_THREAD_FLAGS
17+
#include <thread_flags.h>
18+
#endif
19+
#include <thread.h>
20+
21+
/* board include */
22+
#include <board.h>
23+
24+
#include "riot-periph.h"
25+
26+
/* sys libraries */
27+
#ifdef MODULE_BLUETIL_AD
28+
#include <net/bluetil/ad.h>
29+
#endif
30+
#ifdef MODULE_CORD_COMMON
31+
#include <net/cord/common.h>
32+
#endif
33+
#ifdef MODULE_CORD_EP
34+
#include <net/cord/ep.h>
35+
#endif
36+
#ifdef MODULE_CORD_EP_STANDALONE
37+
#include <net/cord/ep_standalone.h>
38+
#endif
39+
#ifdef MODULE_CORD_EPSIM
40+
#include <net/cord/epsim.h>
41+
#endif
42+
#ifdef MODULE_GCOAP
43+
#include <net/gcoap.h>
44+
#endif
45+
#include <net/gnrc.h>
46+
#include <net/gnrc/udp.h>
47+
#include <net/gnrc/pktbuf.h>
48+
#include <net/gnrc/ipv6.h>
49+
#include <net/gnrc/nettype.h>
50+
#include <net/gnrc/netapi.h>
51+
#ifdef MODULE_GNRC_ICMPV6
52+
#include "net/gnrc/icmpv6.h"
53+
#endif
54+
#ifdef MODULE_HASHES
55+
#include <hashes.h>
56+
#include <hashes/aes128_cmac.h>
57+
#include <hashes/md5.h>
58+
#include <hashes/pbkdf2.h>
59+
#include <hashes/sha1.h>
60+
#include <hashes/sha224.h>
61+
#include <hashes/sha256.h>
62+
#include <hashes/sha3.h>
63+
#include <hashes/sha512.h>
64+
#endif
65+
#ifdef MODULE_NANOCOAP
66+
#include <net/nanocoap.h>
67+
#endif
68+
#ifdef MODULE_NANOCOAP_SOCK
69+
#include <net/nanocoap_sock.h>
70+
#endif
71+
#ifdef MODULE_RANDOM
72+
#include <random.h>
73+
#endif
74+
#ifdef MODULE_SOCK
75+
#include <net/sock.h>
76+
#endif
77+
#ifdef MODULE_SOCK_UDP
78+
#include <net/sock/udp.h>
79+
#endif
80+
#ifdef MODULE_SOCK_ASYNC
81+
#include <net/sock/async.h>
82+
#endif
83+
#include <saul.h>
84+
#include <saul_reg.h>
85+
#include <stdio_base.h>
86+
#ifdef MODULE_SHELL
87+
#include <shell.h>
88+
#endif
89+
#ifdef MODULE_SOCK_UTIL
90+
#include <net/sock/util.h>
91+
#endif
92+
#ifdef MODULE_PTHREAD
93+
#include <pthread.h>
94+
#endif
95+
#ifdef MODULE_SUIT
96+
#include "suit.h"
97+
#include "suit/conditions.h"
98+
#include "suit/transport/worker.h"
99+
#endif
100+
#ifdef MODULE_SUIT_TRANSPORT_COAP
101+
#include "suit/transport/coap.h"
102+
#endif
103+
#ifdef MODULE_RIOTBOOT_SLOT
104+
#include "riotboot/slot.h"
105+
#endif
106+
#ifdef MODULE_TINY_STRERROR
107+
#include "tiny_strerror.h"
108+
#endif
109+
#ifdef MODULE_UUID
110+
#include "uuid.h"
111+
#endif
112+
#ifdef MODULE_XTIMER
113+
// Uses C11 generics since https://github.com/RIOT-OS/RIOT/pull/20494
114+
#include <xtimer.h>
115+
#endif
116+
#ifdef MODULE_ZTIMER
117+
#include <ztimer.h>
118+
#endif
119+
#ifdef MODULE_ZTIMER64
120+
#include <ztimer64.h>
121+
#endif
122+
#ifdef MODULE_ZTIMER_PERIODIC
123+
#include <ztimer/periodic.h>
124+
#endif
125+
#ifdef MODULE_VFS
126+
// Actually using VFS needs constants like O_RDONLY
127+
#include <fcntl.h>
128+
#include <vfs.h>
129+
#endif
130+
#ifdef MODULE_AUTO_INIT
131+
#include "auto_init_utils.h"
132+
#endif
133+
134+
/* packages */
135+
#ifdef MODULE_NIMBLE_AUTOADV
136+
# include "nimble_autoadv.h"
137+
# include "nimble_autoadv_params.h"
138+
#endif
139+
#ifdef MODULE_NIMBLE_HOST
140+
# include "host/ble_gatt.h"
141+
# include "host/ble_gap.h"
142+
# include "host/ble_hs_adv.h"
143+
#endif
144+
#ifdef MODULE_NIMBLE_SVC_GAP
145+
#include "services/gap/ble_svc_gap.h"
146+
#endif
147+
148+
/* drivers */
149+
#ifdef MODULE_MICROBIT
150+
#include "microbit.h"
151+
#endif
152+
#ifdef MODULE_WS281X
153+
#include "ws281x_params.h"
154+
#include "ws281x.h"
155+
#endif
156+
157+
/* wolfSSL */
158+
#if defined(MODULE_WOLFSSL)
159+
#include <wolfssl/wolfcrypt/settings.h>
160+
#include <wolfssl/wolfcrypt/sha256.h>
161+
#include <wolfssl/ssl.h>
162+
#include <sock_tls.h>
163+
#endif

riot-c2rust.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,35 @@ static inline void __masked_builtin_arm_set_fpscr(int fpscr){
136136
#undef atomic_intmax_t
137137
#undef atomic_uintmax_t
138138

139-
// Allow header files that pull in lots of odd stuff but don't depend on
140-
// inlines -- like nimble's host/ble_gap.h -- to opt out of C2Rust altogether
141-
#define IS_C2RUST
139+
/* core libraries */
140+
/* for mutex_MUTEX_INIT */
141+
#include <mutex.h>
142142

143-
#include "riot-headers.h"
143+
/* board include */
144+
#include <board.h>
145+
146+
/* All peripherals are also built through C2Rust because the macro_SPI_DEV etc need them */
147+
#include "riot-periph.h"
148+
149+
/* sys libraries */
150+
#ifdef MODULE_BLUETIL_AD
151+
#include <net/bluetil/ad.h>
152+
#endif
153+
#include <net/gnrc/netif.h>
154+
#include <net/gnrc/ipv6.h>
155+
#ifdef MODULE_NANOCOAP
156+
#include <net/nanocoap.h>
157+
#endif
158+
#ifdef MODULE_SHELL
159+
#include <shell.h>
160+
#endif
161+
#ifdef MODULE_SOCK
162+
#include <net/sock.h>
163+
#endif
164+
#ifdef MODULE_ZTIMER
165+
#include <ztimer.h>
166+
#endif
167+
168+
/* This defines the fallback macros in the LED macros' absence from board.h;
169+
* needed for macro_LED<nonexistent>_TOGGLE etc */
170+
#include <led.h>

0 commit comments

Comments
 (0)