Skip to content

Commit c56fd04

Browse files
authored
Merge pull request #4468 from tgross35/backport-ghost
[0.2] Backports
2 parents ccdcaff + 00c1999 commit c56fd04

File tree

65 files changed

+4150
-1337
lines changed

Some content is hidden

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

65 files changed

+4150
-1337
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ jobs:
3030
- name: Check style
3131
run: ./ci/style.sh
3232

33+
clippy:
34+
name: Clippy on ${{ matrix.os }}
35+
strategy:
36+
matrix:
37+
os: [ubuntu-24.04, macos-14, windows-2022]
38+
runs-on: ${{ matrix.os }}
39+
timeout-minutes: 10
40+
steps:
41+
- uses: actions/checkout@v4
42+
- run: rustup update stable --no-self-update
43+
- uses: Swatinem/rust-cache@v2
44+
# Here we use the latest stable Rust toolchain already installed by GitHub
45+
# Ideally we should run it for every target, but we cannot rely on unstable toolchains
46+
# due to Clippy not being consistent between them.
47+
- run: cargo clippy --workspace --exclude libc-test --exclude ctest-test --all-targets -- -D warnings
48+
3349
# This runs `cargo build --target ...` for all T1 and T2 targets`
3450
verify_build:
3551
name: Verify build
@@ -180,6 +196,18 @@ jobs:
180196
env:
181197
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
182198
artifact-tag: offset-bits64
199+
- target: aarch64-unknown-linux-musl
200+
env:
201+
RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1
202+
- target: arm-unknown-linux-musleabihf
203+
env:
204+
RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1
205+
- target: i686-unknown-linux-musl
206+
env:
207+
RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1
208+
- target: loongarch64-unknown-linux-musl
209+
env:
210+
RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1
183211
# FIXME(ppc): SIGILL running tests, see
184212
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
185213
# - target: powerpc-unknown-linux-gnu
@@ -258,7 +286,8 @@ jobs:
258286
- test_tier2
259287
- test_tier2_vm
260288
- verify_build
261-
# Github branch protection is exceedingly silly and treats "jobs skipped because a dependency
289+
- clippy
290+
# GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency
262291
# failed" as success. So we have to do some contortions to ensure the job fails if any of its
263292
# dependencies fails.
264293
if: always() # make sure this is never "skipped"

Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,30 @@ members = [
150150
"ctest",
151151
"libc-test",
152152
]
153+
154+
# FIXME(msrv): These should be renamed as `[workspace.lints.*]` once MSRV is above 1.64
155+
# This way all crates can use it with `[lints] workspace=true` section
156+
157+
[lints.rust]
158+
# FIXME(cleanup): make ident usage consistent in each file
159+
unused_qualifications = "allow"
160+
161+
[lints.clippy]
162+
# Enable pedantic lints - use this manually once in a while, but don't enable by default
163+
# pedantic = { level = "warn", priority = -1 }
164+
165+
# We are okay with the current state of these lints
166+
explicit_iter_loop = "warn"
167+
identity_op = "allow" # some expressions like `0 | x` are clearer for bit ops
168+
manual_assert = "warn"
169+
map_unwrap_or = "warn"
170+
missing_safety_doc = "allow" # safety? in libc? seriously?
171+
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this
172+
ptr_as_ptr = "warn"
173+
unnecessary_semicolon = "warn"
174+
175+
# FIXME(clippy): these should be fixed if possible
176+
expl_impl_clone_on_copy = "allow"
177+
uninlined_format_args = "allow"
178+
unnecessary_cast = "allow" # some casts like `as usize` are only needed for some targets
179+
used_underscore_binding = "allow"

