sdl3_sys/
lib.rs

1#![no_std]
2#![allow(non_camel_case_types)]
3#![cfg_attr(feature = "nightly", feature(breakpoint))] // https://github.com/rust-lang/rust/issues/133724
4#![cfg_attr(feature = "nightly", feature(c_variadic))] // https://github.com/rust-lang/rust/issues/44930
5#![cfg_attr(all(feature = "nightly", doc), feature(doc_cfg))] // https://github.com/rust-lang/rust/issues/43781
6#![doc = include_str!("../README.md")]
7
8extern crate self as sdl3_sys;
9
10// This macro is used to apply a cfg attribute to multiple items
11// e.g. `apply_cfg!(#[cfg(feature = "nightly")] => { type VaList = ::core::ffi::VaList; })`
12macro_rules! apply_cfg {
13    (#[cfg $cfg:tt] => { $($item:item)* }) => { $( #[cfg $cfg] $item )* };
14}
15
16// Get the size of a field of a struct or union
17macro_rules! size_of_field {
18    ($struct:ty, $field:ident) => {
19        $crate::size_of_return_value(&|s: $struct| unsafe {
20            // safety: this is never evaluated
21            #[allow(deprecated)]
22            s.$field
23        })
24    };
25}
26
27pub(crate) use size_of_field;
28
29#[allow(unused)] // incorrectly detected as unused
30const fn size_of_return_value<T, R>(_: &impl FnOnce(T) -> R) -> usize {
31    size_of::<R>()
32}
33
34#[doc(hidden)] // for internal use only
35#[macro_export]
36macro_rules! __const_c_str {
37    ($cstr:ident = $str:expr) => {
38        const $cstr: [::core::ffi::c_char; $str.len() + 1] = {
39            const BYTES: &[::core::primitive::u8] = $str.as_bytes();
40            let mut cstr = [0 as ::core::ffi::c_char; BYTES.len() + 1];
41            let mut i = 0;
42            while i < BYTES.len() {
43                assert!(BYTES[i] != 0, "zero byte in string");
44                cstr[i] = BYTES[i] as ::core::ffi::c_char;
45                i += 1;
46            }
47            cstr
48        };
49    };
50}
51
52#[doc(hidden)]
53#[repr(C)]
54#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
55pub struct NonExhaustive(());
56
57#[cfg(feature = "debug-impls")]
58impl core::fmt::Debug for NonExhaustive {
59    #[inline(always)]
60    fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
61        Ok(())
62    }
63}
64
65const _: () = assert!(size_of::<NonExhaustive>() == 0);
66
67mod generated;
68pub use generated::*;
69
70/// You can set a breakpoint on this function to break into the debugger when asserts
71/// want to trigger a breakpoint.
72///
73/// If the `nightly` feature is enabled, this calls [`core::arch::breakpoint()`],
74/// so you don't have to set a breakpoint manually in that case.
75#[cold]
76#[inline(never)]
77pub fn breakpoint() {
78    #[cfg(feature = "nightly")]
79    core::arch::breakpoint();
80
81    #[cfg(not(feature = "nightly"))]
82    {
83        // raise a double panic to abort (this is no-std so we can't use std::process::abort)
84        struct Abort;
85        impl Drop for Abort {
86            fn drop(&mut self) {
87                panic!("breakpoint");
88            }
89        }
90        let _abort = Abort;
91        panic!("breakpoint");
92    }
93}
94
95/// Extra ffi types for `sdl3-sys`
96pub mod ffi {
97    #[cfg(doc)]
98    /// Equivalent to C's `wchar_t` type. This is `u16` on Windows and `u32` otherwise.
99    /// Enable a `use-libc-*` feature to make this an alias of `libc::wchar_t`.
100    pub type c_wchar_t = u32;
101    #[cfg(all(not(doc), feature = "use-libc-v0-2"))]
102    pub type c_wchar_t = ::libc_v0_2::wchar_t;
103    #[cfg(all(not(any(doc, feature = "use-libc-v0-2")), windows))]
104    pub type c_wchar_t = u16;
105    #[cfg(all(not(any(doc, feature = "use-libc-v0-2")), not(windows)))]
106    pub type c_wchar_t = u32;
107
108    #[cfg(doc)]
109    /// Equivalent to C's `va_list` type. Enable the `nightly` feature and compile with
110    /// the nightly compiler to make this an alias of [`core::ffi::VaList`]. Otherwise,
111    /// this type can't be instantiated.
112    pub enum VaList {}
113    #[cfg(all(not(doc), feature = "nightly"))]
114    pub use core::ffi::VaList;
115    #[cfg(all(not(doc), not(feature = "nightly")))]
116    pub enum VaList {}
117}
118
119pub mod metadata;