Skip to content

Commit

Permalink
Merge pull request #450 from saethlin/remove-libc
Browse files Browse the repository at this point in the history
Tidy up beneath-std, support Windows-MSVC without libc
  • Loading branch information
ehuss committed Jun 5, 2024
2 parents 0d5f884 + 462ac2d commit 0ebdaca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/beneath-std.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Note that the default features have been disabled. This is a critical step -
disabled.**

Alternatively, we can use the unstable `rustc_private` private feature together
with an `extern crate libc;` declaration as shown in the examples below.
with an `extern crate libc;` declaration as shown in the examples below. Note that
windows-msvc targets do not require a libc, and correspondingly there is no `libc`
crate in their sysroot. We do not need the `extern crate libc;` below, and having it
on a windows-msvc target would be a compile error.

## Writing an executable without `std`

Expand All @@ -39,11 +42,12 @@ in the same format as C (aside from the exact integer types being used):
#![allow(internal_features)]
#![no_std]

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

// Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc;

use core::panic::PanicInfo;
Expand Down Expand Up @@ -73,11 +77,12 @@ compiler's name mangling too:
#![no_std]
#![no_main]

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

// Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc;

use core::ffi::{c_char, c_int};
Expand Down

0 comments on commit 0ebdaca

Please sign in to comment.