build.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{env, str};
44
// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
55
// need to know all the possible cfgs that this script will set. If you need to set another cfg
66
// make sure to add it to this list as well.
7-
const ALLOWED_CFGS: &'static [&'static str] = &[
7+
const ALLOWED_CFGS: &[&str] = &[
88
"emscripten_old_stat_abi",
99
"espidf_time32",
1010
"freebsd10",
@@ -22,10 +22,11 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
2222
"libc_ctest",
2323
// Corresponds to `__USE_TIME_BITS64` in UAPI
2424
"linux_time_bits64",
25+
"musl_v1_2_3",
2526
];
2627

2728
// Extra values to allow for check-cfg.
28-
const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
29+
const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
2930
(
3031
"target_os",
3132
&[
@@ -89,6 +90,13 @@ fn main() {
8990
_ => (),
9091
}
9192

93+
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
94+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
95+
// loongarch64 and ohos have already updated
96+
if musl_v1_2_3 || target_os == "loongarch64" || target_env == "ohos" {
97+
// FIXME(musl): enable time64 api as well
98+
set_cfg("musl_v1_2_3");
99+
}
92100
let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
93101
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
94102
if linux_time_bits64 {
@@ -130,17 +138,17 @@ fn main() {
130138
if rustc_minor_ver >= 80 {
131139
for cfg in ALLOWED_CFGS {
132140
if rustc_minor_ver >= 75 {
133-
println!("cargo:rustc-check-cfg=cfg({})", cfg);
141+
println!("cargo:rustc-check-cfg=cfg({cfg})");
134142
} else {
135-
println!("cargo:rustc-check-cfg=values({})", cfg);
143+
println!("cargo:rustc-check-cfg=values({cfg})");
136144
}
137145
}
138146
for &(name, values) in CHECK_CFG_EXTRA {
139147
let values = values.join("\",\"");
140148
if rustc_minor_ver >= 75 {
141-
println!("cargo:rustc-check-cfg=cfg({},values(\"{}\"))", name, values);
149+
println!("cargo:rustc-check-cfg=cfg({name},values(\"{values}\"))");
142150
} else {
143-
println!("cargo:rustc-check-cfg=values({},\"{}\")", name, values);
151+
println!("cargo:rustc-check-cfg=values({name},\"{values}\")");
144152
}
145153
}
146154
}
@@ -169,12 +177,11 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
169177

170178
let output = cmd.output().expect("Failed to get rustc version");
171179

172-
if !output.status.success() {
173-
panic!(
174-
"failed to run rustc: {}",
175-
String::from_utf8_lossy(output.stderr.as_slice())
176-
);
177-
}
180+
assert!(
181+
output.status.success(),
182+
"failed to run rustc: {}",
183+
String::from_utf8_lossy(output.stderr.as_slice())
184+
);
178185

179186
output
180187
}
@@ -201,9 +208,11 @@ fn rustc_minor_nightly() -> (u32, bool) {
201208

202209
let mut pieces = version.split('.');
203210

204-
if pieces.next() != Some("rustc 1") {
205-
panic!("Failed to get rustc version");
206-
}
211+
assert_eq!(
212+
pieces.next(),
213+
Some("rustc 1"),
214+
"Failed to get rustc version"
215+
);
207216

208217
let minor = pieces.next();
209218

@@ -213,9 +222,9 @@ fn rustc_minor_nightly() -> (u32, bool) {
213222
// since a nightly build should either come from CI
214223
// or a git checkout
215224
let nightly_raw = otry!(pieces.next()).split('-').nth(1);
216-
let nightly = nightly_raw
217-
.map(|raw| raw.starts_with("dev") || raw.starts_with("nightly"))
218-
.unwrap_or(false);
225+
let nightly = nightly_raw.map_or(false, |raw| {
226+
raw.starts_with("dev") || raw.starts_with("nightly")
227+
});
219228
let minor = otry!(otry!(minor).parse().ok());
220229

221230
(minor, nightly)
@@ -266,8 +275,9 @@ fn emcc_version_code() -> Option<u64> {
266275
}
267276

268277
fn set_cfg(cfg: &str) {
269-
if !ALLOWED_CFGS.contains(&cfg) {
270-
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
271-
}
272-
println!("cargo:rustc-cfg={}", cfg);
278+
assert!(
279+
ALLOWED_CFGS.contains(&cfg),
280+
"trying to set cfg {cfg}, but it is not in ALLOWED_CFGS",
281+
);
282+
println!("cargo:rustc-cfg={cfg}");
273283
}

ci/install-musl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ case ${1} in
1010
musl_version=1.2.5
1111
;;
1212
*)
13-
musl_version=1.1.24
13+
[ -n "${RUST_LIBC_UNSTABLE_MUSL_V1_2_3:-}" ] && musl_version=1.2.3 || musl_version=1.1.24
1414
;;
1515
esac
1616

1717
musl="musl-${musl_version}"
1818

1919
# Download, configure, build, and install musl:
20-
curl --retry 5 https://www.musl-libc.org/releases/${musl}.tar.gz | tar xzf -
20+
curl --retry 5 "https://www.musl-libc.org/releases/${musl}.tar.gz" | tar xzf -
2121

2222
cd "$musl"
2323
case ${1} in

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/runtest-android.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ fn main() {
3737
let stderr = String::from_utf8_lossy(&output.stderr);
3838

3939
println!(
40-
"status: {}\nstdout ---\n{}\nstderr ---\n{}",
41-
output.status, stdout, stderr
40+
"status: {}\nstdout ---\n{stdout}\nstderr ---\n{stderr}",
41+
output.status,
4242
);
4343

4444
if !stderr.lines().any(|l| {

ci/style.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ while IFS= read -r file; do
2626

2727
# Turn all braced macro `foo! { /* ... */ }` invocations into
2828
# `fn foo_fmt_tmp() { /* ... */ }`.
29-
perl -pi -e 's/(?!macro_rules)\b(\w+)!\s*\{/fn $1_fmt_tmp() {/g' "$file"
29+
perl -pi -e 's/(?!macro_rules|c_enum)\b(\w+)!\s*\{/fn $1_fmt_tmp() {/g' "$file"
3030

3131
# Replace `if #[cfg(...)]` within `cfg_if` with `if cfg_tmp!([...])` which
3232
# `rustfmt` will format. We put brackets within the parens so it is easy to
@@ -59,12 +59,9 @@ done < "$tmpfile"
5959

6060
rm "$tmpfile"
6161

62-
if shellcheck --version ; then
63-
find . -name '*.sh' -print0 | xargs -0 shellcheck
64-
else
65-
echo "shellcheck not found"
66-
exit 1
67-
fi
62+
# Run once from workspace root to get everything that wasn't handled as an
63+
# individual file.
64+
cargo fmt
6865

6966
# Ensure that `sort` output is not locale-dependent
7067
export LC_ALL=C
@@ -87,3 +84,10 @@ for file in libc-test/semver/*.txt; do
8784
exit 1
8885
fi
8986
done
87+
88+
if shellcheck --version ; then
89+
find . -name '*.sh' -print0 | xargs -0 shellcheck
90+
else
91+
echo "shellcheck not found"
92+
exit 1
93+
fi

libc-test/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,10 @@ harness = true
104104
name = "style_tests"
105105
path = "test/style_tests.rs"
106106
harness = true
107+
108+
# FIXME(msrv): These should be moved to the root Cargo.toml as `[workspace.lints.*]`
109+
# once MSRV is above 1.64 and replaced with `[lints] workspace=true`
110+
111+
[lints.rust]
112+
113+
[lints.clippy]

0 commit comments

Comments
 (0)