zephyr_sys/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2024 Linaro LTD
// SPDX-License-Identifier: Apache-2.0

//! Zephyr application support for Rust
//!
//! This crates provides the core functionality for applications written in Rust that run on top of
//! Zephyr.

#![no_std]
// Allow rust naming convention violations.
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
// Zephyr makes use of zero-sized structs, which Rustc considers invalid.  Suppress this warning.
// Note, however, that this suppresses any warnings in the bindings about improper C types.
#![allow(improper_ctypes)]
#![allow(rustdoc::broken_intra_doc_links)]
#![allow(rustdoc::bare_urls)]
// Disable various clippy warnings as they will not be fixable in the bindgen generated code.
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::transmute_int_to_bool)]
#![allow(clippy::useless_transmute)]
#![allow(clippy::len_without_is_empty)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

// We have directed bindgen to not generate copy for any times.  It unfortunately doesn't have an
// easy mechanism to enable just for a few types.

// Fortunately, it isn't difficult to mostly auto-derive copy/clone.
macro_rules! derive_clone {
    ($($t:ty),+ $(,)?) => {
        $(
            impl Clone for $t {
                fn clone(&self) -> $t {
                    *self
                }
            }
        )+
    };
}

macro_rules! derive_copy {
    ($($t:ty),+ $(,)?) => {
        $(
            impl Copy for $t {}
        )+
    }
}

derive_copy!(z_spinlock_key);
derive_clone!(z_spinlock_key);
derive_copy!(k_timeout_t);
derive_clone!(k_timeout_t);