rust(deps): move macros into a separate file

This commit is contained in:
figsoda 2023-07-01 10:34:34 -04:00
parent 786cae41c3
commit a669786383
3 changed files with 66 additions and 51 deletions

View File

@ -1,59 +1,10 @@
use cargo::core::{PackageId, Resolve};
use semver::Version;
use crate::inputs::AllInputs;
use crate::{inputs::AllInputs, macros::input_macros};
pub(super) fn load_rust_dependency(inputs: &mut AllInputs, resolve: &Resolve, pkg: PackageId) {
macro_rules! input {
($key:ident: $($input:expr),+) => {
input!($key: $($input),+; always)
};
($key:ident: $($input:expr),+; $sys:ident) => {{
$(
inputs.$key.$sys.insert($input.into());
)+
}};
}
macro_rules! environ {
($name:expr, $value:expr) => {
environ!($name, $value;);
};
($name:expr, $value:expr; $($tt:tt)*) => {
inputs.env.insert(
$name.into(),
($value.into(), vec![$($tt)*]),
);
};
}
// native build inputs
macro_rules! native_build {
($($tt:tt)+) => {
input!(native_build_inputs: $($tt)+)
};
}
// build inputs
macro_rules! build {
($($tt:tt)+) => {
input!(build_inputs: $($tt)+)
};
}
// apple frameworks
macro_rules! framework {
($($input:literal),+) => {
build!($(concat!("darwin.apple_sdk.frameworks.", $input)),+; darwin)
};
}
// gstreamer libraries
macro_rules! gst {
($($input:literal),+) => {
build!($(concat!("gst_all_1.", $input)),+)
};
}
input_macros!(inputs);
match &*pkg.name() {
"alsa-sys" => build!("alsa-lib"; linux),

63
src/macros.rs Normal file
View File

@ -0,0 +1,63 @@
/// define a set af macros to work with inputs
macro_rules! input_macros {
// workaround to escape `$`
// so it can be used with nested macro_rules
($inputs:ident) => {
input_macros!(($) $inputs);
};
(($_:tt) $inputs:ident) => {
macro_rules! input {
($key:ident: $_($input:expr),+) => {
input!($key: $_($input),+; always)
};
($key:ident: $_($input:expr),+; $sys:ident) => {{
$_(
$inputs.$key.$sys.insert($input.into());
)+
}};
}
macro_rules! environ {
($name:expr, $value:expr) => {
environ!($name, $value;);
};
($name:expr, $value:expr; $_($tt:tt)*) => {
$inputs.env.insert(
$name.into(),
($value.into(), vec![$_($tt)*]),
);
};
}
// native build inputs
macro_rules! native_build {
($_($tt:tt)+) => {
input!(native_build_inputs: $_($tt)+)
};
}
// build inputs
macro_rules! build {
($_($tt:tt)+) => {
input!(build_inputs: $_($tt)+)
};
}
// apple frameworks
macro_rules! framework {
($_($input:literal),+) => {
build!($_(concat!("darwin.apple_sdk.frameworks.", $input)),+; darwin)
};
}
// gstreamer libraries
macro_rules! gst {
($_($input:literal),+) => {
build!($_(concat!("gst_all_1.", $input)),+)
};
}
};
}
pub(crate) use input_macros;

View File

@ -6,6 +6,7 @@ mod fetcher;
mod inputs;
mod lang;
mod license;
mod macros;
mod prompt;
mod utils;