Skip to main content

miden_project/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5#[cfg(any(test, feature = "std"))]
6extern crate std;
7
8#[cfg(feature = "serde")]
9pub mod ast;
10mod dependencies;
11mod linkage;
12mod package;
13mod profile;
14mod target;
15mod target_type;
16#[cfg(all(test, feature = "std", feature = "serde"))]
17mod tests;
18mod workspace;
19
20use alloc::{sync::Arc, vec::Vec};
21
22#[cfg(feature = "serde")]
23use miden_assembly_syntax::{
24    Report,
25    debuginfo::{SourceFile, SourceId},
26    diagnostics::{Label, RelatedError, RelatedLabel},
27};
28// Re-exported for consistency
29pub use miden_assembly_syntax::{Word, debuginfo::Uri, semver};
30use miden_assembly_syntax::{
31    debuginfo::{SourceSpan, Span},
32    diagnostics::{Diagnostic, miette},
33};
34pub use miden_core::LexicographicWord;
35#[cfg(feature = "serde")]
36use serde::{Deserialize, Serialize};
37pub use toml::Value;
38
39pub use self::{
40    dependencies::*, linkage::Linkage, package::Package, profile::Profile, target::Target,
41    target_type::TargetType, workspace::Workspace,
42};
43
44/// An alias for [`alloc::collections::BTreeMap`].
45pub type Map<K, V> = alloc::collections::BTreeMap<K, V>;
46
47/// Represents arbitrary metadata in key/value format
48///
49/// This representation provides spans for both keys and values
50pub type Metadata = Map<Span<Arc<str>>, Span<Value>>;
51
52/// Represents a set of named metadata tables, where each table is represented by [Metadata].
53///
54/// This representation provides spans for the table name, and each entry in that table's metadata.
55pub type MetadataSet = Map<Span<Arc<str>>, Metadata>;
56
57/// A utility function for making a path absolute and canonical.
58///
59/// Relative paths are made absolute relative to `workspace_root`.
60#[cfg(all(feature = "std", feature = "serde"))]
61pub(crate) fn absolutize_path(
62    path: &std::path::Path,
63    workspace_root: &std::path::Path,
64) -> Result<std::path::PathBuf, std::io::Error> {
65    if path.is_absolute() {
66        path.canonicalize()
67    } else {
68        workspace_root.join(path).canonicalize()
69    }
70}