Skip to content

Commit

Permalink
Remove libc from beneath-std, it's not actually required anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed May 15, 2024
1 parent 0d5f884 commit cc25bc5
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/beneath-std.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ This section documents features that are normally provided by the `std` crate an
that `#![no_std]` developers have to deal with (i.e. provide) to build
`#![no_std]` binary crates.

## Using `libc`

In order to build a `#[no_std]` executable we will need `libc` as a dependency.
We can specify this using our `Cargo.toml` file:

```toml
[dependencies]
libc = { version = "0.2.146", default-features = false }
```

Note that the default features have been disabled. This is a critical step -
**the default features of `libc` include the `std` crate and so must be
disabled.**

Alternatively, we can use the unstable `rustc_private` private feature together
with an `extern crate libc;` declaration as shown in the examples below.

## Writing an executable without `std`

We will probably need a nightly version of the compiler to produce
Expand All @@ -35,17 +18,14 @@ The function marked `#[start]` is passed the command line parameters
in the same format as C (aside from the exact integer types being used):

```rust
#![feature(start, lang_items, core_intrinsics, rustc_private)]
#![feature(start, lang_items, core_intrinsics)]
#![allow(internal_features)]
#![no_std]

// Necessary for `panic = "unwind"` builds on some platforms.
#![feature(panic_unwind)]
extern crate unwind;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;

use core::panic::PanicInfo;

// Entry point for this program.
Expand All @@ -68,7 +48,7 @@ correct ABI and the correct name, which requires overriding the
compiler's name mangling too:

```rust
#![feature(lang_items, core_intrinsics, rustc_private)]
#![feature(lang_items, core_intrinsics)]
#![allow(internal_features)]
#![no_std]
#![no_main]
Expand All @@ -77,9 +57,6 @@ compiler's name mangling too:
#![feature(panic_unwind)]
extern crate unwind;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;

use core::ffi::{c_char, c_int};
use core::panic::PanicInfo;

Expand Down

0 comments on commit cc25bc5

Please sign in to comment.