Skip to content

Commit 601beeb

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

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

build.rs

Lines changed: 22 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",
@@ -84,6 +86,26 @@ fn main() {
8486
if linux_time_bits64 {
8587
set_cfg("linux_time_bits64");
8688
}
89+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64");
90+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64") {
91+
Ok(val) => {
92+
if val == "1" {
93+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
94+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
95+
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
96+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
97+
if target_env == "gnu"
98+
&& target_os == "linux"
99+
&& target_ptr_width == "32"
100+
&& target_arch != "riscv32"
101+
&& target_arch != "x86_64"
102+
{
103+
set_cfg("gnu_file_offset_bits64");
104+
}
105+
}
106+
}
107+
Err(_e) => {}
108+
}
87109

88110
// On CI: deny all warnings
89111
if libc_ci {

libc-test/build.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,6 +3574,25 @@ 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_BITS64") {
3579+
Ok(val) => {
3580+
if val == "1" {
3581+
if target.contains("gnu")
3582+
&& target.contains("linux")
3583+
&& !target.ends_with("x32")
3584+
&& !target.contains("riscv32")
3585+
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3586+
{
3587+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3588+
cfg.cfg("gnu_file_offset_bits64", None);
3589+
}
3590+
}
3591+
}
3592+
Err(_e) => {}
3593+
}
3594+
}
3595+
35773596
fn test_linux(target: &str) {
35783597
assert!(target.contains("linux"));
35793598

@@ -3617,6 +3636,8 @@ fn test_linux(target: &str) {
36173636
// glibc versions older than 2.29.
36183637
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
36193638

3639+
config_gnu_bits(target, &mut cfg);
3640+
36203641
headers! { cfg:
36213642
"ctype.h",
36223643
"dirent.h",
@@ -4064,8 +4085,7 @@ fn test_linux(target: &str) {
40644085
"epoll_params" => true,
40654086

40664087
// FIXME(linux): Requires >= 6.12 kernel headers.
4067-
"dmabuf_cmsg" |
4068-
"dmabuf_token" => true,
4088+
"dmabuf_cmsg" | "dmabuf_token" => true,
40694089

40704090
_ => false,
40714091
}
@@ -4779,6 +4799,7 @@ fn test_linux_like_apis(target: &str) {
47794799
if linux || android || emscripten {
47804800
// test strerror_r from the `string.h` header
47814801
let mut cfg = ctest_cfg();
4802+
config_gnu_bits(target, &mut cfg);
47824803
cfg.skip_type(|_| true).skip_static(|_| true);
47834804

47844805
headers! { cfg: "string.h" }
@@ -4795,6 +4816,7 @@ fn test_linux_like_apis(target: &str) {
47954816
// test fcntl - see:
47964817
// http://man7.org/linux/man-pages/man2/fcntl.2.html
47974818
let mut cfg = ctest_cfg();
4819+
config_gnu_bits(target, &mut cfg);
47984820

47994821
if musl {
48004822
cfg.header("fcntl.h");
@@ -4824,6 +4846,7 @@ fn test_linux_like_apis(target: &str) {
48244846
if (linux && !wali) || android {
48254847
// test termios
48264848
let mut cfg = ctest_cfg();
4849+
config_gnu_bits(target, &mut cfg);
48274850
cfg.header("asm/termbits.h");
48284851
cfg.header("linux/termios.h");
48294852
cfg.skip_type(|_| true)
@@ -4848,6 +4871,7 @@ fn test_linux_like_apis(target: &str) {
48484871
if linux || android {
48494872
// test IPV6_ constants:
48504873
let mut cfg = ctest_cfg();
4874+
config_gnu_bits(target, &mut cfg);
48514875
headers! {
48524876
cfg:
48534877
"linux/in6.h"
@@ -4879,6 +4903,7 @@ fn test_linux_like_apis(target: &str) {
48794903
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
48804904
// making the tests for these fails when both are included.
48814905
let mut cfg = ctest_cfg();
4906+
config_gnu_bits(target, &mut cfg);
48824907
cfg.header("elf.h");
48834908
cfg.skip_fn(|_| true)
48844909
.skip_static(|_| true)
@@ -4898,6 +4923,7 @@ fn test_linux_like_apis(target: &str) {
48984923
if (linux && !wali) || android {
48994924
// Test `ARPHRD_CAN`.
49004925
let mut cfg = ctest_cfg();
4926+
config_gnu_bits(target, &mut cfg);
49014927
cfg.header("linux/if_arp.h");
49024928
cfg.skip_fn(|_| true)
49034929
.skip_static(|_| true)

0 commit comments

Comments
 (0)