Skip to content

Commit a9f3f46

Browse files
authored
cpubits: vendor the full cfg_if! macro (#1429)
If we do this, we can potentially drop `cfg-if` as a dependency from crates that use `cpubits`, which would cut down on the impression of the total number of dependencies those crates have.
1 parent 27e5257 commit a9f3f46

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cpubits/src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,37 @@ macro_rules! cpubits {
230230
};
231231
}
232232

233-
/// Vendored partial copy of the `cfg_if::cfg_if` macro.
233+
/// Vendored copy of the `cfg_if::cfg_if` macro.
234234
/// Copyright (c) 2014 Alex Crichton. Dual-licensed Apache 2.0 + MIT.
235+
///
236+
/// NOTE: though this is marked `doc(hidden)`, it is considered a stable part of the public API.
235237
#[doc(hidden)]
236238
#[macro_export]
237239
macro_rules! cfg_if {
240+
// NOTE(cpubits): we deliberately include the original frontend even though we don't use it
241+
// internally within this crate so consumers of `cpubits` can use the vendored `cfg_if` instead
242+
// of requiring both `cpubits` and `cfg-if`.
243+
(
244+
if #[cfg( $($i_meta:tt)+ )] { $( $i_tokens:tt )* }
245+
$(
246+
else if #[cfg( $($ei_meta:tt)+ )] { $( $ei_tokens:tt )* }
247+
)*
248+
$(
249+
else { $( $e_tokens:tt )* }
250+
)?
251+
) => {
252+
$crate::cfg_if! {
253+
@__items () ;
254+
(( $($i_meta)+ ) ( $( $i_tokens )* )),
255+
$(
256+
(( $($ei_meta)+ ) ( $( $ei_tokens )* )),
257+
)*
258+
$(
259+
(() ( $( $e_tokens )* )),
260+
)?
261+
}
262+
};
263+
238264
// Internal and recursive macro to emit all the items
239265
//
240266
// Collects all the previous cfgs in a list at the beginning, so they can be

0 commit comments

Comments
 (0)