miden_assembly/linker/
library.rs

1use alloc::sync::Arc;
2
3use miden_assembly_syntax::Library;
4
5/// Represents an assembled module or modules to use when resolving references while linking,
6/// as well as the method by which referenced symbols will be linked into the assembled MAST.
7#[derive(Clone)]
8pub struct LinkLibrary {
9    /// The library to link
10    pub library: Arc<Library>,
11    /// How to link against this library
12    pub kind: LinkLibraryKind,
13}
14
15impl LinkLibrary {
16    /// Dynamically link against `library`
17    pub fn dynamic(library: Arc<Library>) -> Self {
18        Self { library, kind: LinkLibraryKind::Dynamic }
19    }
20
21    /// Statically link `library`
22    pub fn r#static(library: Arc<Library>) -> Self {
23        Self { library, kind: LinkLibraryKind::Static }
24    }
25}
26
27/// Represents how a library should be linked into the assembled MAST
28#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
29pub enum LinkLibraryKind {
30    /// A dynamically-linked library.
31    ///
32    /// References to symbols of dynamically-linked libraries expect to have those symbols resolved
33    /// at runtime, i.e. it is expected that the library was loaded (or will be loaded on-demand),
34    /// and that the referenced symbol is resolvable by the VM.
35    ///
36    /// Concretely, the digest corresponding to a referenced procedure symbol will be linked as a
37    /// [`miden_core::mast::ExternalNode`], rather than including the procedure in the assembled
38    /// MAST, and referencing the procedure via [`miden_core::mast::MastNodeId`].
39    #[default]
40    Dynamic,
41    /// A statically-linked library.
42    ///
43    /// References to symbols of statically-linked libraries expect to be resolvable by the linker,
44    /// during assembly, i.e. it is expected that the library was provided to the assembler/linker
45    /// as an input, and that the entire definition of the referenced symbol is available.
46    ///
47    /// Concretely, a statically linked procedure will have its root, and all reachable nodes found
48    /// in the MAST of the library, included in the assembled MAST, and referenced via
49    /// [`miden_core::mast::MastNodeId`].
50    ///
51    /// Statically linked symbols are thus merged into the assembled artifact as if they had been
52    /// defined in your own project, and the library they were originally defined in will not be
53    /// required to be provided at runtime, as is the case with dynamically-linked libraries.
54    Static,
55}