Skip to content

Commit a226127

Browse files
remove cfg-if dependency by vendoring
1 parent c4a6977 commit a226127

File tree

7 files changed

+98
-8
lines changed

7 files changed

+98
-8
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ edition = "2021"
3535
[workspace.dependencies]
3636
afl = "0.15"
3737
arbitrary = { version = "1.4.1" }
38-
cfg-if = "1"
3938
tikv-jemallocator = "0.6.0"
4039
time = { version = "0.3.37", default-features = false }
4140
zip = { path = ".", default-features = false }

fuzz_read/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ publish = false
66

77
[dependencies]
88
afl.workspace = true
9-
cfg-if.workspace = true
10-
tikv-jemallocator.workspace = true
119
zip.workspace = true
1210

11+
[target.'cfg(fuzzing)'.dependencies]
12+
tikv-jemallocator.workspace = true
13+
1314
[features]
1415
zip-default = ["zip/default"]

fuzz_read/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
#[cfg(fuzzing)]
44
use afl::fuzz;
55
use std::io::{Read, Seek, SeekFrom};
6+
#[cfg(fuzzing)]
67
use tikv_jemallocator::Jemalloc;
78
use zip::read::read_zipfile_from_stream;
9+
use zip::macros::cfg_if;
810

911
const MAX_BYTES_TO_READ: u64 = 1 << 24;
1012

13+
#[cfg(fuzzing)]
1114
#[global_allocator]
1215
static GLOBAL: Jemalloc = Jemalloc;
1316

@@ -27,7 +30,7 @@ fn decompress_all(reader: impl Read + Seek) -> Result<(), Box<dyn std::error::Er
2730
}
2831

2932
fn main() {
30-
cfg_if::cfg_if! {
33+
cfg_if! {
3134
if #[cfg(fuzzing)] {
3235
fuzz!(|data: &[u8]| {
3336
let reader = std::io::Cursor::new(data);

fuzz_write/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ publish = false
77
[dependencies]
88
afl.workspace = true
99
arbitrary = { workspace = true, features = ["derive"] }
10-
cfg-if.workspace = true
1110
replace_with = "0.1.7"
12-
tikv-jemallocator.workspace = true
1311
zip = { workspace = true, features = ["arbitrary"] }
1412

13+
[target.'cfg(fuzzing)'.dependencies]
14+
tikv-jemallocator.workspace = true
15+
1516
[features]
1617
zip-default = ["zip/default"]

fuzz_write/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ use std::io::Write as IoWrite;
1010
use std::io::{Cursor, Seek, SeekFrom};
1111
use std::ops;
1212
use std::path::PathBuf;
13+
#[cfg(fuzzing)]
1314
use tikv_jemallocator::Jemalloc;
15+
use zip::macros::cfg_if;
1416
use zip::result::{ZipError, ZipResult};
1517
use zip::unstable::path_to_string;
1618
use zip::write::FullFileOptions;
1719

20+
#[cfg(fuzzing)]
1821
#[global_allocator]
1922
static GLOBAL: Jemalloc = Jemalloc;
2023

@@ -404,7 +407,7 @@ impl ops::Drop for StdoutWrite {
404407
}
405408

406409
fn main() {
407-
cfg_if::cfg_if! {
410+
cfg_if! {
408411
if #[cfg(fuzzing)] {
409412
let mut w = NoopWrite::default();
410413
fuzz!(|data: &[u8]| {

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//!
3232
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3333
#![warn(missing_docs)]
34-
#![allow(unexpected_cfgs)] // Needed for cfg(fuzzing) on nightly as of 2024-05-06
34+
#![allow(unexpected_cfgs)] // Needed for cfg(fuzzing)
3535
pub use crate::compression::{CompressionMethod, SUPPORTED_COMPRESSION_METHODS};
3636
pub use crate::read::HasZipMetadata;
3737
pub use crate::read::ZipArchive;
@@ -71,3 +71,6 @@ zip = \"="]
7171
#[doc = "\"\n\
7272
```"]
7373
pub mod unstable;
74+
75+
#[doc(hidden)]
76+
pub mod macros;

src/macros.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//! Macros used internally.
2+
//!
3+
//! These may technically be exported, but that's only to make them available to internal
4+
//! project dependencies. The `#[doc(hidden)]` mark indicates that these are not stable or supported
5+
//! APIs, and should not be relied upon by external dependees.
6+
7+
/// The single macro export of the [`cfg-if`](https://docs.rs/cfg-if) crate.
8+
///
9+
/// It is packaged here to avoid pulling in another dependency. The stdlib does the same[^1].
10+
///
11+
/// [^1]: https://github.com/rust-lang/rust/blob/a2db9280539229a3b8a084a09886670a57bc7e9c/library/compiler-builtins/libm/src/math/support/macros.rs#L1
12+
#[doc(hidden)]
13+
#[macro_export]
14+
macro_rules! cfg_if {
15+
// match if/else chains with a final `else`
16+
(
17+
$(
18+
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
19+
) else+
20+
else { $( $e_tokens:tt )* }
21+
) => {
22+
$crate::cfg_if! {
23+
@__items () ;
24+
$(
25+
(( $i_meta ) ( $( $i_tokens )* )) ,
26+
)+
27+
(() ( $( $e_tokens )* )) ,
28+
}
29+
};
30+
31+
// match if/else chains lacking a final `else`
32+
(
33+
if #[cfg( $i_meta:meta )] { $( $i_tokens:tt )* }
34+
$(
35+
else if #[cfg( $e_meta:meta )] { $( $e_tokens:tt )* }
36+
)*
37+
) => {
38+
$crate::cfg_if! {
39+
@__items () ;
40+
(( $i_meta ) ( $( $i_tokens )* )) ,
41+
$(
42+
(( $e_meta ) ( $( $e_tokens )* )) ,
43+
)*
44+
}
45+
};
46+
47+
// Internal and recursive macro to emit all the items
48+
//
49+
// Collects all the previous cfgs in a list at the beginning, so they can be
50+
// negated. After the semicolon are all the remaining items.
51+
(@__items ( $( $_:meta , )* ) ; ) => {};
52+
(
53+
@__items ( $( $no:meta , )* ) ;
54+
(( $( $yes:meta )? ) ( $( $tokens:tt )* )) ,
55+
$( $rest:tt , )*
56+
) => {
57+
// Emit all items within one block, applying an appropriate #[cfg]. The
58+
// #[cfg] will require all `$yes` matchers specified and must also negate
59+
// all previous matchers.
60+
#[cfg(all(
61+
$( $yes , )?
62+
not(any( $( $no ),* ))
63+
))]
64+
$crate::cfg_if! { @__identity $( $tokens )* }
65+
66+
// Recurse to emit all other items in `$rest`, and when we do so add all
67+
// our `$yes` matchers to the list of `$no` matchers as future emissions
68+
// will have to negate everything we just matched as well.
69+
$crate::cfg_if! {
70+
@__items ( $( $no , )* $( $yes , )? ) ;
71+
$( $rest , )*
72+
}
73+
};
74+
75+
// Internal macro to make __apply work out right for different match types,
76+
// because of how macros match/expand stuff.
77+
(@__identity $( $tokens:tt )* ) => {
78+
$( $tokens )*
79+
};
80+
}

0 commit comments

Comments
 (0)