// Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT use heck::AsShoutySnakeCase; use heck::AsSnakeCase; use heck::ToSnakeCase; use once_cell::sync::OnceCell; use std::{path::Path, sync::Mutex}; static CHECKED_FEATURES: OnceCell>> = OnceCell::new(); // checks if the given Cargo feature is enabled. fn has_feature(feature: &str) -> bool { CHECKED_FEATURES .get_or_init(Default::default) .lock() .unwrap() .push(feature.to_string()); // when a feature is enabled, Cargo sets the `CARGO_FEATURE_-` // and aliased as `_`. // // The `-all` feature is also aliased to `_all`. // // If any of the features is enabled, the `_any` alias is created. // // Note that both `module` and `apis` strings must be written in kebab case. fn alias_module(module: &str, apis: &[&str], api_all: bool) { let all_feature_name = format!("{}-all", module); let all = has_feature(&all_feature_name) || api_all; alias(&all_feature_name.to_snake_case(), all); let mut any = all; for api in apis { let has = has_feature(&format!("{}-{}", module, api)) || all; alias( &format!("{}_{}", AsSnakeCase(module), AsSnakeCase(api)), has, ); any = any || has; } alias(&format!("{}_any", AsSnakeCase(module)), any); }