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, GoConfig,
30 JavaConfig, KotlinConfig, NodeConfig, PhpConfig, PythonConfig, RConfig, RubyConfig, SwiftConfig, WasmConfig,
31 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 go: Option<GoConfig>,
86 pub java: Option<JavaConfig>,
87 pub dart: Option<DartConfig>,
88 pub kotlin: Option<KotlinConfig>,
89 pub swift: Option<SwiftConfig>,
90 pub csharp: Option<CSharpConfig>,
91 pub r: Option<RConfig>,
92 pub zig: Option<ZigConfig>,
93
94 // -----------------------------------------------------------------
95 // Filters
96 // -----------------------------------------------------------------
97 pub exclude: ExcludeConfig,
98 pub include: IncludeConfig,
99
100 /// Resolved output directory per language code (`"python"` → `packages/python/spikard/`).
101 /// Only contains entries for languages this crate actually targets.
102 pub output_paths: HashMap<String, PathBuf>,
103
104 /// Raw user-supplied per-language output paths from `[crates.output]`.
105 ///
106 /// Distinct from [`Self::output_paths`]: this preserves the original (possibly
107 /// `None`) value so methods that need to distinguish "user explicitly set this
108 /// path" from "template-derived" can do so. Used by [`Self::ffi_lib_name`] and
109 /// any other consumer that derives identifiers from the user-supplied path.
110 pub explicit_output: OutputConfig,
111
112 // -----------------------------------------------------------------
113 // Pipelines (workspace defaults merged with per-crate overrides)
114 // -----------------------------------------------------------------
115 pub lint: HashMap<String, LintConfig>,
116 pub test: HashMap<String, TestConfig>,
117 pub setup: HashMap<String, SetupConfig>,
118 pub update: HashMap<String, UpdateConfig>,
119 pub clean: HashMap<String, CleanConfig>,
120 pub build_commands: HashMap<String, BuildCommandConfig>,
121
122 // -----------------------------------------------------------------
123 // Generation flags
124 // -----------------------------------------------------------------
125 pub generate: GenerateConfig,
126 pub generate_overrides: HashMap<String, GenerateConfig>,
127 pub format: FormatConfig,
128 pub format_overrides: HashMap<String, FormatConfig>,
129 pub dto: DtoConfig,
130
131 // -----------------------------------------------------------------
132 // Workspace concerns surfaced to the crate (read-only inheritance)
133 // -----------------------------------------------------------------
134 pub tools: ToolsConfig,
135 pub opaque_types: HashMap<String, String>,
136 pub sync: Option<SyncConfig>,
137
138 // -----------------------------------------------------------------
139 // Packaging, e2e, extensibility
140 // -----------------------------------------------------------------
141 pub publish: Option<PublishConfig>,
142 pub e2e: Option<E2eConfig>,
143 pub adapters: Vec<AdapterConfig>,
144 pub trait_bridges: Vec<TraitBridgeConfig>,
145 pub scaffold: Option<ScaffoldConfig>,
146 pub readme: Option<ReadmeConfig>,
147 pub custom_files: HashMap<String, Vec<PathBuf>>,
148 pub custom_modules: CustomModulesConfig,
149 pub custom_registrations: CustomRegistrationsConfig,
150}
151
152impl ResolvedCrateConfig {
153 /// Convenience accessor: the resolved output directory for a language.
154 /// Returns `None` if this crate does not target the language.
155 pub fn output_for(&self, lang: &str) -> Option<&std::path::Path> {
156 self.output_paths.get(lang).map(|p| p.as_path())
157 }
158
159 /// Whether this crate targets the given language.
160 pub fn targets(&self, lang: Language) -> bool {
161 self.languages.contains(&lang)
162 }
163}