Skip to content

Commit 18ecd40

Browse files
committed
test-distro: build without cross toolchain
Make the xz2 dependency optional to allow building without a C cross compiler. This allows clippy.sh to be used on e.g. macOS more easily: ``` ./clippy.sh --target x86_64-unknown-linux-gnu --exclude-features xz2 ```
1 parent 0099193 commit 18ecd40

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

test-distro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ nix = { workspace = true, features = [
3535
] }
3636
object = { workspace = true, features = ["elf", "read_core", "std"] }
3737
walkdir = { workspace = true }
38-
xz2 = { workspace = true }
38+
xz2 = { workspace = true, optional = true } # Optional to allow building without a cross toolchain.

test-distro/src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,25 @@ pub fn read_to_end(path: &std::path::Path, compressed: bool) -> anyhow::Result<V
3737
let mut contents = Vec::new();
3838

3939
if compressed {
40-
let stat = f.metadata().context("metadata()")?;
41-
#[expect(clippy::manual_ok_err)]
42-
let len = match usize::try_from(stat.len()) {
43-
Ok(len) => Some(len),
44-
Err(std::num::TryFromIntError { .. }) => None,
40+
#[cfg(feature = "xz2")]
41+
{
42+
let stat = f.metadata().context("metadata()")?;
43+
#[expect(clippy::manual_ok_err)]
44+
let len = match usize::try_from(stat.len()) {
45+
Ok(len) => Some(len),
46+
Err(std::num::TryFromIntError { .. }) => None,
47+
}
48+
.and_then(|len| len.checked_mul(2))
49+
.ok_or_else(|| anyhow::anyhow!("2 * {stat:?}.len() is too large to fit in a usize"))?;
50+
contents.reserve(len);
51+
52+
xz2::read::XzDecoder::new(f).read_to_end(&mut contents)
4553
}
46-
.and_then(|len| len.checked_mul(2))
47-
.ok_or_else(|| anyhow::anyhow!("2 * {stat:?}.len() is too large to fit in a usize"))?;
48-
contents.reserve(len);
4954

50-
xz2::read::XzDecoder::new(f).read_to_end(&mut contents)
55+
#[cfg(not(feature = "xz2"))]
56+
{
57+
anyhow::bail!("cannot read {} without xz2 feature", path.display());
58+
}
5159
} else {
5260
f.read_to_end(&mut contents)
5361
}

0 commit comments

Comments
 (0)