Skip to content

Commit 8fc1989

Browse files
imarkovMabezDev
imarkov
authored andcommitted
STD support for the ESP-IDF framework
1 parent 8c4feaf commit 8fc1989

File tree

31 files changed

+1116
-495
lines changed

31 files changed

+1116
-495
lines changed

Cargo.lock

Lines changed: 505 additions & 446 deletions
Large diffs are not rendered by default.

compiler/rustc_mir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ doctest = false
1010
[dependencies]
1111
either = "1.5.0"
1212
rustc_graphviz = { path = "../rustc_graphviz" }
13-
gsgdt = "0.1.2"
13+
gsgdt = "=0.1.2"
1414
itertools = "0.9"
1515
tracing = "0.1"
1616
polonius-engine = "0.12.0"

library/panic_abort/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ doc = false
1616
alloc = { path = "../alloc" }
1717
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1818
core = { path = "../core" }
19-
libc = { git = "https://github.com/ivmarkov/libc.git", default-features = false }
19+
libc = { git = "https://github.com/rust-lang/libc.git", default-features = false }
2020
compiler_builtins = "0.1.0"

library/panic_unwind/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ doc = false
1515
[dependencies]
1616
alloc = { path = "../alloc" }
1717
core = { path = "../core" }
18-
libc = { git = "https://github.com/ivmarkov/libc.git", default-features = false }
18+
libc = { git = "https://github.com/rust-lang/libc.git", default-features = false }
1919
unwind = { path = "../unwind" }
2020
compiler_builtins = "0.1.0"
2121
cfg-if = "0.1.8"

library/panic_unwind/src/lib.rs

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

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1616
panic_unwind = { path = "../panic_unwind", optional = true }
1717
panic_abort = { path = "../panic_abort" }
1818
core = { path = "../core" }
19-
libc = { git = "https://github.com/ivmarkov/libc.git", default-features = false, features = ['rustc-dep-of-std'] }
19+
libc = { git = "https://github.com/rust-lang/libc.git", default-features = false, features = ['rustc-dep-of-std'] }
2020
compiler_builtins = { version = "0.1.44" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }

library/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 {

library/std/src/os/espidf/fs.rs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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_crtime(&self) -> i64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_crtime_nsec(&self) -> i64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_blksize(&self) -> u64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_blocks(&self) -> u64;
59+
}
60+
61+
#[stable(feature = "metadata_ext", since = "1.1.0")]
62+
impl MetadataExt for Metadata {
63+
#[allow(deprecated)]
64+
fn as_raw_stat(&self) -> &raw::stat {
65+
unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) }
66+
}
67+
fn st_dev(&self) -> u64 {
68+
self.as_inner().as_inner().st_dev as u64
69+
}
70+
fn st_ino(&self) -> u64 {
71+
self.as_inner().as_inner().st_ino as u64
72+
}
73+
fn st_mode(&self) -> u32 {
74+
self.as_inner().as_inner().st_mode as u32
75+
}
76+
fn st_nlink(&self) -> u64 {
77+
self.as_inner().as_inner().st_nlink as u64
78+
}
79+
fn st_uid(&self) -> u32 {
80+
self.as_inner().as_inner().st_uid as u32
81+
}
82+
fn st_gid(&self) -> u32 {
83+
self.as_inner().as_inner().st_gid as u32
84+
}
85+
fn st_rdev(&self) -> u64 {
86+
self.as_inner().as_inner().st_rdev as u64
87+
}
88+
fn st_size(&self) -> u64 {
89+
self.as_inner().as_inner().st_size as u64
90+
}
91+
fn st_atime(&self) -> i64 {
92+
self.as_inner().as_inner().st_atime as i64
93+
}
94+
fn st_atime_nsec(&self) -> i64 {
95+
//self.as_inner().as_inner().st_atime_nsec as i64
96+
0
97+
}
98+
fn st_mtime(&self) -> i64 {
99+
self.as_inner().as_inner().st_mtime as i64
100+
}
101+
fn st_mtime_nsec(&self) -> i64 {
102+
//self.as_inner().as_inner().st_mtime_nsec as i64
103+
0
104+
}
105+
fn st_ctime(&self) -> i64 {
106+
self.as_inner().as_inner().st_ctime as i64
107+
}
108+
fn st_ctime_nsec(&self) -> i64 {
109+
//self.as_inner().as_inner().st_ctime_nsec as i64
110+
0
111+
}
112+
fn st_crtime(&self) -> i64 {
113+
//self.as_inner().as_inner().st_crtime as i64
114+
0
115+
}
116+
fn st_crtime_nsec(&self) -> i64 {
117+
//self.as_inner().as_inner().st_crtime_nsec as i64
118+
0
119+
}
120+
fn st_blksize(&self) -> u64 {
121+
self.as_inner().as_inner().st_blksize as u64
122+
}
123+
fn st_blocks(&self) -> u64 {
124+
self.as_inner().as_inner().st_blocks as u64
125+
}
126+
}

