Skip to content

Commit dc4254e

Browse files
committed
Make libstd compile.
1 parent bc0e24c commit dc4254e

37 files changed

+3244
-94
lines changed

compiler/rustc_target/src/spec/xtensa_esp32_none_elf.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ pub fn target() -> Target {
1010
options: TargetOptions {
1111
endian: "little".to_string(),
1212
c_int_width: "32".to_string(),
13-
os: "none".to_string(),
14-
env: String::new(),
15-
vendor: String::new(),
13+
os: "freertos".to_string(),
14+
target_family: Some("unix".to_string()),
15+
env: "newlib".to_string(),
16+
vendor: "espressif".to_string(),
1617
linker_flavor: LinkerFlavor::Gcc,
1718

1819
executables: true,
1920
cpu: "esp32".to_string(),
2021
linker: Some("xtensa-esp32-elf-gcc".to_string()),
22+
linker_is_gnu: true,
2123

2224
max_atomic_width: Some(32),
2325

compiler/rustc_target/src/spec/xtensa_esp8266_none_elf.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ pub fn target() -> Target {
1010
options: TargetOptions {
1111
endian: "little".to_string(),
1212
c_int_width: "32".to_string(),
13-
os: "none".to_string(),
14-
env: String::new(),
15-
vendor: String::new(),
13+
os: "freertos".to_string(),
14+
target_family: Some("unix".to_string()),
15+
env: "newlib".to_string(),
16+
vendor: "espressif".to_string(),
1617
linker_flavor: LinkerFlavor::Gcc,
1718

1819
executables: true,
1920
cpu: "esp8266".to_string(),
2021
linker: Some("xtensa-lx106-elf-gcc".to_string()),
22+
linker_is_gnu: true,
2123

2224
max_atomic_width: Some(32),
2325

library/panic_unwind/src/gcc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const UNWIND_DATA_REG: (i32, i32) = (0, 1); // R0, R1
123123
#[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
124124
const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11
125125

126+
#[cfg(target_arch = "xtensa")]
127+
const UNWIND_DATA_REG: (i32, i32) = (2, 3); // A2, A3
128+
126129
// The following code is based on GCC's C and C++ personality routines. For reference, see:
127130
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
128131
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

library/std/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ fn main() {
2828
|| target.contains("asmjs")
2929
{
3030
// These platforms don't have any special requirements.
31+
} else if target.contains("esp32") {
32+
println!(r#"cargo:rustc-cfg=target_device="esp32""#);
33+
} else if target.contains("esp8266") {
34+
println!(r#"cargo:rustc-cfg=target_device="esp8266""#);
3135
} else {
3236
// This is for Cargo's build-std support, to mark std as unstable for
3337
// typically no_std platforms.

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
#![feature(into_future)]
276276
#![feature(lang_items)]
277277
#![feature(link_args)]
278+
#![feature(linked_list_remove)]
278279
#![feature(linkage)]
279280
#![feature(llvm_asm)]
280281
#![feature(log_syntax)]

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#![stable(feature = "metadata_ext", since = "1.1.0")]
2+
3+
use crate::fs::Metadata;
4+
use crate::sys_common::AsInner;
5+
6+
/// OS-specific extensions to [`fs::Metadata`].
7+
///
8+
/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
9+
#[stable(feature = "metadata_ext", since = "1.1.0")]
10+
pub trait MetadataExt {
11+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
12+
fn st_dev(&self) -> u64;
13+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
14+
fn st_ino(&self) -> u64;
15+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
16+
fn st_mode(&self) -> u32;
17+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
18+
fn st_nlink(&self) -> u64;
19+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
20+
fn st_uid(&self) -> u32;
21+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
22+
fn st_gid(&self) -> u32;
23+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
24+
fn st_rdev(&self) -> u64;
25+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
26+
fn st_size(&self) -> u64;
27+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
28+
fn st_atime(&self) -> i64;
29+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
30+
fn st_atime_nsec(&self) -> i64;
31+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
32+
fn st_mtime(&self) -> i64;
33+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
34+
fn st_mtime_nsec(&self) -> i64;
35+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
36+
fn st_ctime(&self) -> i64;
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_ctime_nsec(&self) -> i64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_blksize(&self) -> u64;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_blocks(&self) -> u64;
43+
}
44+
45+
#[stable(feature = "metadata_ext", since = "1.1.0")]
46+
impl MetadataExt for Metadata {
47+
fn st_dev(&self) -> u64 {
48+
self.as_inner().as_inner().st_dev as u64
49+
}
50+
fn st_ino(&self) -> u64 {
51+
self.as_inner().as_inner().st_ino as u64
52+
}
53+
fn st_mode(&self) -> u32 {
54+
self.as_inner().as_inner().st_mode as u32
55+
}
56+
fn st_nlink(&self) -> u64 {
57+
self.as_inner().as_inner().st_nlink as u64
58+
}
59+
fn st_uid(&self) -> u32 {
60+
self.as_inner().as_inner().st_uid as u32
61+
}
62+
fn st_gid(&self) -> u32 {
63+
self.as_inner().as_inner().st_gid as u32
64+
}
65+
fn st_rdev(&self) -> u64 {
66+
self.as_inner().as_inner().st_rdev as u64
67+
}
68+
fn st_size(&self) -> u64 {
69+
self.as_inner().as_inner().st_size as u64
70+
}
71+
fn st_atime(&self) -> i64 {
72+
self.as_inner().as_inner().st_atime as i64
73+
}
74+
fn st_atime_nsec(&self) -> i64 {
75+
0
76+
}
77+
fn st_mtime(&self) -> i64 {
78+
self.as_inner().as_inner().st_mtime as i64
79+
}
80+
fn st_mtime_nsec(&self) -> i64 {
81+
0
82+
}
83+
fn st_ctime(&self) -> i64 {
84+
self.as_inner().as_inner().st_ctime as i64
85+
}
86+
fn st_ctime_nsec(&self) -> i64 {
87+
0
88+
}
89+
fn st_blksize(&self) -> u64 {
90+
self.as_inner().as_inner().st_blksize as u64
91+
}
92+
fn st_blocks(&self) -> u64 {
93+
self.as_inner().as_inner().st_blocks as u64
94+
}
95+
}

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

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! FreeRTOS-specific raw type definitions
2+
3+
#![stable(feature = "raw_ext", since = "1.1.0")]
4+
#![rustc_deprecated(since = "1.8.0",
5+
reason = "these type aliases are no longer supported by \
6+
the standard library, the `libc` crate on \
7+
crates.io should be used instead for the correct \
8+
definitions")]
9+
#![allow(deprecated)]
10+
#![allow(missing_debug_implementations)]
11+
12+
#[stable(feature = "pthread_t", since = "1.8.0")]
13+
pub use libc::pthread_t;
14+
15+
#[doc(inline)]
16+
#[stable(feature = "raw_ext", since = "1.1.0")]
17+
pub use libc::{dev_t, mode_t, off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub mod emscripten;
4848
pub mod fortanix_sgx;
4949
#[cfg(target_os = "freebsd")]
5050
pub mod freebsd;
51+
#[cfg(target_os = "freertos")]
52+
pub mod freertos;
5153
#[cfg(target_os = "fuchsia")]
5254
pub mod fuchsia;
5355
#[cfg(target_os = "haiku")]

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ unsafe impl GlobalAlloc for System {
5353
}
5454

5555
cfg_if::cfg_if! {
56-
if #[cfg(any(
56+
if #[cfg(target_os = "freertos")] {
57+
#[inline]
58+
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
59+
libc::malloc(layout.size()) as *mut u8
60+
}
61+
} else if #[cfg(any(
5762
target_os = "android",
5863
target_os = "illumos",
5964
target_os = "redox",

0 commit comments

Comments
 (0)