|
1 | 1 | use std::{collections::BTreeMap, fmt::Display, ops::Deref, sync::Arc}; |
2 | 2 |
|
3 | 3 | use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; |
4 | | -use zpm_utils::{AbstractValue, Container, DataType, FromFileString, IoResultExt, Path, RawString, Serialized, ToFileString, ToHumanString, tree}; |
| 4 | +use zpm_utils::{AbstractValue, Container, Cpu, DataType, FromFileString, IoResultExt, Libc, Os, Path, RawString, Serialized, System, ToFileString, ToHumanString, tree}; |
5 | 5 |
|
6 | 6 | #[derive(Debug, Clone)] |
7 | 7 | pub struct ConfigurationContext { |
@@ -698,6 +698,66 @@ macro_rules! merge_settings { |
698 | 698 |
|
699 | 699 | include!(concat!(env!("OUT_DIR"), "/schema.rs")); |
700 | 700 |
|
| 701 | +impl SupportedArchitectures { |
| 702 | + pub fn to_systems(&self) -> Vec<System> { |
| 703 | + let mut systems |
| 704 | + = Vec::new(); |
| 705 | + |
| 706 | + let current |
| 707 | + = System::from_current(); |
| 708 | + |
| 709 | + let cpus = if self.cpu.is_empty() { |
| 710 | + vec![&Cpu::Current] |
| 711 | + } else { |
| 712 | + self.cpu.iter().map(|c| &c.value).collect() |
| 713 | + }; |
| 714 | + |
| 715 | + let os = if self.os.is_empty() { |
| 716 | + vec![&Os::Current] |
| 717 | + } else { |
| 718 | + self.os.iter().map(|o| &o.value).collect() |
| 719 | + }; |
| 720 | + |
| 721 | + let libc = if self.libc.is_empty() { |
| 722 | + vec![&Libc::Current] |
| 723 | + } else { |
| 724 | + self.libc.iter().map(|l| &l.value).collect() |
| 725 | + }; |
| 726 | + |
| 727 | + for &cpu in &cpus { |
| 728 | + for &os in &os { |
| 729 | + for &libc in &libc { |
| 730 | + let arch = if cpu == &Cpu::Current { |
| 731 | + current.arch.clone() |
| 732 | + } else { |
| 733 | + Some(cpu.clone()) |
| 734 | + }; |
| 735 | + |
| 736 | + let os = if os == &Os::Current { |
| 737 | + current.os.clone() |
| 738 | + } else { |
| 739 | + Some(os.clone()) |
| 740 | + }; |
| 741 | + |
| 742 | + let libc = if libc == &Libc::Current { |
| 743 | + current.libc.clone() |
| 744 | + } else { |
| 745 | + Some(libc.clone()) |
| 746 | + }; |
| 747 | + |
| 748 | + systems.push(System { |
| 749 | + arch, |
| 750 | + os, |
| 751 | + libc, |
| 752 | + }); |
| 753 | + } |
| 754 | + } |
| 755 | + } |
| 756 | + |
| 757 | + systems |
| 758 | + } |
| 759 | +} |
| 760 | + |
701 | 761 | pub struct Configuration { |
702 | 762 | pub settings: Settings, |
703 | 763 | pub user_config_path: Option<Path>, |
@@ -846,11 +906,11 @@ merge_settings!(zpm_primitives::Reference, |s: &str| FromFileString::from_file_s |
846 | 906 |
|
847 | 907 | merge_settings!(zpm_semver::RangeKind, |s: &str| FromFileString::from_file_string(s).unwrap()); |
848 | 908 |
|
849 | | -merge_settings!(zpm_utils::Secret<String>, |s: &str| FromFileString::from_file_string(s).unwrap()); |
| 909 | +merge_settings!(zpm_utils::Cpu, |s: &str| FromFileString::from_file_string(s).unwrap()); |
850 | 910 | merge_settings!(zpm_utils::Glob, |s: &str| FromFileString::from_file_string(s).unwrap()); |
| 911 | +merge_settings!(zpm_utils::Libc, |s: &str| FromFileString::from_file_string(s).unwrap()); |
| 912 | +merge_settings!(zpm_utils::Os, |s: &str| FromFileString::from_file_string(s).unwrap()); |
| 913 | +merge_settings!(zpm_utils::Secret<String>, |s: &str| FromFileString::from_file_string(s).unwrap()); |
851 | 914 |
|
852 | 915 | merge_settings!(crate::types::NodeLinker, |s: &str| FromFileString::from_file_string(s).unwrap()); |
853 | 916 | merge_settings!(crate::types::PnpFallbackMode, |s: &str| FromFileString::from_file_string(s).unwrap()); |
854 | | -merge_settings!(crate::types::Cpu, |s: &str| FromFileString::from_file_string(s).unwrap()); |
855 | | -merge_settings!(crate::types::Libc, |s: &str| FromFileString::from_file_string(s).unwrap()); |
856 | | -merge_settings!(crate::types::Os, |s: &str| FromFileString::from_file_string(s).unwrap()); |
|
0 commit comments