library/std/src/os/espidf/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Definitions for the ESP-IDF framework.
2+
3+
// FIXME: Figure out if these can be proclaimed as "stable" and if yes, since what version
4+
#![stable(feature = "raw_ext", since = "1.1.0")]
5+
6+
pub mod fs;
7+
pub mod raw;

library/std/src/os/espidf/raw.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//! Raw type definitions for the ESP-IDF framework.
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![allow(deprecated)]
5+
6+
use crate::os::raw::c_long;
7+
use crate::os::unix::raw::{gid_t, uid_t};
8+
9+
// Use the direct definition of usize, instead of uintptr_t like in libc
10+
#[stable(feature = "pthread_t", since = "1.8.0")]
11+
pub type pthread_t = libc::pthread_t;
12+
13+
#[stable(feature = "raw_ext", since = "1.1.0")]
14+
pub type blkcnt_t = libc::blkcnt_t;
15+
16+
#[stable(feature = "raw_ext", since = "1.1.0")]
17+
pub type blksize_t = libc::blksize_t;
18+
#[stable(feature = "raw_ext", since = "1.1.0")]
19+
pub type dev_t = libc::dev_t;
20+
#[stable(feature = "raw_ext", since = "1.1.0")]
21+
pub type ino_t = libc::ino_t;
22+
#[stable(feature = "raw_ext", since = "1.1.0")]
23+
pub type mode_t = libc::mode_t;
24+
#[stable(feature = "raw_ext", since = "1.1.0")]
25+
pub type nlink_t = libc::nlink_t;
26+
#[stable(feature = "raw_ext", since = "1.1.0")]
27+
pub type off_t = libc::off_t;
28+
29+
#[stable(feature = "raw_ext", since = "1.1.0")]
30+
pub type time_t = libc::time_t;
31+
32+
#[repr(C)]
33+
#[derive(Clone)]
34+
#[stable(feature = "raw_ext", since = "1.1.0")]
35+
pub struct stat {
36+
#[stable(feature = "raw_ext", since = "1.1.0")]
37+
pub st_dev: dev_t,
38+
#[stable(feature = "raw_ext", since = "1.1.0")]
39+
pub st_ino: ino_t,
40+
#[stable(feature = "raw_ext", since = "1.1.0")]
41+
pub st_mode: mode_t,
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
43+
pub st_nlink: nlink_t,
44+
#[stable(feature = "raw_ext", since = "1.1.0")]
45+
pub st_uid: uid_t,
46+
#[stable(feature = "raw_ext", since = "1.1.0")]
47+
pub st_gid: gid_t,
48+
#[stable(feature = "raw_ext", since = "1.1.0")]
49+
pub st_rdev: dev_t,
50+
#[stable(feature = "raw_ext", since = "1.1.0")]
51+
pub st_size: off_t,
52+
#[stable(feature = "raw_ext", since = "1.1.0")]
53+
pub st_atime: time_t,
54+
// #[stable(feature = "raw_ext", since = "1.1.0")]
55+
// pub st_atime_nsec: c_long,
56+
#[stable(feature = "raw_ext", since = "1.1.0")]
57+
pub st_mtime: time_t,
58+
// #[stable(feature = "raw_ext", since = "1.1.0")]
59+
// pub st_mtime_nsec: c_long,
60+
#[stable(feature = "raw_ext", since = "1.1.0")]
61+
pub st_ctime: time_t,
62+
// #[stable(feature = "raw_ext", since = "1.1.0")]
63+
// pub st_ctime_nsec: c_long,
64+
// #[stable(feature = "raw_ext", since = "1.1.0")]
65+
// pub st_crtime: time_t,
66+
// #[stable(feature = "raw_ext", since = "1.1.0")]
67+
// pub st_crtime_nsec: c_long,
68+
#[stable(feature = "raw_ext", since = "1.1.0")]
69+
pub st_blksize: blksize_t,
70+
#[stable(feature = "raw_ext", since = "1.1.0")]
71+
pub st_blocks: blkcnt_t,
72+
// #[stable(feature = "raw_ext", since = "1.1.0")]
73+
// pub st_type: u32,
74+
}

