python_packaging/
libpython.rs1use {
12 crate::licensing::LicensedComponents,
13 simple_file_manifest::FileData,
14 std::{
15 collections::{BTreeMap, BTreeSet},
16 path::PathBuf,
17 },
18};
19
20#[derive(Clone, Debug, Default, PartialEq)]
25pub struct LibPythonBuildContext {
26 pub inittab_cflags: Option<Vec<String>>,
28
29 pub includes: BTreeMap<PathBuf, FileData>,
33
34 pub object_files: Vec<FileData>,
36
37 pub library_search_paths: BTreeSet<PathBuf>,
39
40 pub system_libraries: BTreeSet<String>,
42
43 pub dynamic_libraries: BTreeSet<String>,
45
46 pub static_libraries: BTreeSet<String>,
48
49 pub frameworks: BTreeSet<String>,
53
54 pub init_functions: BTreeMap<String, String>,
59
60 pub licensed_components: LicensedComponents,
62}
63
64impl LibPythonBuildContext {
65 pub fn merge(contexts: &[&Self]) -> Self {
67 let mut inittab_cflags = None;
68 let mut includes = BTreeMap::new();
69 let mut object_files = Vec::new();
70 let mut library_search_paths = BTreeSet::new();
71 let mut system_libraries = BTreeSet::new();
72 let mut dynamic_libraries = BTreeSet::new();
73 let mut static_libraries = BTreeSet::new();
74 let mut frameworks = BTreeSet::new();
75 let mut init_functions = BTreeMap::new();
76 let mut licensed_components = LicensedComponents::default();
77
78 for context in contexts {
79 if let Some(flags) = &context.inittab_cflags {
81 inittab_cflags = Some(flags.clone());
82 }
83 for (k, v) in &context.includes {
84 includes.insert(k.clone(), v.clone());
85 }
86 for o in &context.object_files {
87 object_files.push(o.clone());
88 }
89 for p in &context.library_search_paths {
90 library_search_paths.insert(p.clone());
91 }
92 for l in &context.system_libraries {
93 system_libraries.insert(l.clone());
94 }
95 for l in &context.dynamic_libraries {
96 dynamic_libraries.insert(l.clone());
97 }
98 for l in &context.static_libraries {
99 static_libraries.insert(l.clone());
100 }
101 for f in &context.frameworks {
102 frameworks.insert(f.clone());
103 }
104 for (k, v) in &context.init_functions {
105 init_functions.insert(k.clone(), v.clone());
106 }
107 for c in context.licensed_components.iter_components() {
108 licensed_components.add_component(c.clone());
109 }
110 }
111
112 Self {
113 inittab_cflags,
114 includes,
115 object_files,
116 library_search_paths,
117 system_libraries,
118 dynamic_libraries,
119 static_libraries,
120 frameworks,
121 init_functions,
122 licensed_components,
123 }
124 }
125}