Skip to main content

miden_assembly/linker/
library.rs

1use alloc::{sync::Arc, vec::Vec};
2
3use miden_assembly_syntax::module::ModuleInfo;
4use miden_mast_package::{ManifestValidationError, MastForest, Package};
5pub use miden_project::Linkage;
6
7/// Represents an assembled module or modules to use when resolving references while linking,
8/// as well as the method by which referenced symbols will be linked into the assembled MAST.
9#[derive(Clone)]
10pub struct LinkLibrary {
11    pub package: Arc<Package>,
12    /// How to link against this library
13    pub linkage: Linkage,
14}
15
16impl LinkLibrary {
17    /// Construct a [LinkLibrary] from a [miden_mast_package::Package]
18    pub fn from_package(package: Arc<Package>) -> Self {
19        Self { package, linkage: Linkage::Dynamic }
20    }
21
22    /// Modify the linkage of this library
23    pub fn with_linkage(mut self, linkage: Linkage) -> Self {
24        self.linkage = linkage;
25        self
26    }
27
28    #[inline(always)]
29    pub fn mast(&self) -> &Arc<MastForest> {
30        self.package.mast_forest()
31    }
32
33    #[inline]
34    pub fn module_infos(&self) -> Result<Vec<ModuleInfo>, ManifestValidationError> {
35        self.package.try_module_infos()
36    }
37}