From 145ecb73d2cc47a48f16912744fe5774c32ba4de Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Thu, 4 Jun 2026 10:35:02 +0200 Subject: [PATCH] refactor: fix definition of file types in emcc The definitions for types that were made available under the LFS64 spec were being exposed even when the right feature test macro for that is now `FILE_OFFSET_BITS64`. This has been patched by deprecating the current definition when building without the existing `gnu_file_offset_bits64` `cfg` option. Even though the definitions are exposed when both the afore mentioned macro and the `_GNU_SOURCE` macro are defined, no `cfg` has been added for the latter. --- libc-test/semver/emscripten.txt | 1 - src/unix/linux_like/emscripten/mod.rs | 70 ++++++++++++++++++++++----- src/unix/linux_like/mod.rs | 1 + 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/libc-test/semver/emscripten.txt b/libc-test/semver/emscripten.txt index dc9e6b4f3b52d..48559aa89bdc3 100644 --- a/libc-test/semver/emscripten.txt +++ b/libc-test/semver/emscripten.txt @@ -6,4 +6,3 @@ getgrnam getgrnam_r getpwnam_r getpwuid_r -posix_fallocate64 diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 128025d813789..390f7c02084d5 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -28,19 +28,48 @@ pub type fsfilcnt_t = u32; pub type rlim_t = u64; pub type nlink_t = u32; -pub type ino64_t = crate::ino_t; -pub type off64_t = off_t; -pub type blkcnt64_t = crate::blkcnt_t; -pub type rlim64_t = crate::rlim_t; - -pub type rlimit64 = crate::rlimit; -pub type flock64 = crate::flock; -pub type stat64 = crate::stat; -pub type statfs64 = crate::statfs; -pub type statvfs64 = crate::statvfs; -pub type dirent64 = crate::dirent; +macro_rules! deprecate_lfs64 { + ($($it:item)+) => { + $( + #[cfg_attr( + not(gnu_file_offset_bits64), + deprecated( + since = "0.2.187", + note = "Use the unsuffixed variant instead. This type is meant to provide an \ + LFS64-compliant interface that was once exposed through \ + `_LARGEFIL64_SOURCE` but is currently exposed through \ + `FILE_OFFSET_BITS=64`", + ) + )] + $it + )+ + }; +} + +deprecate_lfs64! { + pub type ino64_t = ino_t; + pub type off64_t = off_t; + pub type blkcnt64_t = crate::blkcnt_t; + pub type rlim64_t = crate::rlim_t; + + pub type rlimit64 = crate::rlimit; + pub type flock64 = crate::flock; + pub type stat64 = crate::stat; + pub type statfs64 = crate::statfs; + pub type statvfs64 = crate::statvfs; + pub type dirent64 = crate::dirent; +} extern_ty! { + #[cfg_attr( + not(gnu_file_offset_bits64), + deprecated( + since = "0.2.187", + note = "Use `fpos_t`. This type is meant to provide a suffixed 64-bit alternative for \ + 32-bit systems where handling files larger than 2 GiB is not possible without \ + compatibility shims." + ) + )] pub enum fpos64_t {} // FIXME(emscripten): fill this out with a struct } @@ -1456,5 +1485,24 @@ extern "C" { } // Alias to 64 to mimic glibc's LFS64 support +#[cfg(not(gnu_file_offset_bits64))] +#[allow(deprecated)] +#[deprecated( + since = "0.2.187", + note = "This module was previously accessed by any emscripten user, but that is only \ + possible when the `_GNU_SOURCE` and `_LARGEFILE64_SOURCE` feature test macros are \ + defined. Note the latter is deprecated and instead should be issued to this crate \ + with the `gnu_file_offset_bits64` `cfg` option." +)] mod lfs64; + +#[cfg(not(gnu_file_offset_bits64))] +#[allow(deprecated)] +#[deprecated( + since = "0.2.187", + note = "This module was previously accessed by any emscripten user, but that is only \ + possible when the `_GNU_SOURCE` and `_LARGEFILE64_SOURCE` feature test macros are \ + defined. Note the latter is deprecated and instead should be issued to this crate \ + with the `gnu_file_offset_bits64` `cfg` option." +)] pub use self::lfs64::*; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 172e44111e455..60cbb45c8eafe 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -533,6 +533,7 @@ cfg_if! { if #[cfg(target_os = "android")] { pub const RLIM64_INFINITY: c_ulonglong = !0; } else { + #[cfg_attr(target_os = "emscripten", allow(deprecated))] pub const RLIM64_INFINITY: crate::rlim64_t = !0; } }