Skip to content

Commit ecc74e9

Browse files
authored
Merge branch 'main' into issues/4340
2 parents 5ee406f + e8b0152 commit ecc74e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1873
-1002
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 20 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

@@ -25,3 +37,9 @@ or mark it as a draft if you are not sure. -->
2537
included (see [#3131](https://github.com/rust-lang/libc/issues/3131))
2638
- [ ] Tested locally (`cd libc-test && cargo test --target mytarget`);
2739
especially relevant for platforms that may not be checked in CI
40+
41+
<!-- labels: is this PR a breaking change? If not, we can probably get it in a
42+
0.2 release. Just uncomment the following:
43+
44+
@rustbot label +stable-nominated
45+
-->

.github/workflows/ci.yaml

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ jobs:
2929
- name: Check style
3030
run: ./ci/style.sh
3131

32+
clippy:
33+
name: Clippy on ${{ matrix.os }}
34+
strategy:
35+
matrix:
36+
os: [ubuntu-24.04, macos-14, windows-2022]
37+
runs-on: ${{ matrix.os }}
38+
timeout-minutes: 10
39+
steps:
40+
- uses: actions/checkout@v4
41+
- run: rustup update stable --no-self-update
42+
- uses: Swatinem/rust-cache@v2
43+
# Here we use the latest stable Rust toolchain already installed by GitHub
44+
# Ideally we should run it for every target, but we cannot rely on unstable toolchains
45+
# due to Clippy not being consistent between them.
46+
- run: cargo clippy --workspace --exclude libc-test --exclude ctest-test --all-targets -- -D warnings
47+
3248
# This runs `cargo build --target ...` for all T1 and T2 targets`
3349
verify_build:
3450
name: Verify build
@@ -76,6 +92,12 @@ jobs:
7692
- target: i686-unknown-linux-gnu
7793
docker: true
7894
os: ubuntu-24.04
95+
- target: i686-unknown-linux-gnu
96+
docker: true
97+
os: ubuntu-24.04
98+
artifact-tag: offset-bits64
99+
env:
100+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
79101
- target: x86_64-unknown-linux-gnu
80102
docker: true
81103
os: ubuntu-24.04
@@ -107,6 +129,13 @@ jobs:
107129
with:
108130
key: ${{ matrix.target }}
109131

132+
- name: Add matrix env variables to the environment
133+
if: matrix.env
134+
run: |
135+
echo '${{ toJson(matrix.env) }}' |
136+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
137+
shell: bash
138+
110139
- name: Run natively
111140
if: "!matrix.docker"
112141
run: ./ci/run.sh ${{ matrix.target }}
@@ -115,11 +144,13 @@ jobs:
115144
run: ./ci/run-docker.sh ${{ matrix.target }}
116145

117146
- name: Create CI artifacts
147+
id: create_artifacts
118148
if: always()
119149
run: ./ci/create-artifacts.py
120150
- uses: actions/upload-artifact@v4
151+
if: always() && steps.create_artifacts.outcome == 'success'
121152
with:
122-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
153+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
123154
path: ${{ env.ARCHIVE_PATH }}
124155
retention-days: 5
125156

@@ -139,15 +170,11 @@ jobs:
139170
- aarch64-unknown-linux-gnu
140171
- aarch64-unknown-linux-musl
141172
- arm-linux-androideabi
142-
- arm-unknown-linux-gnueabihf
143173
- arm-unknown-linux-musleabihf
144174
- i686-linux-android
145175
- i686-unknown-linux-musl
146176
- loongarch64-unknown-linux-gnu
147177
- loongarch64-unknown-linux-musl
148-
# FIXME(ppc): SIGILL running tests, see
149-
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
150-
# - powerpc-unknown-linux-gnu
151178
- powerpc64-unknown-linux-gnu
152179
- powerpc64le-unknown-linux-gnu
153180
- riscv64gc-unknown-linux-gnu
@@ -162,6 +189,19 @@ jobs:
162189
# FIXME: It seems some items in `src/unix/mod.rs`
163190
# aren't defined on redox actually.
164191
# - x86_64-unknown-redox
192+
include:
193+
- target: arm-unknown-linux-gnueabihf
194+
- target: arm-unknown-linux-gnueabihf
195+
env:
196+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
197+
artifact-tag: offset-bits64
198+
# FIXME(ppc): SIGILL running tests, see
199+
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
200+
# - target: powerpc-unknown-linux-gnu
201+
# - target: powerpc-unknown-linux-gnu
202+
# env:
203+
# RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
204+
# artifact-tag: offset-bits64
165205
timeout-minutes: 25
166206
env:
167207
TARGET: ${{ matrix.target }}
@@ -173,15 +213,24 @@ jobs:
173213
with:
174214
key: ${{ matrix.target }}
175215

216+
- name: Add matrix env variables to the environment
217+
if: matrix.env
218+
run: |
219+
echo '${{ toJson(matrix.env) }}' |
220+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
221+
shell: bash
222+
176223
- name: Execute run-docker.sh
177224
run: ./ci/run-docker.sh ${{ matrix.target }}
178225

179226
- name: Create CI artifacts
227+
id: create_artifacts
180228
if: always()
181229
run: ./ci/create-artifacts.py
182230
- uses: actions/upload-artifact@v4
231+
if: always() && steps.create_artifacts.outcome == 'success'
183232
with:
184-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
233+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
185234
path: ${{ env.ARCHIVE_PATH }}
186235
retention-days: 5
187236

@@ -222,14 +271,25 @@ jobs:
222271
steps:
223272
- uses: actions/checkout@master
224273
- run: |
225-
msrv="$(perl -ne 'print if s/rust-version\s*=\s*"(.*)"/\1/g' ctest/Cargo.toml)"
274+
msrv="$(cargo metadata --format-version 1 | jq -r --arg CRATE_NAME ctest '.packages | map(select(.name == $CRATE_NAME)) | first | .rust_version')"
226275
echo "MSRV: $msrv"
227276
echo "MSRV=$msrv" >> "$GITHUB_ENV"
228277
- name: Install Rust
229278
run: rustup update "$MSRV" --no-self-update && rustup default "$MSRV"
230279
- uses: Swatinem/rust-cache@v2
231280
- run: cargo build -p ctest
232281

282+
docs:
283+
name: Ensure docs build
284+
runs-on: ubuntu-24.04
285+
timeout-minutes: 10
286+
steps:
287+
- uses: actions/checkout@master
288+
- name: Install Rust
289+
run: rustup update nightly --no-self-update && rustup default nightly
290+
- uses: Swatinem/rust-cache@v2
291+
- run: cargo doc --workspace --no-deps
292+
233293
# One job that "summarizes" the success state of this pipeline. This can then be added to branch
234294
# protection, rather than having to add each job separately.
235295
success:
@@ -242,7 +302,9 @@ jobs:
242302
- test_tier2_vm
243303
- verify_build
244304
- ctest_msrv
245-
# Github branch protection is exceedingly silly and treats "jobs skipped because a dependency
305+
- docs
306+
- clippy
307+
# GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency
246308
# failed" as success. So we have to do some contortions to ensure the job fails if any of its
247309
# dependencies fails.
248310
if: always() # make sure this is never "skipped"

.github/workflows/release.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ jobs:
2424
run: rustup update stable --no-self-update && rustup default stable
2525
- name: Run release-plz
2626
uses: MarcoIeni/[email protected]
27-
with:
28-
# On the main branch, only release ctest
29-
manifest_path: ctest/Cargo.toml
3027
env:
3128
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3229
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
30+
with:
31+
# FIXME(release): release-pr is broken since we have two release tracks for
32+
# `libc` :(
33+
command: release

.release-plz.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name = "libc"
33
changelog_path = "CHANGELOG.md"
44
git_release_name = "{{ version }}"
55
git_tag_name = "{{ version }}"
6+
publish = false # On the main branch, we don't want to publish anything
67

78
[[package]]
89
name = "ctest"
910
changelog_path = "ctest/CHANGELOG.md"
1011
git_release_name = "ctest-{{ version }}"
11-
git_tag_name = "ctest-{{ version }}"
12+
git_tag_name = "ctest-v{{ version }}"
1213

1314
[changelog]
1415
body = """

Cargo.toml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
[package]
22
name = "libc"
33
version = "1.0.0-alpha.1"
4-
authors = ["The Rust Project Developers"]
5-
license = "MIT OR Apache-2.0"
6-
readme = "README.md"
7-
edition = "2021"
8-
repository = "https://github.com/rust-lang/libc"
9-
homepage = "https://github.com/rust-lang/libc"
10-
documentation = "https://docs.rs/libc/"
114
keywords = ["libc", "ffi", "bindings", "operating", "system"]
125
categories = ["external-ffi-bindings", "no-std", "os"]
13-
build = "build.rs"
146
exclude = ["/ci/*", "/.github/*", "/.cirrus.yml", "/triagebot.toml"]
15-
rust-version = "1.63"
167
description = "Raw FFI bindings to platform libraries like libc."
8+
publish = false # On the main branch, we don't want to publish anything
9+
authors = ["The Rust Project Developers"]
10+
edition = "2021"
11+
license = "MIT OR Apache-2.0"
12+
repository = "https://github.com/rust-lang/libc"
13+
rust-version = "1.63"
1714

1815
[package.metadata.docs.rs]
1916
features = ["extra_traits"]
@@ -145,3 +142,24 @@ members = [
145142
"ctest-test",
146143
"libc-test",
147144
]
145+
146+
# FIXME(msrv): These should be renamed as `[workspace.lints.*]` once MSRV is above 1.64
147+
# This way all crates can use it with `[lints] workspace=true` section
148+
149+
[lints.rust]
150+
# FIXME(cleanup): make ident usage consistent in each file
151+
unused_qualifications = "allow"
152+
153+
[lints.clippy]
154+
missing_safety_doc = "allow"
155+
156+
# FIXME(clippy): all these are default lints and should probably be fixed
157+
identity_op = "allow"
158+
if_same_then_else = "allow"
159+
non_minimal_cfg = "allow"
160+
precedence = "allow"
161+
redundant_field_names = "allow"
162+
redundant_static_lifetimes = "allow"
163+
unnecessary_cast = "allow"
164+
unused_unit = "allow"
165+
zero_ptr = "allow"

build.rs

Lines changed: 33 additions & 7 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",
@@ -29,7 +31,10 @@ const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
2931
"switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", "cygwin",
3032
],
3133
),
32-
("target_env", &["illumos", "wasi", "aix", "ohos"]),
34+
(
35+
"target_env",
36+
&["illumos", "wasi", "aix", "ohos", "nto71_iosock", "nto80"],
37+
),
3338
(
3439
"target_arch",
3540
&["loongarch64", "mips32r6", "mips64r6", "csky"],
@@ -43,6 +48,10 @@ fn main() {
4348
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
4449
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4550
let libc_ci = env::var("LIBC_CI").is_ok();
51+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
52+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
53+
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
54+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
4655

4756
// The ABI of libc used by std is backward compatible with FreeBSD 12.
4857
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
@@ -84,6 +93,23 @@ fn main() {
8493
if linux_time_bits64 {
8594
set_cfg("linux_time_bits64");
8695
}
96+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
97+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
98+
Ok(val) if val == "64" => {
99+
if target_env == "gnu"
100+
&& target_os == "linux"
101+
&& target_ptr_width == "32"
102+
&& target_arch != "riscv32"
103+
&& target_arch != "x86_64"
104+
{
105+
set_cfg("gnu_file_offset_bits64");
106+
}
107+
}
108+
Ok(val) if val != "32" => {
109+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
110+
}
111+
_ => {}
112+
}
87113

88114
// On CI: deny all warnings
89115
if libc_ci {
@@ -98,17 +124,17 @@ fn main() {
98124
if rustc_minor_ver >= 80 {
99125
for cfg in ALLOWED_CFGS {
100126
if rustc_minor_ver >= 75 {
101-
println!("cargo:rustc-check-cfg=cfg({})", cfg);
127+
println!("cargo:rustc-check-cfg=cfg({cfg})");
102128
} else {
103-
println!("cargo:rustc-check-cfg=values({})", cfg);
129+
println!("cargo:rustc-check-cfg=values({cfg})");
104130
}
105131
}
106132
for &(name, values) in CHECK_CFG_EXTRA {
107133
let values = values.join("\",\"");
108134
if rustc_minor_ver >= 75 {
109-
println!("cargo:rustc-check-cfg=cfg({},values(\"{}\"))", name, values);
135+
println!("cargo:rustc-check-cfg=cfg({name},values(\"{values}\"))");
110136
} else {
111-
println!("cargo:rustc-check-cfg=values({},\"{}\")", name, values);
137+
println!("cargo:rustc-check-cfg=values({name},\"{values}\")");
112138
}
113139
}
114140
}
@@ -229,7 +255,7 @@ fn emcc_version_code() -> Option<u64> {
229255

230256
fn set_cfg(cfg: &str) {
231257
if !ALLOWED_CFGS.contains(&cfg) {
232-
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
258+
panic!("trying to set cfg {cfg}, but it is not in ALLOWED_CFGS");
233259
}
234-
println!("cargo:rustc-cfg={}", cfg);
260+
println!("cargo:rustc-cfg={cfg}");
235261
}

ci/ios/deploy_and_run_on_ios_simulator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::process::Command;
1616
macro_rules! t {
1717
($e:expr) => (match $e {
1818
Ok(e) => e,
19-
Err(e) => panic!("{} failed with: {}", stringify!($e), e),
19+
Err(e) => panic!("{} failed with: {e}", stringify!($e)),
2020
})
2121
}
2222

@@ -143,7 +143,7 @@ trait CheckStatus {
143143

144144
impl CheckStatus for Command {
145145
fn check_status(&mut self) {
146-
println!("\trunning: {:?}", self);
146+
println!("\trunning: {self:?}");
147147
assert!(t!(self.status()).success());
148148
}
149149
}

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 \

0 commit comments

Comments
 (0)