Skip to content

Commit 1c88e89

Browse files
authored
Merge pull request #4393 from tgross35/backport-jalapeno
[0.2] Backports
2 parents 56c0149 + dca8f09 commit 1c88e89

File tree

20 files changed

+401
-103
lines changed

20 files changed

+401
-103
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ Please fill out the below template.
1212

1313
# Sources
1414

15-
<!-- All API changes must have links to headers and/or documentation,
16-
preferably both -->
15+
<!-- All API changes must have permalinks to headers. Common sources:
16+
17+
* Linux uapi https://github.com/torvalds/linux/tree/master/include/uapi
18+
* Glibc https://github.com/bminor/glibc
19+
* Musl https://github.com/bminor/musl
20+
* Apple XNU https://github.com/apple-oss-distributions/xnu
21+
* Android https://cs.android.com/android/platform/superproject/main
22+
23+
After navigating to the relevant file, click the triple dots and select "copy
24+
permalink" if on GitHub, or l-r (links->commit) for the Android source to get a
25+
link to the current version of the header.
26+
27+
If sources are closed, link to documentation or paste relevant C definitions.
28+
-->
1729

1830
# Checklist
1931

.github/workflows/ci.yaml

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ jobs:
7777
- target: i686-unknown-linux-gnu
7878
docker: true
7979
os: ubuntu-24.04
80+
- target: i686-unknown-linux-gnu
81+
docker: true
82+
os: ubuntu-24.04
83+
artifact-tag: offset-bits64
84+
env:
85+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
8086
- target: x86_64-unknown-linux-gnu
8187
docker: true
8288
os: ubuntu-24.04
@@ -108,6 +114,13 @@ jobs:
108114
with:
109115
key: ${{ matrix.target }}
110116

117+
- name: Add matrix env variables to the environment
118+
if: matrix.env
119+
run: |
120+
echo '${{ toJson(matrix.env) }}' |
121+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
122+
shell: bash
123+
111124
- name: Run natively
112125
if: "!matrix.docker"
113126
run: ./ci/run.sh ${{ matrix.target }}
@@ -116,11 +129,13 @@ jobs:
116129
run: ./ci/run-docker.sh ${{ matrix.target }}
117130

118131
- name: Create CI artifacts
132+
id: create_artifacts
119133
if: always()
120134
run: ./ci/create-artifacts.py
121135
- uses: actions/upload-artifact@v4
136+
if: always() && steps.create_artifacts.outcome == 'success'
122137
with:
123-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
138+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
124139
path: ${{ env.ARCHIVE_PATH }}
125140
retention-days: 5
126141

@@ -140,15 +155,11 @@ jobs:
140155
- aarch64-unknown-linux-gnu
141156
- aarch64-unknown-linux-musl
142157
- arm-linux-androideabi
143-
- arm-unknown-linux-gnueabihf
144158
- arm-unknown-linux-musleabihf
145159
- i686-linux-android
146160
- i686-unknown-linux-musl
147161
- loongarch64-unknown-linux-gnu
148162
- loongarch64-unknown-linux-musl
149-
# FIXME(ppc): SIGILL running tests, see
150-
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
151-
# - powerpc-unknown-linux-gnu
152163
- powerpc64-unknown-linux-gnu
153164
- powerpc64le-unknown-linux-gnu
154165
- riscv64gc-unknown-linux-gnu
@@ -163,6 +174,19 @@ jobs:
163174
# FIXME: It seems some items in `src/unix/mod.rs`
164175
# aren't defined on redox actually.
165176
# - x86_64-unknown-redox
177+
include:
178+
- target: arm-unknown-linux-gnueabihf
179+
- target: arm-unknown-linux-gnueabihf
180+
env:
181+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
182+
artifact-tag: offset-bits64
183+
# FIXME(ppc): SIGILL running tests, see
184+
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
185+
# - target: powerpc-unknown-linux-gnu
186+
# - target: powerpc-unknown-linux-gnu
187+
# env:
188+
# RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
189+
# artifact-tag: offset-bits64
166190
timeout-minutes: 25
167191
env:
168192
TARGET: ${{ matrix.target }}
@@ -174,15 +198,24 @@ jobs:
174198
with:
175199
key: ${{ matrix.target }}
176200

201+
- name: Add matrix env variables to the environment
202+
if: matrix.env
203+
run: |
204+
echo '${{ toJson(matrix.env) }}' |
205+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
206+
shell: bash
207+
177208
- name: Execute run-docker.sh
178209
run: ./ci/run-docker.sh ${{ matrix.target }}
179210

180211
- name: Create CI artifacts
212+
id: create_artifacts
181213
if: always()
182214
run: ./ci/create-artifacts.py
183215
- uses: actions/upload-artifact@v4
216+
if: always() && steps.create_artifacts.outcome == 'success'
184217
with:
185-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
218+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
186219
path: ${{ env.ARCHIVE_PATH }}
187220
retention-days: 5
188221

build.rs

