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