alef_core/config/resolved/mod.rs
1//! `ResolvedCrateConfig` — the per-crate view that backends consume.
2//!
3//! Every backend in `alef-backend-*`, every codegen pass, scaffold step,
4//! e2e generator, and publish step takes a `&ResolvedCrateConfig`. The
5//! resolved view is what you get after merging a [`crate::config::raw_crate::RawCrateConfig`]
6//! with the workspace [`crate::config::workspace::WorkspaceConfig`] defaults.
7//!
8//! Resolution merges values *into* a per-crate value. Workspace defaults
9//! that the crate did not override are folded in. Output paths are
10//! resolved through the workspace [`crate::config::output::OutputTemplate`]
11//! unless the crate set an explicit path in its `[crates.output]` table.
12
13pub mod ffi;
14pub mod fields;
15pub mod identifiers;
16pub mod imports;
17pub mod lookups;
18pub mod naming;
19
20use serde::{Deserialize, Serialize};
21use std::collections::HashMap;
22use std::path::PathBuf;
23
24use crate::config::SourceCrate;
25use crate::config::dto::DtoConfig;
26use crate::config::e2e::E2eConfig;
27use crate::config::extras::{AdapterConfig, Language};
28use crate::config::languages::{
29 CSharpConfig, CustomModulesConfig, CustomRegistrationsConfig, DartConfig, ElixirConfig, FfiConfig, GleamConfig,
30 GoConfig, JavaConfig, KotlinConfig, NodeConfig, PhpConfig, PythonConfig, RConfig, RubyConfig, SwiftConfig,
31 WasmConfig, ZigConfig,
32};
33use crate::config::output::{
34 BuildCommandConfig, CleanConfig, ExcludeConfig, IncludeConfig, LintConfig, OutputConfig, ReadmeConfig,
35 ScaffoldConfig, SetupConfig, SyncConfig, TestConfig, UpdateConfig,
36};
37use crate::config::publish::PublishConfig;
38use crate::config::tools::ToolsConfig;
39use crate::config::trait_bridge::TraitBridgeConfig;
40use crate::config::{FormatConfig, GenerateConfig};
41
42/// Fully-resolved configuration for one crate.
43///
44/// Backends consume `&ResolvedCrateConfig`; they should not need to look at
45/// the workspace defaults directly. Anything a backend reads has already been
46/// merged in by [`crate::config::NewAlefConfig::resolve`].
47///
48/// `output_paths` is precomputed: for every language this crate targets, the
49/// map holds the resolved output directory (with `{crate}` and `{lang}`
50/// placeholders substituted).
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct ResolvedCrateConfig {
53 // -----------------------------------------------------------------
54 // Identity
55 // -----------------------------------------------------------------
56 pub name: String,
57 pub sources: Vec<PathBuf>,
58 pub source_crates: Vec<SourceCrate>,
59 pub version_from: String,
60 pub core_import: Option<String>,
61 pub workspace_root: Option<PathBuf>,
62 pub skip_core_import: bool,
63 pub error_type: Option<String>,
64 pub error_constructor: Option<String>,
65 pub features: Vec<String>,
66 pub path_mappings: HashMap<String, String>,
67 pub extra_dependencies: HashMap<String, toml::Value>,
68 pub auto_path_mappings: bool,
69
70 // -----------------------------------------------------------------
71 // Languages targeted by this crate
72 // -----------------------------------------------------------------
73 pub languages: Vec<Language>,
74
75 // -----------------------------------------------------------------
76 // Per-language settings (workspace defaults already merged)
77 // -----------------------------------------------------------------
78 pub python: Option<PythonConfig>,
79 pub node: Option<NodeConfig>,
80 pub ruby: Option<RubyConfig>,
81 pub php: Option<PhpConfig>,
82 pub elixir: Option<ElixirConfig>,
83 pub wasm: Option<WasmConfig>,
84 pub ffi: Option<FfiConfig>,
85 pub gleam: Option<GleamConfig>,
86 pub go: Option<GoConfig>,
87 pub java: Option<JavaConfig>,
88 pub dart: Option<DartConfig>,
89 pub kotlin: Option<KotlinConfig>,
90 pub swift: Option<SwiftConfig>,
91 pub csharp: Option<CSharpConfig>,
92 pub r: Option<RConfig>,
93 pub zig: Option<ZigConfig>,
94
95 // -----------------------------------------------------------------
96 // Filters
97 // -----------------------------------------------------------------
98 pub exclude: ExcludeConfig,
99 pub include: IncludeConfig,
100
101 /// Resolved output directory per language code (`"python"` → `packages/python/spikard/`).
102 /// Only contains entries for languages this crate actually targets.
103 pub output_paths: HashMap<String, PathBuf>,
104
105 /// Raw user-supplied per-language output paths from `[crates.output]`.
106 ///
107 /// Distinct from [`Self::output_paths`]: this preserves the original (possibly
108 /// `None`) value so methods that need to distinguish "user explicitly set this
109 /// path" from "template-derived" can do so. Used by [`Self::ffi_lib_name`] and
110 /// any other consumer that derives identifiers from the user-supplied path.
111 pub explicit_output: OutputConfig,
112
113 // -----------------------------------------------------------------
114 // Pipelines (workspace defaults merged with per-crate overrides)
115 // -----------------------------------------------------------------
116 pub lint: HashMap<String, LintConfig>,
117 pub test: HashMap<String, TestConfig>,
118 pub setup: HashMap<String, SetupConfig>,
119 pub update: HashMap<String, UpdateConfig>,
120 pub clean: HashMap<String, CleanConfig>,
121 pub build_commands: HashMap<String, BuildCommandConfig>,
122
123 // -----------------------------------------------------------------
124 // Generation flags
125 // -----------------------------------------------------------------
126 pub generate: GenerateConfig,
127 pub generate_overrides: HashMap<String, GenerateConfig>,
128 pub format: FormatConfig,
129 pub format_overrides: HashMap<String, FormatConfig>,
130 pub dto: DtoConfig,
131
132 // -----------------------------------------------------------------
133 // Workspace concerns surfaced to the crate (read-only inheritance)
134 // -----------------------------------------------------------------
135 pub tools: ToolsConfig,
136 pub opaque_types: HashMap<String, String>,
137 pub sync: Option<SyncConfig>,
138
139 // -----------------------------------------------------------------
140 // Packaging, e2e, extensibility
141 // -----------------------------------------------------------------
142 pub publish: Option<PublishConfig>,
143 pub e2e: Option<E2eConfig>,
144 pub adapters: Vec<AdapterConfig>,
145 pub trait_bridges: Vec<TraitBridgeConfig>,
146 pub scaffold: Option<ScaffoldConfig>,
147 pub readme: Option<ReadmeConfig>,
148 pub custom_files: HashMap<String, Vec<PathBuf>>,
149 pub custom_modules: CustomModulesConfig,
150 pub custom_registrations: CustomRegistrationsConfig,
151}
152
153impl ResolvedCrateConfig {
154 /// Convenience accessor: the resolved output directory for a language.
155 /// Returns `None` if this crate does not target the language.
156 pub fn output_for(&self, lang: &str) -> Option<&std::path::Path> {
157 self.output_paths.get(lang).map(|p| p.as_path())
158 }
159
160 /// Whether this crate targets the given language.
161 pub fn targets(&self, lang: Language) -> bool {
162 self.languages.contains(&lang)
163 }
164}