Skip to content

Add new cfg gnu_file_offset_bits64 corresponding to _FILE_OFFSET_BITS=64 #4345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
afa5c65
ci: Use $PWD instead of $(pwd) in run-docker
snogge Dec 11, 2024
84a04a1
ci: Add matrix env variables to the environment
snogge Mar 14, 2025
f10e8e4
ci: Always upload successfully created artifacts
snogge Mar 14, 2025
a184436
gnu: build settings for _FILE_OFFSET_BITS=64
snogge Mar 14, 2025
874e399
gnu: Set up the CI for _FILE_OFFSET_BITS=64
snogge Mar 14, 2025
f44fdc1
gnu: Handle basic file types for 32bit with _FILE_OFFSET_BITS=64
snogge Dec 16, 2024
862ba8a
gnu: Update F_GETLK for gnu_file_offset_bits64
snogge Mar 20, 2023
6ed2bc8
gnu: Update F_SETLK and F_SETLKW for gnu_file_offset_bits64
snogge Mar 20, 2023
5c5c364
gnu: Set RLIM_INFINITY for mips with gnu_file_offset_bits64
snogge Mar 11, 2025
2b4fafb
gnu: Use _FILE_OFFSET_BITS=64 versions of glibc symbols
snogge Nov 21, 2024
0c6d56c
gnu powerpc: Use a separate stat struct for powerpc
snogge Mar 18, 2025
e134959
gnu sparc: Use a separate stat struct for 32bit powerpc
snogge Mar 20, 2025
5a5abc2
gnu: Adapt struct stat for gnu_file_offset_bits64
snogge Dec 19, 2024
96e81e7
gnu: Adapt stat64 for gnu_file_offset_bits64
snogge Mar 18, 2025
169d50b
gnu: Correct the struct stat64 padding for 32bit mips
snogge Mar 20, 2025
22ac02c
gnu: Correct struct stat64 for sparc
snogge Mar 20, 2025
131efe9
gnu: Add the __f_unused field to struct statvfs for sparc
snogge Mar 17, 2025
c1e4812
gnu: Add missing f_flags field to struct statfs for sparc
snogge Mar 18, 2025
872642a
gnu: Add proper structs for fpos_t and fpos64_t
snogge Nov 21, 2024
7ba56f2
gnu: Update struct aiocb for gnu_file_offset_bits64
snogge Mar 20, 2023
4a7c9a9
gnu: Adapt struct flock on mips for gnu_file_offset_bits64
snogge Mar 11, 2025
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
Prev Previous commit
Next Next commit
gnu: build settings for _FILE_OFFSET_BITS=64
  • Loading branch information
snogge authored and tgross35 committed Apr 9, 2025
commit a184436eca52a191dc8af9f16c7e9f22d966a7f0
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"freebsd13",
"freebsd14",
"freebsd15",
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
"gnu_file_offset_bits64",
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
"libc_const_extern_fn",
"libc_deny_warnings",
Expand Down Expand Up @@ -43,6 +45,10 @@ fn main() {
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

// The ABI of libc used by std is backward compatible with FreeBSD 12.
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
Expand Down Expand Up @@ -84,6 +90,23 @@ fn main() {
if linux_time_bits64 {
set_cfg("linux_time_bits64");
}
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
Ok(val) if val == "64" => {
if target_env == "gnu"
&& target_os == "linux"
&& target_ptr_width == "32"
&& target_arch != "riscv32"
&& target_arch != "x86_64"
{
set_cfg("gnu_file_offset_bits64");
}
}
Ok(val) if val != "32" => {
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
}
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add something like Ok(val) if val != "32" => panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'),?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added that check for both build.rs and libc-test/build.rs.

}

// On CI: deny all warnings
if libc_ci {
Expand Down
28 changes: 28 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3587,6 +3587,26 @@ fn test_vxworks(target: &str) {
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
Ok(val) if val == "64" => {
if target.contains("gnu")
&& target.contains("linux")
&& !target.ends_with("x32")
&& !target.contains("riscv32")
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
{
cfg.define("_FILE_OFFSET_BITS", Some("64"));
cfg.cfg("gnu_file_offset_bits64", None);
}
}
Ok(val) if val != "32" => {
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
}
_ => {}
}
}

fn test_linux(target: &str) {
assert!(target.contains("linux"));

Expand Down Expand Up @@ -3630,6 +3650,8 @@ fn test_linux(target: &str) {
// glibc versions older than 2.29.
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);

config_gnu_bits(target, &mut cfg);

headers! { cfg:
"ctype.h",
"dirent.h",
Expand Down Expand Up @@ -4791,6 +4813,7 @@ fn test_linux_like_apis(target: &str) {
if linux || android || emscripten {
// test strerror_r from the `string.h` header
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.skip_type(|_| true).skip_static(|_| true);

headers! { cfg: "string.h" }
Expand All @@ -4807,6 +4830,7 @@ fn test_linux_like_apis(target: &str) {
// test fcntl - see:
// http://man7.org/linux/man-pages/man2/fcntl.2.html
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);

if musl {
cfg.header("fcntl.h");
Expand Down Expand Up @@ -4836,6 +4860,7 @@ fn test_linux_like_apis(target: &str) {
if (linux && !wali) || android {
// test termios
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("asm/termbits.h");
cfg.header("linux/termios.h");
cfg.skip_type(|_| true)
Expand All @@ -4860,6 +4885,7 @@ fn test_linux_like_apis(target: &str) {
if linux || android {
// test IPV6_ constants:
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
headers! {
cfg:
"linux/in6.h"
Expand Down Expand Up @@ -4891,6 +4917,7 @@ fn test_linux_like_apis(target: &str) {
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
// making the tests for these fails when both are included.
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("elf.h");
cfg.skip_fn(|_| true)
.skip_static(|_| true)
Expand All @@ -4910,6 +4937,7 @@ fn test_linux_like_apis(target: &str) {
if (linux && !wali) || android {
// Test `ARPHRD_CAN`.
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("linux/if_arp.h");
cfg.skip_fn(|_| true)
.skip_static(|_| true)
Expand Down