Skip to content

Commit aed5b56

Browse files
snoggetgross35
authored andcommitted
gnu: build settings for _FILE_OFFSET_BITS=64
(backport <rust-lang#4345>) (cherry picked from commit a184436)
1 parent 4aba8ad commit aed5b56

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",
@@ -44,6 +46,10 @@ fn main() {
4446
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
4547
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4648
let libc_ci = env::var("LIBC_CI").is_ok();
49+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
50+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
51+
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
52+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
4753

4854
// The ABI of libc used by std is backward compatible with FreeBSD 12.
4955
// The ABI of libc from crates.io is backward compatible with FreeBSD 11.
@@ -85,6 +91,23 @@ fn main() {
8591
if linux_time_bits64 {
8692
set_cfg("linux_time_bits64");
8793
}
94+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
95+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
96+
Ok(val) if val == "64" => {
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+
Ok(val) if val != "32" => {
107+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
108+
}
109+
_ => {}
110+
}
88111

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

libc-test/build.rs

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

3667+
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3668+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3669+
Ok(val) if val == "64" => {
3670+
if target.contains("gnu")
3671+
&& target.contains("linux")
3672+
&& !target.ends_with("x32")
3673+
&& !target.contains("riscv32")
3674+
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3675+
{
3676+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3677+
cfg.cfg("gnu_file_offset_bits64", None);
3678+
}
3679+
}
3680+
Ok(val) if val != "32" => {
3681+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3682+
}
3683+
_ => {}
3684+
}
3685+
}
3686+
36673687
fn test_linux(target: &str) {
36683688
assert!(target.contains("linux"));
36693689

@@ -3707,6 +3727,8 @@ fn test_linux(target: &str) {
37073727
// glibc versions older than 2.29.
37083728
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
37093729

3730+
config_gnu_bits(target, &mut cfg);
3731+
37103732
headers! { cfg:
37113733
"ctype.h",
37123734
"dirent.h",
@@ -4869,6 +4891,7 @@ fn test_linux_like_apis(target: &str) {
48694891
if linux || android || emscripten {
48704892
// test strerror_r from the `string.h` header
48714893
let mut cfg = ctest_cfg();
4894+
config_gnu_bits(target, &mut cfg);
48724895
cfg.skip_type(|_| true).skip_static(|_| true);
48734896

48744897
headers! { cfg: "string.h" }
@@ -4885,6 +4908,7 @@ fn test_linux_like_apis(target: &str) {
48854908
// test fcntl - see:
48864909
// http://man7.org/linux/man-pages/man2/fcntl.2.html
48874910
let mut cfg = ctest_cfg();
4911+
config_gnu_bits(target, &mut cfg);
48884912

48894913
if musl {
48904914
cfg.header("fcntl.h");
@@ -4914,6 +4938,7 @@ fn test_linux_like_apis(target: &str) {
49144938
if (linux && !wali) || android {
49154939
// test termios
49164940
let mut cfg = ctest_cfg();
4941+
config_gnu_bits(target, &mut cfg);
49174942
cfg.header("asm/termbits.h");
49184943
cfg.header("linux/termios.h");
49194944
cfg.skip_type(|_| true)
@@ -4938,6 +4963,7 @@ fn test_linux_like_apis(target: &str) {
49384963
if linux || android {
49394964
// test IPV6_ constants:
49404965
let mut cfg = ctest_cfg();
4966+
config_gnu_bits(target, &mut cfg);
49414967
headers! {
49424968
cfg:
49434969
"linux/in6.h"
@@ -4969,6 +4995,7 @@ fn test_linux_like_apis(target: &str) {
49694995
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
49704996
// making the tests for these fails when both are included.
49714997
let mut cfg = ctest_cfg();
4998+
config_gnu_bits(target, &mut cfg);
49724999
cfg.header("elf.h");
49735000
cfg.skip_fn(|_| true)
49745001
.skip_static(|_| true)
@@ -4988,6 +5015,7 @@ fn test_linux_like_apis(target: &str) {
49885015
if (linux && !wali) || android {
49895016
// Test `ARPHRD_CAN`.
49905017
let mut cfg = ctest_cfg();
5018+
config_gnu_bits(target, &mut cfg);
49915019
cfg.header("linux/if_arp.h");
49925020
cfg.skip_fn(|_| true)
49935021
.skip_static(|_| true)

0 commit comments

Comments
 (0)