Skip to content

Commit 7e684c4

Browse files
committed
gnu: build settings for _FILE_OFFSET_BITS=64
1 parent 899fb69 commit 7e684c4

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1313
"freebsd13",
1414
"freebsd14",
1515
"freebsd15",
16+
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
17+
"gnu_file_offset_bits64",
1618
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
1719
"libc_const_extern_fn",
1820
"libc_deny_warnings",
@@ -43,6 +45,10 @@ fn main() {
4345
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
4446
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4547
let libc_ci = env::var("LIBC_CI").is_ok();
48+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
49+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
50+
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
51+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
4652

4753
// The ABI of libc used by std is backward compatible with FreeBSD 12.
4854
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
@@ -84,6 +90,20 @@ fn main() {
8490
if linux_time_bits64 {
8591
set_cfg("linux_time_bits64");
8692
}
93+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
94+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
95+
Ok(val) if val == "64" => {
96+
if target_env == "gnu"
97+
&& target_os == "linux"
98+
&& target_ptr_width == "32"
99+
&& target_arch != "riscv32"
100+
&& target_arch != "x86_64"
101+
{
102+
set_cfg("gnu_file_offset_bits64");
103+
}
104+
}
105+
_ => {}
106+
}
87107

88108
// On CI: deny all warnings
89109
if libc_ci {

libc-test/build.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,6 +3574,23 @@ fn test_vxworks(target: &str) {
35743574
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
35753575
}
35763576

3577+
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3578+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3579+
Ok(val) if val == "64" => {
3580+
if target.contains("gnu")
3581+
&& target.contains("linux")
3582+
&& !target.ends_with("x32")
3583+
&& !target.contains("riscv32")
3584+
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3585+
{
3586+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3587+
cfg.cfg("gnu_file_offset_bits64", None);
3588+
}
3589+
}
3590+
_ => {}
3591+
}
3592+
}
3593+
35773594
fn test_linux(target: &str) {
35783595
assert!(target.contains("linux"));
35793596

@@ -3617,6 +3634,8 @@ fn test_linux(target: &str) {
36173634
// glibc versions older than 2.29.
36183635
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
36193636

3637+
config_gnu_bits(target, &mut cfg);
3638+
36203639
headers! { cfg:
36213640
"ctype.h",
36223641
"dirent.h",
@@ -4064,8 +4083,7 @@ fn test_linux(target: &str) {
40644083
"epoll_params" => true,
40654084

40664085
// FIXME(linux): Requires >= 6.12 kernel headers.
4067-
"dmabuf_cmsg" |
4068-
"dmabuf_token" => true,
4086+
"dmabuf_cmsg" | "dmabuf_token" => true,
40694087

40704088
_ => false,
40714089
}
@@ -4779,6 +4797,7 @@ fn test_linux_like_apis(target: &str) {
47794797
if linux || android || emscripten {
47804798
// test strerror_r from the `string.h` header
47814799
let mut cfg = ctest_cfg();
4800+
config_gnu_bits(target, &mut cfg);
47824801
cfg.skip_type(|_| true).skip_static(|_| true);
47834802

47844803
headers! { cfg: "string.h" }
@@ -4795,6 +4814,7 @@ fn test_linux_like_apis(target: &str) {
47954814
// test fcntl - see:
47964815
// http://man7.org/linux/man-pages/man2/fcntl.2.html
47974816
let mut cfg = ctest_cfg();
4817+
config_gnu_bits(target, &mut cfg);
47984818

47994819
if musl {
48004820
cfg.header("fcntl.h");
@@ -4824,6 +4844,7 @@ fn test_linux_like_apis(target: &str) {
48244844
if (linux && !wali) || android {
48254845
// test termios
48264846
let mut cfg = ctest_cfg();
4847+
config_gnu_bits(target, &mut cfg);
48274848
cfg.header("asm/termbits.h");
48284849
cfg.header("linux/termios.h");
48294850
cfg.skip_type(|_| true)
@@ -4848,6 +4869,7 @@ fn test_linux_like_apis(target: &str) {
48484869
if linux || android {
48494870
// test IPV6_ constants:
48504871
let mut cfg = ctest_cfg();
4872+
config_gnu_bits(target, &mut cfg);
48514873
headers! {
48524874
cfg:
48534875
"linux/in6.h"
@@ -4879,6 +4901,7 @@ fn test_linux_like_apis(target: &str) {
48794901
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
48804902
// making the tests for these fails when both are included.
48814903
let mut cfg = ctest_cfg();
4904+
config_gnu_bits(target, &mut cfg);
48824905
cfg.header("elf.h");
48834906
cfg.skip_fn(|_| true)
48844907
.skip_static(|_| true)
@@ -4898,6 +4921,7 @@ fn test_linux_like_apis(target: &str) {
48984921
if (linux && !wali) || android {
48994922
// Test `ARPHRD_CAN`.
49004923
let mut cfg = ctest_cfg();
4924+
config_gnu_bits(target, &mut cfg);
49014925
cfg.header("linux/if_arp.h");
49024926
cfg.skip_fn(|_| true)
49034927
.skip_static(|_| true)

0 commit comments

Comments
 (0)