Lines changed: 23 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",
@@ -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 {

ci/run-docker.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ run() {
4343
--user "$(id -u)":"$(id -g)" \
4444
--env LIBC_CI \
4545
--env LIBC_CI_ZBUILD_STD \
46+
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
4647
--env CARGO_HOME=/cargo \
4748
--env CARGO_TARGET_DIR=/checkout/target \
4849
--volume "$CARGO_HOME":/cargo \
4950
--volume "$(rustc --print sysroot)":/rust:ro \
50-
--volume "$(pwd)":/checkout:ro \
51-
--volume "$(pwd)"/target:/checkout/target \
51+
--volume "$PWD":/checkout:ro \
52+
--volume "$PWD"/target:/checkout/target \
5253
$kvm \
5354
--init \
5455
--workdir /checkout \

ci/verify-build.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ test_target() {
7575
if [ "$os" = "linux" ]; then
7676
# Test with the equivalent of __USE_TIME_BITS64
7777
RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
78+
case "$target" in
79+
# Test with the equivalent of __FILE_OFFSET_BITS=64
80+
arm*-gnu*|i*86*-gnu|powerpc-*-gnu*|mips*-gnu|sparc-*-gnu|thumb-*gnu*)
81+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd;;
82+
esac
7883
fi
7984

8085
# Test again without default features, i.e. without "std"
@@ -92,7 +97,7 @@ test_target() {
9297
stable-x86_64-*freebsd*) do_freebsd_checks=1 ;;
9398
nightly-i686*freebsd*) do_freebsd_checks=1 ;;
9499
esac
95-
100+
96101
if [ -n "${do_freebsd_checks:-}" ]; then
97102
for version in $freebsd_versions; do
98103
export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version"
@@ -300,7 +305,7 @@ filter_and_run() {
300305
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
301306
return
302307
fi
303-
308+
304309
test_target "$target" "$no_dist"
305310
some_tests_run=1
306311
fi

libc-test/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,9 @@ fn test_freebsd(target: &str) {
28552855
"CAP_UNUSED0_44" | "CAP_UNUSED0_57" | "CAP_UNUSED1_22" | "CAP_UNUSED1_57"
28562856
| "CAP_ALL0" | "CAP_ALL1" => true,
28572857

2858+
// FIXME(freebsd): Removed in FreeBSD 15, deprecated in libc
2859+
"TCP_PCAP_OUT" | "TCP_PCAP_IN" => true,
2860+
28582861
_ => false,
28592862
}
28602863
});
@@ -3661,6 +3664,26 @@ fn test_vxworks(target: &str) {
36613664
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
36623665
}
36633666

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+
36643687
fn test_linux(target: &str) {
36653688
assert!(target.contains("linux"));
36663689

@@ -3704,6 +3727,8 @@ fn test_linux(target: &str) {
37043727
// glibc versions older than 2.29.
37053728
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
37063729

3730+
config_gnu_bits(target, &mut cfg);
3731+
37073732
headers! { cfg:
37083733
"ctype.h",
37093734
"dirent.h",
@@ -4866,6 +4891,7 @@ fn test_linux_like_apis(target: &str) {
48664891
if linux || android || emscripten {
48674892
// test strerror_r from the `string.h` header
48684893
let mut cfg = ctest_cfg();
4894+
config_gnu_bits(target, &mut cfg);
48694895
cfg.skip_type(|_| true).skip_static(|_| true);
48704896

48714897
headers! { cfg: "string.h" }
@@ -4882,6 +4908,7 @@ fn test_linux_like_apis(target: &str) {
48824908
// test fcntl - see:
48834909
// http://man7.org/linux/man-pages/man2/fcntl.2.html
48844910
let mut cfg = ctest_cfg();
4911+
config_gnu_bits(target, &mut cfg);
48854912

48864913
if musl {
48874914
cfg.header("fcntl.h");
@@ -4911,6 +4938,7 @@ fn test_linux_like_apis(target: &str) {
49114938
if (linux && !wali) || android {
49124939
// test termios
49134940
let mut cfg = ctest_cfg();
4941+
config_gnu_bits(target, &mut cfg);
49144942
cfg.header("asm/termbits.h");
49154943
cfg.header("linux/termios.h");
49164944
cfg.skip_type(|_| true)
@@ -4935,6 +4963,7 @@ fn test_linux_like_apis(target: &str) {
49354963
if linux || android {
49364964
// test IPV6_ constants:
49374965
let mut cfg = ctest_cfg();
4966+
config_gnu_bits(target, &mut cfg);
49384967
headers! {
49394968
cfg:
49404969
"linux/in6.h"
@@ -4966,6 +4995,7 @@ fn test_linux_like_apis(target: &str) {
49664995
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
49674996
// making the tests for these fails when both are included.
49684997
let mut cfg = ctest_cfg();
4998+
config_gnu_bits(target, &mut cfg);
49694999
cfg.header("elf.h");
49705000
cfg.skip_fn(|_| true)
49715001
.skip_static(|_| true)
@@ -4985,6 +5015,7 @@ fn test_linux_like_apis(target: &str) {
49855015
if (linux && !wali) || android {
49865016
// Test `ARPHRD_CAN`.
49875017
let mut cfg = ctest_cfg();
5018+
config_gnu_bits(target, &mut cfg);
49885019
cfg.header("linux/if_arp.h");
49895020
cfg.skip_fn(|_| true)
49905021
.skip_static(|_| true)

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,7 +3771,9 @@ pub const TCP_PERF_INFO: c_int = 78;
37713771
pub const TCP_LRD: c_int = 79;
37723772
pub const TCP_KEEPINIT: c_int = 128;
37733773
pub const TCP_FASTOPEN: c_int = 1025;
3774+
#[deprecated(since = "0.2.171", note = "removed in FreeBSD 15")]
37743775
pub const TCP_PCAP_OUT: c_int = 2048;
3776+
#[deprecated(since = "0.2.171", note = "removed in FreeBSD 15")]
37753777
pub const TCP_PCAP_IN: c_int = 4096;
37763778
pub const TCP_FUNCTION_BLK: c_int = 8192;
37773779
pub const TCP_FUNCTION_ALIAS: c_int = 8193;

0 commit comments

Comments
 (0)