Skip to content

Commit d0c3daf

Browse files
ivmarkovivmarkov
authored andcommitted
STD support for the ESP-IDF framework
1 parent 896da0b commit d0c3daf

File tree

25 files changed

+540
-45
lines changed

25 files changed

+540
-45
lines changed

panic_unwind/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cfg_if::cfg_if! {
4545
} else if #[cfg(any(
4646
all(target_family = "windows", target_env = "gnu"),
4747
target_os = "psp",
48-
target_family = "unix",
48+
all(target_family = "unix", not(target_os = "espidf")),
4949
all(target_vendor = "fortanix", target_env = "sgx"),
5050
))] {
5151
// Rust runtime's startup objects depend on these symbols, so make them public.
@@ -58,6 +58,7 @@ cfg_if::cfg_if! {
5858
// - arch=wasm32
5959
// - os=none ("bare metal" targets)
6060
// - os=uefi
61+
// - os=espidf
6162
// - nvptx64-nvidia-cuda
6263
// - arch=avr
6364
#[path = "dummy.rs"]

std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1515
panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
18-
libc = { version = "0.2.98", default-features = false, features = ['rustc-dep-of-std'] }
18+
libc = { version = "0.2.99", default-features = false, features = ['rustc-dep-of-std'] }
1919
compiler_builtins = { version = "0.1.44" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }

std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn main() {
2626
|| target.contains("vxworks")
2727
|| target.contains("wasm32")
2828
|| target.contains("asmjs")
29+
|| target.contains("espidf")
2930
{
3031
// These platforms don't have any special requirements.
3132
} else {

std/src/os/espidf/fs.rs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::Metadata;
4+
use crate::sys_common::AsInner;
5+
6+
#[allow(deprecated)]
7+
use crate::os::espidf::raw;
8+
9+
/// OS-specific extensions to [`fs::Metadata`].
10+
///
11+
/// [`fs::Metadata`]: crate::fs::Metadata
12+
#[stable(feature = "metadata_ext", since = "1.1.0")]
13+
pub trait MetadataExt {
14+
#[stable(feature = "metadata_ext", since = "1.1.0")]
15+
#[rustc_deprecated(
16+
since = "1.8.0",
17+
reason = "deprecated in favor of the accessor \
18+
methods of this trait"
19+
)]
20+
#[allow(deprecated)]
21+
fn as_raw_stat(&self) -> &raw::stat;
22+
23+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
24+
fn st_dev(&self) -> u64;
25+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
26+
fn st_ino(&self) -> u64;
27+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
28+
fn st_mode(&self) -> u32;
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_nlink(&self) -> u64;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_uid(&self) -> u32;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_gid(&self) -> u32;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_rdev(&self) -> u64;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_size(&self) -> u64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_atime(&self) -> i64;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_atime_nsec(&self) -> i64;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_mtime(&self) -> i64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_mtime_nsec(&self) -> i64;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_ctime(&self) -> i64;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_ctime_nsec(&self) -> i64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_blksize(&self) -> u64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_blocks(&self) -> u64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_spare4(&self) -> [u32; 2];
57+
}
58+
59+
#[stable(feature = "metadata_ext", since = "1.1.0")]
60+
impl MetadataExt for Metadata {
61+
#[allow(deprecated)]
62+
fn as_raw_stat(&self) -> &raw::stat {
63+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
64+
}
65+
fn st_dev(&self) -> u64 {
66+
self.as_inner().as_inner().st_dev as u64
67+
}
68+
fn st_ino(&self) -> u64 {
69+
self.as_inner().as_inner().st_ino as u64
70+
}
71+
fn st_mode(&self) -> u32 {
72+
self.as_inner().as_inner().st_mode as u32
73+
}
74+
fn st_nlink(&self) -> u64 {
75+
self.as_inner().as_inner().st_nlink as u64
76+
}
77+
fn st_uid(&self) -> u32 {
78+
self.as_inner().as_inner().st_uid as u32
79+
}
80+
fn st_gid(&self) -> u32 {
81+
self.as_inner().as_inner().st_gid as u32
82+
}
83+
fn st_rdev(&self) -> u64 {
84+
self.as_inner().as_inner().st_rdev as u64
85+
}
86+
fn st_size(&self) -> u64 {
87+
self.as_inner().as_inner().st_size as u64
88+
}
89+
fn st_atime(&self) -> i64 {
90+
self.as_inner().as_inner().st_atime as i64
91+
}
92+
fn st_atime_nsec(&self) -> i64 {
93+
0
94+
}
95+
fn st_mtime(&self) -> i64 {
96+
self.as_inner().as_inner().st_mtime as i64
97+
}
98+
fn st_mtime_nsec(&self) -> i64 {
99+
0
100+
}
101+
fn st_ctime(&self) -> i64 {
102+
self.as_inner().as_inner().st_ctime as i64
103+
}
104+
fn st_ctime_nsec(&self) -> i64 {
105+
0
106+
}
107+
fn st_blksize(&self) -> u64 {
108+
self.as_inner().as_inner().st_blksize as u64
109+
}
110+
fn st_blocks(&self) -> u64 {
111+
self.as_inner().as_inner().st_blocks as u64
112+
}
113+
fn st_spare4(&self) -> [u32; 2] {
114+
let spare4 = self.as_inner().as_inner().st_spare4;
115+
[spare4[0] as u32, spare4[1] as u32]
116+
}
117+
}

std/src/os/espidf/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Definitions for the ESP-IDF framework.
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
5+
pub mod fs;
6+
pub mod raw;

std/src/os/espidf/raw.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//! Raw type definitions for the ESP-IDF framework.
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![rustc_deprecated(
5+
since = "1.8.0",
6+
reason = "these type aliases are no longer supported by \
7+
the standard library, the `libc` crate on \
8+
crates.io should be used instead for the correct \
9+
definitions"
10+
)]
11+
12+
use crate::os::raw::c_long;
13+
use crate::os::unix::raw::{gid_t, uid_t};
14+
15+
#[stable(feature = "pthread_t", since = "1.8.0")]
16+
pub type pthread_t = libc::pthread_t;
17+
18+
#[stable(feature = "raw_ext", since = "1.1.0")]
19+
pub type blkcnt_t = libc::blkcnt_t;
20+
21+
#[stable(feature = "raw_ext", since = "1.1.0")]
22+
pub type blksize_t = libc::blksize_t;
23+
#[stable(feature = "raw_ext", since = "1.1.0")]
24+
pub type dev_t = libc::dev_t;
25+
#[stable(feature = "raw_ext", since = "1.1.0")]
26+
pub type ino_t = libc::ino_t;
27+
#[stable(feature = "raw_ext", since = "1.1.0")]
28+
pub type mode_t = libc::mode_t;
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
30+
pub type nlink_t = libc::nlink_t;
31+
#[stable(feature = "raw_ext", since = "1.1.0")]
32+
pub type off_t = libc::off_t;
33+
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
35+
pub type time_t = libc::time_t;
36+
37+
#[repr(C)]
38+
#[derive(Clone)]
39+
#[stable(feature = "raw_ext", since = "1.1.0")]
40+
pub struct stat {
41+
#[stable(feature = "raw_ext", since = "1.1.0")]
42+
pub st_dev: dev_t,
43+
#[stable(feature = "raw_ext", since = "1.1.0")]
44+
pub st_ino: ino_t,
45+
#[stable(feature = "raw_ext", since = "1.1.0")]
46+
pub st_mode: mode_t,
47+
#[stable(feature = "raw_ext", since = "1.1.0")]
48+
pub st_nlink: nlink_t,
49+
#[stable(feature = "raw_ext", since = "1.1.0")]
50+
pub st_uid: uid_t,
51+
#[stable(feature = "raw_ext", since = "1.1.0")]
52+
pub st_gid: gid_t,
53+
#[stable(feature = "raw_ext", since = "1.1.0")]
54+
pub st_rdev: dev_t,
55+
#[stable(feature = "raw_ext", since = "1.1.0")]
56+
pub st_size: off_t,
57+
#[stable(feature = "raw_ext", since = "1.1.0")]
58+
pub st_atime: time_t,
59+
#[stable(feature = "raw_ext", since = "1.1.0")]
60+
pub st_mtime: time_t,
61+
#[stable(feature = "raw_ext", since = "1.1.0")]
62+
pub st_ctime: time_t,
63+
#[stable(feature = "raw_ext", since = "1.1.0")]
64+
pub st_blksize: blksize_t,
65+
#[stable(feature = "raw_ext", since = "1.1.0")]
66+
pub st_blocks: blkcnt_t,
67+
#[stable(feature = "raw_ext", since = "1.1.0")]
68+
pub st_spare4: [c_long; 2usize],
69+
}

std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ mod imp {
8080
pub mod dragonfly;
8181
#[cfg(target_os = "emscripten")]
8282
pub mod emscripten;
83+
#[cfg(target_os = "espidf")]
84+
pub mod espidf;
8385
#[cfg(target_os = "freebsd")]
8486
pub mod freebsd;
8587
#[cfg(target_os = "fuchsia")]

std/src/os/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ mod platform {
4040
pub use crate::os::dragonfly::*;
4141
#[cfg(target_os = "emscripten")]
4242
pub use crate::os::emscripten::*;
43+
#[cfg(target_os = "espidf")]
44+
pub use crate::os::espidf::*;
4345
#[cfg(target_os = "freebsd")]
4446
pub use crate::os::freebsd::*;
4547
#[cfg(target_os = "fuchsia")]

std/src/sys/common/alloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::ptr;
1414
target_arch = "asmjs",
1515
target_arch = "wasm32",
1616
target_arch = "hexagon",
17-
target_arch = "riscv32"
17+
target_arch = "riscv32",
18+
target_arch = "xtensa"
1819
)))]
1920
pub const MIN_ALIGN: usize = 8;
2021
#[cfg(all(any(

std/src/sys/unix/alloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ cfg_if::cfg_if! {
5757
target_os = "android",
5858
target_os = "illumos",
5959
target_os = "redox",
60-
target_os = "solaris"
60+
target_os = "solaris",
61+
target_os = "espidf"
6162
))] {
6263
#[inline]
6364
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {

0 commit comments

Comments
 (0)