wdl_engine/
lib.rs

1//! Execution engine for Workflow Description Language (WDL) documents.
2
3mod backend;
4pub mod config;
5pub mod diagnostics;
6mod eval;
7pub(crate) mod hash;
8pub(crate) mod http;
9mod inputs;
10mod outputs;
11pub mod path;
12mod stdlib;
13pub(crate) mod tree;
14mod units;
15mod value;
16
17use std::sync::LazyLock;
18
19pub use backend::*;
20pub use eval::*;
21pub use inputs::*;
22pub use outputs::*;
23use sysinfo::CpuRefreshKind;
24use sysinfo::MemoryRefreshKind;
25use sysinfo::System;
26pub use units::*;
27pub use value::*;
28use wdl_analysis::Document;
29use wdl_analysis::diagnostics::unknown_type;
30use wdl_analysis::types::Type;
31use wdl_analysis::types::TypeNameResolver;
32use wdl_analysis::types::v1::AstTypeConverter;
33use wdl_ast::Diagnostic;
34use wdl_ast::Span;
35use wdl_ast::TreeNode;
36
37/// One gibibyte (GiB) as a float.
38///
39/// This is defined as a constant as it's a commonly performed conversion.
40const ONE_GIBIBYTE: f64 = 1024.0 * 1024.0 * 1024.0;
41
42/// Resolves a type name from a document.
43///
44/// This function will import the type into the type cache if not already
45/// cached.
46fn resolve_type_name(document: &Document, name: &str, span: Span) -> Result<Type, Diagnostic> {
47    document
48        .struct_by_name(name)
49        .map(|s| s.ty().expect("struct should have type").clone())
50        .ok_or_else(|| unknown_type(name, span))
51}
52
53/// Converts a V1 AST type to an analysis type.
54fn convert_ast_type_v1<N: TreeNode>(
55    document: &Document,
56    ty: &wdl_ast::v1::Type<N>,
57) -> Result<Type, Diagnostic> {
58    /// Used to resolve a type name from a document.
59    struct Resolver<'a>(&'a Document);
60
61    impl TypeNameResolver for Resolver<'_> {
62        fn resolve(&mut self, name: &str, span: Span) -> Result<Type, Diagnostic> {
63            resolve_type_name(self.0, name, span)
64        }
65    }
66
67    AstTypeConverter::new(Resolver(document)).convert_type(ty)
68}
69
70/// Cached information about the host system.
71static SYSTEM: LazyLock<System> = LazyLock::new(|| {
72    let mut system = System::new();
73    system.refresh_cpu_list(CpuRefreshKind::nothing());
74    system.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());
75    system
76});