library/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")]

library/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")]

library/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(

library/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 {

library/std/src/sys/unix/args.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,18 @@ mod imp {
250250
Args { iter: res.into_iter() }
251251
}
252252
}
253+
254+
#[cfg(target_os = "espidf")]
255+
mod imp {
256+
use super::Args;
257+
258+
#[inline(always)]
259+
pub unsafe fn cleanup() {}
260+
261+
#[inline(always)]
262+
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
263+
264+
pub fn args() -> Args {
265+
Args { iter: Vec::new().into_iter() }
266+
}
267+
}

library/std/src/sys/unix/condvar.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ impl Condvar {
3434
))]
3535
pub unsafe fn init(&mut self) {}
3636

37+
// NOTE: ESP-IDF's PTHREAD_COND_INITIALIZER support is not released yet
38+
// So on that platform, init() should always be called
39+
// Moreover, that platform does not have pthread_condattr_setclock support,
40+
// hence that initialization should be skipped as well
41+
#[cfg(target_os = "espidf")]
42+
pub unsafe fn init(&mut self) {
43+
let r = libc::pthread_cond_init(self.inner.get(), crate::ptr::null());
44+
assert_eq!(r, 0);
45+
}
46+
3747
#[cfg(not(any(
3848
target_os = "macos",
3949
target_os = "ios",
4050
target_os = "l4re",
4151
target_os = "android",
42-
target_os = "redox"
52+
target_os = "redox",
53+
target_os = "espidf"
4354
)))]
4455
pub unsafe fn init(&mut self) {
4556
use crate::mem::MaybeUninit;
@@ -76,7 +87,12 @@ impl Condvar {
7687
// where we configure condition variable to use monotonic clock (instead of
7788
// default system clock). This approach avoids all problems that result
7889
// from changes made to the system time.
79-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
90+
#[cfg(not(any(
91+
target_os = "macos",
92+
target_os = "ios",
93+
target_os = "android",
94+
target_os = "espidf"
95+
)))]
8096
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
8197
use crate::mem;
8298

@@ -103,7 +119,12 @@ impl Condvar {
103119
// This implementation is modeled after libcxx's condition_variable
104120
// https://github.com/llvm-mirror/libcxx/blob/release_35/src/condition_variable.cpp#L46
105121
// https://github.com/llvm-mirror/libcxx/blob/release_35/include/__mutex_base#L367
106-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
122+
#[cfg(any(
123+
target_os = "macos",
124+
target_os = "ios",
125+
target_os = "android",
126+
target_os = "espidf"
127+
))]
107128
pub unsafe fn wait_timeout(&self, mutex: &Mutex, mut dur: Duration) -> bool {
108129
use crate::ptr;
109130
use crate::time::Instant;

library/std/src/sys/unix/env.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,14 @@ pub mod os {
184184
pub const EXE_SUFFIX: &str = "";
185185
pub const EXE_EXTENSION: &str = "";
186186
}
187+
188+
#[cfg(target_os = "espidf")]
189+
pub mod os {
190+
pub const FAMILY: &str = "unix";
191+
pub const OS: &str = "espidf";
192+
pub const DLL_PREFIX: &str = "lib";
193+
pub const DLL_SUFFIX: &str = ".so";
194+
pub const DLL_EXTENSION: &str = "so";
195+
pub const EXE_SUFFIX: &str = "";
196+
pub const EXE_EXTENSION: &str = "";
197+
}

0 commit comments

Comments
 (0)