use crate as sys;
use compile_fmt::{compile_assert, fmt};
macro_rules! check_constants {
($ident:ident) => {
const _: () = {
compile_assert!(
sys::$ident as i64 == libc::$ident as i64,
"libc/esp-idf-sys constant mismatch for `", stringify!($ident), "`: esp-idf=",
sys::$ident as i64 => fmt::<i64>(),
" libc=", libc::$ident as i64 => fmt::<i64>()
);
};
};
}
macro_rules! check_constants_manually {
($name:literal, $const1:expr, $const2:expr) => {
const _: () = {
compile_assert!(
$const1 as i64 == $const2 as i64,
"libc/esp-idf-sys constant mismatch for `", $name, "`: lhs=",
$const1 as i64 => fmt::<i64>(),
" rhs=", $const2 as i64 => fmt::<i64>()
);
};
};
}
macro_rules! check_types {
($ident:ident) => {
const _: () = {
compile_assert!(
std::mem::size_of::<sys::$ident>() == std::mem::size_of::<libc::$ident>(),
"libc/esp-idf-sys type mismatch for `", stringify!($ident), "` size: esp-idf=",
std::mem::size_of::<sys::$ident>() => fmt::<usize>(),
" libc=", std::mem::size_of::<libc::$ident>() => fmt::<usize>()
);
compile_assert!(
std::mem::align_of::<sys::$ident>() == std::mem::align_of::<libc::$ident>(),
"libc/esp-idf-sys type mismatch for `", stringify!($ident), "` alignment: esp-idf=",
std::mem::align_of::<sys::$ident>() => fmt::<usize>(),
" libc=", std::mem::align_of::<libc::$ident>() => fmt::<usize>()
);
};
};
}
macro_rules! check_types_manually {
($name:literal, $size1:expr, $size2:expr, $align1:expr, $align2:expr) => {
const _: () = {
compile_assert!(
$size1 == $size2,
"libc/esp-idf-sys type mismatch for `", $name, "` size: lhs=",
$size1 => fmt::<usize>(),
" rhs=", $size2 => fmt::<usize>()
);
compile_assert!(
$align1 == $align2,
"libc/esp-idf-sys type mismatch for `", $name, "` alignment: lhs=",
$align1 => fmt::<usize>(),
" rhs=", $align2 => fmt::<usize>()
);
};
};
}
check_types!(clock_t);
#[cfg(any(not(any(esp32, esp32s2, esp32s3)), esp_idf_version_at_least_5_4_0))]
check_types!(wchar_t);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(cmsghdr);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(msghdr);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(sockaddr);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(sockaddr_in6);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(sockaddr_in);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(sockaddr_storage);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AF_INET6);
check_constants!(POLLIN);
check_constants!(POLLRDNORM);
check_constants!(POLLRDBAND);
check_constants!(POLLPRI);
check_constants!(POLLOUT);
check_constants!(POLLWRNORM);
check_constants!(POLLWRBAND);
check_constants!(POLLERR);
check_constants!(POLLHUP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SOL_SOCKET);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_OOB);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_PEEK);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_DONTWAIT);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_DONTROUTE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_WAITALL);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_MORE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_NOSIGNAL);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_TRUNC);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_CTRUNC);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(MSG_EOR);
check_constants!(PTHREAD_STACK_MIN);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGABRT);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGFPE);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGILL);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGINT);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGSEGV);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGTERM);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGHUP);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGQUIT);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(NSIG);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SOMAXCONN);
check_types!(blkcnt_t);
check_types!(blksize_t);
check_types!(clockid_t);
check_types!(dev_t);
check_types!(ino_t);
check_types!(off_t);
check_types!(fsblkcnt_t);
check_types!(fsfilcnt_t);
check_types!(id_t);
check_types!(key_t);
check_types_manually!(
"loff_t",
std::mem::size_of::<sys::__loff_t>(),
std::mem::size_of::<libc::loff_t>(),
std::mem::align_of::<sys::__loff_t>(),
std::mem::align_of::<libc::loff_t>()
);
check_types!(mode_t);
check_types!(nfds_t);
check_types!(nlink_t);
check_types!(pthread_t);
check_types!(pthread_key_t);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(sa_family_t);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(socklen_t);
#[cfg(not(esp_idf_version_at_least_6_0_0))]
check_types!(speed_t);
check_types!(suseconds_t);
#[cfg(not(esp_idf_version_at_least_6_0_0))]
check_types!(tcflag_t);
check_types!(useconds_t);
check_types!(time_t);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(addrinfo);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(ip_mreq);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(in_addr);
check_types!(tm);
#[cfg(not(esp_idf_libc_picolibc))]
check_types!(sigaction);
#[cfg(not(esp_idf_libc_picolibc))]
check_types!(stack_t);
#[cfg(esp_idf_version_at_least_5_0_0)]
check_types!(fd_set);
#[cfg(not(esp_idf_version_at_least_6_0_0))]
check_types!(termios);
#[cfg(not(esp_idf_version_at_least_6_0_0))]
check_constants!(NCCS);
check_constants!(PTHREAD_MUTEX_NORMAL);
check_constants!(PTHREAD_MUTEX_RECURSIVE);
check_constants!(PTHREAD_MUTEX_ERRORCHECK);
check_constants!(FD_SETSIZE);
check_constants!(EPERM);
check_constants!(ENOENT);
check_constants!(ESRCH);
check_constants!(EINTR);
check_constants!(EIO);
check_constants!(ENXIO);
check_constants!(E2BIG);
check_constants!(ENOEXEC);
check_constants!(EBADF);
check_constants!(ECHILD);
check_constants!(EAGAIN);
check_constants!(ENOMEM);
check_constants!(EACCES);
check_constants!(EFAULT);
check_constants!(EBUSY);
check_constants!(EEXIST);
check_constants!(EXDEV);
check_constants!(ENODEV);
check_constants!(ENOTDIR);
check_constants!(EISDIR);
check_constants!(EINVAL);
check_constants!(ENFILE);
check_constants!(EMFILE);
check_constants!(ENOTTY);
check_constants!(ETXTBSY);
check_constants!(EFBIG);
check_constants!(ENOSPC);
check_constants!(ESPIPE);
check_constants!(EROFS);
check_constants!(EMLINK);
check_constants!(EPIPE);
check_constants!(EDOM);
check_constants!(ERANGE);
check_constants!(ENOMSG);
check_constants!(EIDRM);
check_constants!(EDEADLK);
check_constants!(ENOLCK);
check_constants!(ENOSTR);
check_constants!(ENODATA);
check_constants!(ETIME);
check_constants!(ENOSR);
check_constants!(ENOLINK);
check_constants!(EPROTO);
check_constants!(EMULTIHOP);
check_constants!(EBADMSG);
#[cfg(any(not(esp_idf_libc_picolibc), esp_idf_version_at_least_6_0_0))]
check_constants!(EFTYPE);
check_constants!(ENOSYS);
check_constants!(ENOTEMPTY);
check_constants!(ENAMETOOLONG);
check_constants!(ELOOP);
check_constants!(EOPNOTSUPP);
#[cfg(any(not(esp_idf_libc_picolibc), esp_idf_version_at_least_6_0_0))]
check_constants!(EPFNOSUPPORT);
check_constants!(ECONNRESET);
check_constants!(ENOBUFS);
check_constants!(EAFNOSUPPORT);
check_constants!(EPROTOTYPE);
check_constants!(ENOTSOCK);
check_constants!(ENOPROTOOPT);
check_constants!(ECONNREFUSED);
check_constants!(EADDRINUSE);
check_constants!(ECONNABORTED);
check_constants!(ENETUNREACH);
check_constants!(ENETDOWN);
check_constants!(ETIMEDOUT);
#[cfg(any(not(esp_idf_libc_picolibc), esp_idf_version_at_least_6_0_0))]
check_constants!(EHOSTDOWN);
check_constants!(EHOSTUNREACH);
check_constants!(EINPROGRESS);
check_constants!(EALREADY);
check_constants!(EDESTADDRREQ);
check_constants!(EMSGSIZE);
check_constants!(EPROTONOSUPPORT);
check_constants!(EADDRNOTAVAIL);
check_constants!(ENETRESET);
check_constants!(EISCONN);
check_constants!(ENOTCONN);
#[cfg(any(not(esp_idf_libc_picolibc), esp_idf_version_at_least_6_0_0))]
check_constants!(ETOOMANYREFS);
check_constants!(EDQUOT);
check_constants!(ESTALE);
check_constants!(ENOTSUP);
check_constants!(EILSEQ);
check_constants!(EOVERFLOW);
check_constants!(ECANCELED);
check_constants!(ENOTRECOVERABLE);
check_constants!(EOWNERDEAD);
check_constants!(EWOULDBLOCK);
check_constants!(F_DUPFD);
check_constants!(F_GETFD);
check_constants!(F_SETFD);
check_constants!(F_GETFL);
check_constants!(F_SETFL);
check_constants!(F_GETOWN);
check_constants!(F_SETOWN);
check_constants!(F_GETLK);
check_constants!(F_SETLK);
check_constants!(F_SETLKW);
check_constants!(F_RGETLK);
check_constants!(F_RSETLK);
check_constants!(F_CNVT);
check_constants!(F_RSETLKW);
check_constants!(F_DUPFD_CLOEXEC);
check_constants!(O_RDONLY);
check_constants!(O_WRONLY);
check_constants!(O_RDWR);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(O_APPEND);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(O_CREAT);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(O_TRUNC);
check_constants!(O_EXCL);
check_constants!(O_SYNC);
check_constants!(O_NONBLOCK);
check_constants!(O_CLOEXEC);
check_constants!(SEEK_SET);
check_constants!(SEEK_CUR);
check_constants!(SEEK_END);
check_constants!(S_BLKSIZE);
check_constants!(S_IREAD);
check_constants!(S_IWRITE);
check_constants!(S_IEXEC);
check_constants!(S_ENFMT);
check_constants!(S_IFMT);
check_constants!(S_IFDIR);
check_constants!(S_IFCHR);
check_constants!(S_IFBLK);
check_constants!(S_IFREG);
check_constants!(S_IFLNK);
check_constants!(S_IFSOCK);
check_constants!(S_IFIFO);
check_constants!(S_IRUSR);
check_constants!(S_IWUSR);
check_constants!(S_IXUSR);
check_constants!(S_IRGRP);
check_constants!(S_IWGRP);
check_constants!(S_IXGRP);
check_constants!(S_IROTH);
check_constants!(S_IWOTH);
check_constants!(S_IXOTH);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(PF_UNSPEC);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(PF_INET);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(PF_INET6);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AF_UNSPEC);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AF_INET);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SOCK_STREAM);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SOCK_DGRAM);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SHUT_RD);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SHUT_WR);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SHUT_RDWR);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_DEBUG);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_ACCEPTCONN);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_REUSEADDR);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_KEEPALIVE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_DONTROUTE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_BROADCAST);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_USELOOPBACK);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_LINGER);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_OOBINLINE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_REUSEPORT);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_SNDBUF);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_RCVBUF);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_SNDLOWAT);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_RCVLOWAT);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_SNDTIMEO);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_RCVTIMEO);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_ERROR);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(SO_TYPE);
check_constants_manually!("SOCK_CLOEXEC", sys::O_CLOEXEC, libc::SOCK_CLOEXEC);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(INET_ADDRSTRLEN);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(TCP_NODELAY);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(TCP_KEEPIDLE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(TCP_KEEPINTVL);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(TCP_KEEPCNT);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_TOS);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_TTL);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_MULTICAST_IF);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_MULTICAST_TTL);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_MULTICAST_LOOP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_ADD_MEMBERSHIP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IP_DROP_MEMBERSHIP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_UNICAST_HOPS);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_MULTICAST_IF);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_MULTICAST_HOPS);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_MULTICAST_LOOP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_V6ONLY);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_JOIN_GROUP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_LEAVE_GROUP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_ADD_MEMBERSHIP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPV6_DROP_MEMBERSHIP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(HOST_NOT_FOUND);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NO_DATA);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NO_RECOVERY);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(TRY_AGAIN);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AI_PASSIVE);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AI_CANONNAME);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AI_NUMERICHOST);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AI_NUMERICSERV);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(AI_ADDRCONFIG);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NI_MAXHOST);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NI_MAXSERV);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NI_NUMERICSERV);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(NI_DGRAM);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(EAI_FAMILY);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(EAI_MEMORY);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(EAI_NONAME);
check_constants!(EAI_SOCKTYPE);
check_constants!(EXIT_SUCCESS);
check_constants!(EXIT_FAILURE);
check_types!(intmax_t);
check_types!(uintmax_t);
check_types!(pid_t);
check_types!(in_addr_t);
check_types!(in_port_t);
#[cfg(not(esp_idf_version_at_least_6_0_0))]
check_types!(cc_t);
check_types!(uid_t);
check_types!(gid_t);
check_types!(locale_t);
check_types!(utimbuf);
check_types!(timeval);
check_types!(timespec);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(ipv6_mreq);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(hostent);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(iovec);
check_types!(pollfd);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(linger);
#[cfg(not(esp_idf_libc_picolibc))]
check_types!(sigval);
check_types!(itimerval);
#[cfg(esp_idf_comp_lwip_enabled)]
check_types!(in6_addr);
check_constants!(DT_UNKNOWN);
#[cfg(all(esp_idf_libc_picolibc, esp_idf_version_at_least_6_0_0))]
check_constants!(DT_BLK);
#[cfg(all(esp_idf_libc_picolibc, esp_idf_version_at_least_6_0_0))]
check_constants!(DT_LNK);
#[cfg(all(esp_idf_libc_picolibc, esp_idf_version_at_least_6_0_0))]
check_constants!(DT_SOCK);
check_constants!(FD_CLOEXEC);
#[cfg(not(esp_idf_libc_picolibc))]
check_constants!(SIGIOT);
check_constants!(S_ISUID);
check_constants!(S_ISGID);
check_constants!(S_ISVTX);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_ICMP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_ICMPV6);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_TCP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_UDP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_IP);
#[cfg(esp_idf_comp_lwip_enabled)]
check_constants!(IPPROTO_IPV6);
check_constants!(STDIN_FILENO);
check_constants!(STDOUT_FILENO);
check_constants!(STDERR_FILENO);