Skip to main content

miden_assembly/linker/
library.rs

1use alloc::{sync::Arc, vec::Vec};
2
3use miden_assembly_syntax::module::ModuleDescriptor;
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    /// Returns the digest of the package's exported interface.
36    #[inline(always)]
37    pub fn interface_digest(&self) -> Result<Word, ManifestValidationError> {
38        self.package.interface_digest()
39    }
40
41    #[inline(always)]
42    pub fn mast(&self) -> &Arc<MastForest> {
43        self.package.mast_forest()
44    }
45
46    #[inline]
47    pub fn module_descriptors(&self) -> Result<Vec<ModuleDescriptor>, ManifestValidationError> {
48        self.package.try_module_descriptors()
49    }
50}