Skip to content

Commit a184436

Browse files
snoggetgross35
authored andcommitted
gnu: build settings for _FILE_OFFSET_BITS=64
1 parent f10e8e4 commit a184436

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

build.rs

+23
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,23 @@ 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+
Ok(val) if val != "32" => {
106+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
107+
}
108+
_ => {}
109+
}
87110

88111
// On CI: deny all warnings
89112
if libc_ci {

libc-test/build.rs

+28
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,26 @@ fn test_vxworks(target: &str) {
35873587
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
35883588
}
35893589

3590+
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3591+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3592+
Ok(val) if val == "64" => {
3593+
if target.contains("gnu")
3594+
&& target.contains("linux")
3595+
&& !target.ends_with("x32")
3596+
&& !target.contains("riscv32")
3597+
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3598+
{
3599+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3600+
cfg.cfg("gnu_file_offset_bits64", None);
3601+
}
3602+
}
3603+
Ok(val) if val != "32" => {
3604+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3605+
}
3606+
_ => {}
3607+
}
3608+
}
3609+
35903610
fn test_linux(target: &str) {
35913611
assert!(target.contains("linux"));
35923612

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

3653+
config_gnu_bits(target, &mut cfg);
3654+
36333655
headers! { cfg:
36343656
"ctype.h",
36353657
"dirent.h",
@@ -4791,6 +4813,7 @@ fn test_linux_like_apis(target: &str) {
47914813
if linux || android || emscripten {
47924814
// test strerror_r from the `string.h` header
47934815
let mut cfg = ctest_cfg();
4816+
config_gnu_bits(target, &mut cfg);
47944817
cfg.skip_type(|_| true).skip_static(|_| true);
47954818

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

48114835
if musl {
48124836
cfg.header("fcntl.h");
@@ -4836,6 +4860,7 @@ fn test_linux_like_apis(target: &str) {
48364860
if (linux && !wali) || android {
48374861
// test termios
48384862
let mut cfg = ctest_cfg();
4863+
config_gnu_bits(target, &mut cfg);
48394864
cfg.header("asm/termbits.h");
48404865
cfg.header("linux/termios.h");
48414866
cfg.skip_type(|_| true)
@@ -4860,6 +4885,7 @@ fn test_linux_like_apis(target: &str) {
48604885
if linux || android {
48614886
// test IPV6_ constants:
48624887
let mut cfg = ctest_cfg();
4888+
config_gnu_bits(target, &mut cfg);
48634889
headers! {
48644890
cfg:
48654891
"linux/in6.h"
@@ -4891,6 +4917,7 @@ fn test_linux_like_apis(target: &str) {
48914917
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
48924918
// making the tests for these fails when both are included.
48934919
let mut cfg = ctest_cfg();
4920+
config_gnu_bits(target, &mut cfg);
48944921
cfg.header("elf.h");
48954922
cfg.skip_fn(|_| true)
48964923
.skip_static(|_| true)
@@ -4910,6 +4937,7 @@ fn test_linux_like_apis(target: &str) {
49104937
if (linux && !wali) || android {
49114938
// Test `ARPHRD_CAN`.
49124939
let mut cfg = ctest_cfg();
4940+
config_gnu_bits(target, &mut cfg);
49134941
cfg.header("linux/if_arp.h");
49144942
cfg.skip_fn(|_| true)
49154943
.skip_static(|_| true)

0 commit comments

Comments
 (0)