Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ enum Cfg {
LibcPauthtest,

EmscriptenOldStatAbi,
EmscriptenFsblkcntIs32bit,
EmscriptenSigsetLarge,
EmscriptenNfdsIsULong,

/// Should be enabled by users if esp-idf (>=6.0) is build with picolibc instead of newlib. Not
/// set by `libc` itself.
Expand Down Expand Up @@ -63,6 +66,9 @@ enum Cfg {
const ALLOWED_CFGS: &[Cfg] = &[
Cfg::LibcDenyWarnings,
Cfg::EmscriptenOldStatAbi,
Cfg::EmscriptenFsblkcntIs32bit,
Cfg::EmscriptenSigsetLarge,
Cfg::EmscriptenNfdsIsULong,
Cfg::EspidfPicolibc,
Cfg::EspidfTime32,
Cfg::Freebsd10,
Expand All @@ -88,6 +94,9 @@ impl fmt::Display for Cfg {
f.write_str(match self {
Cfg::LibcDenyWarnings => "libc_deny_warnings",
Cfg::EmscriptenOldStatAbi => "emscripten_old_stat_abi",
Cfg::EmscriptenFsblkcntIs32bit => "emscripten_fsblkcnt_is_32bit",
Cfg::EmscriptenSigsetLarge => "emscripten_sigset_large",
Cfg::EmscriptenNfdsIsULong => "emscripten_nfds_is_ulong",
Cfg::EspidfPicolibc => "espidf_picolibc",
Cfg::EspidfTime32 => "espidf_time32",
Cfg::Freebsd10 => "freebsd10",
Expand Down Expand Up @@ -214,10 +223,23 @@ fn main() {
}

if target_os == "emscripten" {
match emcc_version_code() {
Some(v) if (v < 30142) => cfgs.push(Cfg::EmscriptenOldStatAbi),
// Non-Emscripten or version >= 3.1.42.
_ => (),
if let Some(v) = emcc_version_code() {
// 3.1.42

@hoodmane hoodmane Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimum supported version is 4.0.0 so let's drop this.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But minimum supported version is only very recently v4.0.0, whereas libc can still be used with lower MSRV?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not much code to keep so if there's a reason then it's probably fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty small so we may as well keep it around for now. Could we document the versions we support at https://doc.rust-lang.org/beta/rustc/platform-support/wasm32-unknown-emscripten.html?

@madsmtm madsmtm Oct 10, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh why do I always wind up on the beta version of those pages, thanks for the link

if v < 30142 {
cfgs.push(Cfg::EmscriptenOldStatAbi);
}
// 4.0.12
if v < 40012 {
cfgs.push(Cfg::EmscriptenFsblkcntIs32bit);
}
// 5.0.5
if v < 50005 {
cfgs.push(Cfg::EmscriptenSigsetLarge);
}
// 6.0.1
if v < 60001 {
cfgs.push(Cfg::EmscriptenNfdsIsULong);
}
}
}

Expand Down Expand Up @@ -452,7 +474,10 @@ fn validate_cfg(list: &[Cfg], target_env: &str, target_os: &str, target_ptr_widt
Cfg::EspidfPicolibc => (),
Cfg::EspidfTime32 => (),

Cfg::EmscriptenOldStatAbi => {
Cfg::EmscriptenOldStatAbi
| Cfg::EmscriptenFsblkcntIs32bit
| Cfg::EmscriptenSigsetLarge
| Cfg::EmscriptenNfdsIsULong => {
assert_eq!(
target_os, "emscripten",
"{cfg:?} set on non-freebsd platform"
Expand Down
2 changes: 1 addition & 1 deletion ci/emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eux

# Note: keep in sync with:
# https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-unknown-emscripten.md#requirements
emsdk_version=3.1.68
emsdk_version=6.0.11

@madsmtm madsmtm Oct 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should test a range of emscripten versions, though I'm unsure how we'd go about doing that?

WDYT @tgross35?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't hurt but I also wouldn't prioritize it, hopefully any ABI breaks continue to be small.


git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
cd /emsdk-portable
Expand Down
10 changes: 5 additions & 5 deletions libc-test/tests/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ mod t {
use libc::{
self,
c_uchar,
c_uint,
c_void,
cmsghdr,
msghdr,
size_t,
};

extern "C" {
pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr;
pub fn cmsg_nxthdr(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
pub fn cmsg_space(length: c_uint) -> usize;
pub fn cmsg_len(length: c_uint) -> usize;
pub fn cmsg_space(length: size_t) -> size_t;
pub fn cmsg_len(length: size_t) -> size_t;
pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar;
}

Expand Down Expand Up @@ -51,7 +51,7 @@ mod t {
fn test_cmsg_len() {
for l in 0..128 {
unsafe {
assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l));
assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l as usize));
}
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ mod t {
fn test_cmsg_space() {
unsafe {
for l in 0..128 {
assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l));
assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l as usize));
}
}
}
Expand Down
25 changes: 22 additions & 3 deletions src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ pub type shmatt_t = c_ulong;
pub type mqd_t = c_int;
pub type msgqnum_t = c_ulong;
pub type msglen_t = c_ulong;
// nfds_t is 32-bit on wasm64 since 6.0.1:
// https://github.com/emscripten-core/emscripten/pull/27115
#[cfg(not(emscripten_nfds_is_ulong))]
pub type nfds_t = c_uint;
#[cfg(emscripten_nfds_is_ulong)]
pub type nfds_t = c_ulong;
pub type nl_item = c_int;
pub type idtype_t = c_uint;
Expand All @@ -23,8 +28,17 @@ pub type off_t = i64;
pub type blkcnt_t = i32;

pub type blksize_t = c_long;
pub type fsblkcnt_t = u32;
pub type fsfilcnt_t = u32;
cfg_if! {
// `fsblkcnt_t` and `fsfilcnt_t` are 64-bit since v4.0.12, see:
// https://github.com/emscripten-core/emscripten/pull/24769
if #[cfg(not(emscripten_fsblkcnt_is_32bit))] {
pub type fsblkcnt_t = u64;
pub type fsfilcnt_t = u64;
} else {
pub type fsblkcnt_t = u32;
pub type fsfilcnt_t = u32;
}
}
pub type rlim_t = u64;
pub type nlink_t = u32;

Expand Down Expand Up @@ -212,7 +226,12 @@ s! {
}

pub struct sigset_t {
__val: [c_ulong; 32],
// sigset_t is smaller since Emscripten v5.0.5:
// https://github.com/emscripten-core/emscripten/pull/26574
#[cfg(not(emscripten_sigset_large))]
__val: [c_ulong; 2],
#[cfg(emscripten_sigset_large)]
__val: [c_ulong; 128 / size_of::<c_long>()],
}

pub struct msghdr {
Expand Down