Skip to main content

miden_assembly/linker/
library.rs

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