alef_core/config/languages.rs
1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::PathBuf;
4
5use super::extras::Language;
6
7/// Configuration for a single capsule type entry in `PythonConfig::capsule_types`.
8///
9/// Supports two TOML forms via `#[serde(untagged)]`:
10///
11/// - String: `Language = "tree_sitter.Language"` → capsule round-trip via `into_raw()`
12/// - Struct: `Parser = { python_type = "tree_sitter.Parser", construct_from = "Language" }` → Python-side construction
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(untagged)]
15pub enum CapsuleTypeConfig {
16 /// Capsule round-trip: the Rust type exposes `into_raw()` returning a raw pointer.
17 /// The generated code calls `PyCapsule_New(value.into_raw(), capsule_name, None)` on return,
18 /// and `PyCapsule_GetPointer` + `from_raw()` on input.
19 ///
20 /// Value is the fully-qualified Python capsule name (e.g. `"tree_sitter.Language"`).
21 Capsule(String),
22 /// Python-side construction: the type does not have a direct `into_raw()`.
23 /// Instead, the generated code constructs the Python type by calling a Python factory
24 /// (e.g. `tree_sitter.Parser(language)`) where `language` is a bound capsule argument.
25 ConstructFrom {
26 /// The fully-qualified Python type to import and call (e.g. `"tree_sitter.Parser"`).
27 python_type: String,
28 /// The capsule-type argument name to pass to the Python constructor.
29 /// Must be one of the other capsule-type entries (e.g. `"Language"`).
30 construct_from: String,
31 },
32}
33
34impl CapsuleTypeConfig {
35 /// Returns the Python type string (dotted path) for this config entry.
36 pub fn python_type(&self) -> &str {
37 match self {
38 Self::Capsule(name) => name,
39 Self::ConstructFrom { python_type, .. } => python_type,
40 }
41 }
42
43 /// Returns the `construct_from` dependency type name, if this is a `ConstructFrom` entry.
44 pub fn construct_from(&self) -> Option<&str> {
45 match self {
46 Self::ConstructFrom { construct_from, .. } => Some(construct_from.as_str()),
47 Self::Capsule(_) => None,
48 }
49 }
50
51 /// Returns true when this entry represents a raw capsule round-trip (not Python-side construction).
52 pub fn is_capsule_roundtrip(&self) -> bool {
53 matches!(self, Self::Capsule(_))
54 }
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PythonConfig {
59 pub module_name: Option<String>,
60 pub async_runtime: Option<String>,
61 pub stubs: Option<StubsConfig>,
62 /// PyPI package name (e.g. `"html-to-markdown"`). Used as the `[project] name` in
63 /// `pyproject.toml` and to derive the `python-packages` list for maturin.
64 /// Defaults to the crate name.
65 #[serde(default)]
66 pub pip_name: Option<String>,
67 /// Per-language feature override. When set, these features are used instead of
68 /// `[crate] features` for this language's binding crate.
69 #[serde(default)]
70 pub features: Option<Vec<String>>,
71 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
72 /// When set, this takes priority over the IR type-level serde_rename_all.
73 #[serde(default)]
74 pub serde_rename_all: Option<String>,
75 /// Map of type name -> capsule config for PyCapsule pass-through.
76 /// Types listed here are emitted as PyCapsule_New / PyCapsule_GetPointer instead of
77 /// opaque `#[pyclass]` wrappers. Use `CapsuleTypeConfig::Capsule` for raw capsule
78 /// round-trips and `CapsuleTypeConfig::ConstructFrom` for Python-side construction.
79 #[serde(default)]
80 pub capsule_types: HashMap<String, CapsuleTypeConfig>,
81 /// When true, wrap blocking function bodies in py.allow_threads() to release the GIL.
82 // TODO: Wire into gen_bindings.rs to emit py.allow_threads(|| { ... }) for non-async functions.
83 #[serde(default)]
84 pub release_gil: bool,
85 /// Functions to exclude from Python binding generation.
86 #[serde(default)]
87 pub exclude_functions: Vec<String>,
88 /// Types to exclude from Python binding generation.
89 #[serde(default)]
90 pub exclude_types: Vec<String>,
91 /// Additional Cargo dependencies for this language's binding crate only.
92 #[serde(default)]
93 pub extra_dependencies: HashMap<String, toml::Value>,
94 /// Override the scaffold output directory for this language's Cargo.toml and package files.
95 #[serde(default)]
96 pub scaffold_output: Option<PathBuf>,
97 /// Per-field name remapping for this language. Key is `TypeName.field_name` (e.g.
98 /// `"LayoutDetection.class"`), value is the desired binding field name. Applied after
99 /// automatic keyword escaping, so an explicit entry takes priority.
100 #[serde(default)]
101 pub rename_fields: HashMap<String, String>,
102 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
103 /// commands across all pipelines (lint, test, build, etc.).
104 /// E.g., `run_wrapper = "uv run --no-sync"` turns `ruff format packages/python` into
105 /// `uv run --no-sync ruff format packages/python`.
106 #[serde(default)]
107 pub run_wrapper: Option<String>,
108 /// Extra paths to append to default lint commands (format, check, typecheck).
109 /// Space-separated paths are appended to the command.
110 #[serde(default)]
111 pub extra_lint_paths: Vec<String>,
112 /// Additional `from <module> import <symbol>` lines to emit in the generated `__init__.py`.
113 /// Key is the relative or absolute Python module path (e.g. `"._supported_languages"`),
114 /// value is the list of symbols to import. The symbols are also added to `__all__`.
115 ///
116 /// Use this to re-export hand-written sibling modules (e.g. generated by a project's own
117 /// build script) without alef's cleanup culling them. The hand-written file must NOT contain
118 /// the substrings `"DO NOT EDIT"`, `"auto-generated by alef"`, or `"AUTO-GENERATED by alef"`
119 /// in its first 5 lines, or alef's cleanup pipeline will treat it as a stale alef artifact.
120 #[serde(default)]
121 pub extra_init_imports: std::collections::BTreeMap<String, Vec<String>>,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct StubsConfig {
126 pub output: PathBuf,
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct NodeConfig {
131 pub package_name: Option<String>,
132 /// Per-language feature override. When set, these features are used instead of
133 /// `[crate] features` for this language's binding crate.
134 #[serde(default)]
135 pub features: Option<Vec<String>>,
136 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
137 /// When set, this takes priority over the IR type-level serde_rename_all.
138 #[serde(default)]
139 pub serde_rename_all: Option<String>,
140 /// Prefix for generated type names (e.g. "Js" produces `JsConversionOptions`).
141 /// Defaults to `"Js"`.
142 #[serde(default)]
143 pub type_prefix: Option<String>,
144 /// Functions to exclude from Node binding generation.
145 #[serde(default)]
146 pub exclude_functions: Vec<String>,
147 /// Types to exclude from Node binding generation.
148 #[serde(default)]
149 pub exclude_types: Vec<String>,
150 /// Additional Cargo dependencies for this language's binding crate only.
151 #[serde(default)]
152 pub extra_dependencies: HashMap<String, toml::Value>,
153 /// Override the scaffold output directory for this language's Cargo.toml and package files.
154 #[serde(default)]
155 pub scaffold_output: Option<PathBuf>,
156 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
157 /// desired binding field name. Applied after automatic keyword escaping.
158 #[serde(default)]
159 pub rename_fields: HashMap<String, String>,
160 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
161 /// commands across all pipelines (lint, test, build, etc.).
162 #[serde(default)]
163 pub run_wrapper: Option<String>,
164 /// Extra paths to append to default lint commands (format, check, typecheck).
165 #[serde(default)]
166 pub extra_lint_paths: Vec<String>,
167}
168
169#[derive(Debug, Clone, Serialize, Deserialize)]
170pub struct RubyConfig {
171 pub gem_name: Option<String>,
172 pub stubs: Option<StubsConfig>,
173 /// Per-language feature override. When set, these features are used instead of
174 /// `[crate] features` for this language's binding crate.
175 #[serde(default)]
176 pub features: Option<Vec<String>>,
177 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
178 /// When set, this takes priority over the IR type-level serde_rename_all.
179 #[serde(default)]
180 pub serde_rename_all: Option<String>,
181 /// Functions to exclude from Ruby binding generation.
182 #[serde(default)]
183 pub exclude_functions: Vec<String>,
184 /// Types to exclude from Ruby binding generation.
185 #[serde(default)]
186 pub exclude_types: Vec<String>,
187 /// Additional Cargo dependencies for this language's binding crate only.
188 #[serde(default)]
189 pub extra_dependencies: HashMap<String, toml::Value>,
190 /// Override the scaffold output directory for this language's Cargo.toml and package files.
191 #[serde(default)]
192 pub scaffold_output: Option<PathBuf>,
193 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
194 /// desired binding field name. Applied after automatic keyword escaping.
195 #[serde(default)]
196 pub rename_fields: HashMap<String, String>,
197 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
198 /// commands across all pipelines (lint, test, build, etc.).
199 #[serde(default)]
200 pub run_wrapper: Option<String>,
201 /// Extra paths to append to default lint commands (format, check, typecheck).
202 #[serde(default)]
203 pub extra_lint_paths: Vec<String>,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
207pub struct PhpConfig {
208 pub extension_name: Option<String>,
209 /// Cargo crate name for the PHP binding (e.g. `"ts-pack-core-php"`).
210 /// Used to derive the shared library filename in the e2e test runner.
211 /// When absent, the lib name is derived from `extension_name` by appending `_php`.
212 #[serde(default)]
213 pub cargo_crate_name: Option<String>,
214 /// Override the PHP namespace used for class registration and PSR-4 autoloading.
215 ///
216 /// When set, this value is used verbatim as the PHP namespace (e.g. `"HtmlToMarkdown"`).
217 /// When absent, the namespace is derived from `extension_name` by splitting on `_` and
218 /// converting each segment to PascalCase (e.g. `html_to_markdown` → `Html\To\Markdown`).
219 #[serde(default)]
220 pub namespace: Option<String>,
221 /// Feature gate for ext-php-rs (default: "extension-module").
222 /// All generated code is wrapped in `#[cfg(feature = "...")]`.
223 #[serde(default)]
224 pub feature_gate: Option<String>,
225 /// Output directory for generated PHP facade / stubs (e.g., `packages/php/src/`).
226 #[serde(default)]
227 pub stubs: Option<StubsConfig>,
228 #[serde(default)]
229 pub features: Option<Vec<String>>,
230 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
231 /// When set, this takes priority over the IR type-level serde_rename_all.
232 #[serde(default)]
233 pub serde_rename_all: Option<String>,
234 /// Functions to exclude from PHP binding generation.
235 #[serde(default)]
236 pub exclude_functions: Vec<String>,
237 /// Types to exclude from PHP binding generation.
238 #[serde(default)]
239 pub exclude_types: Vec<String>,
240 /// Additional Cargo dependencies for this language's binding crate only.
241 #[serde(default)]
242 pub extra_dependencies: HashMap<String, toml::Value>,
243 /// Override the scaffold output directory for this language's Cargo.toml and package files.
244 #[serde(default)]
245 pub scaffold_output: Option<PathBuf>,
246 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
247 /// desired binding field name. Applied after automatic keyword escaping.
248 #[serde(default)]
249 pub rename_fields: HashMap<String, String>,
250 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
251 /// commands across all pipelines (lint, test, build, etc.).
252 #[serde(default)]
253 pub run_wrapper: Option<String>,
254 /// Extra paths to append to default lint commands (format, check, typecheck).
255 #[serde(default)]
256 pub extra_lint_paths: Vec<String>,
257}
258
259#[derive(Debug, Clone, Serialize, Deserialize)]
260pub struct ElixirConfig {
261 pub app_name: Option<String>,
262 #[serde(default)]
263 pub features: Option<Vec<String>>,
264 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
265 /// When set, this takes priority over the IR type-level serde_rename_all.
266 #[serde(default)]
267 pub serde_rename_all: Option<String>,
268 /// Functions to exclude from Elixir NIF generation.
269 #[serde(default)]
270 pub exclude_functions: Vec<String>,
271 /// Types to exclude from Elixir NIF generation.
272 #[serde(default)]
273 pub exclude_types: Vec<String>,
274 /// Additional Cargo dependencies for this language's binding crate only.
275 #[serde(default)]
276 pub extra_dependencies: HashMap<String, toml::Value>,
277 /// Override the scaffold output directory for this language's Cargo.toml and package files.
278 #[serde(default)]
279 pub scaffold_output: Option<PathBuf>,
280 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
281 /// desired binding field name. Applied after automatic keyword escaping.
282 #[serde(default)]
283 pub rename_fields: HashMap<String, String>,
284 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
285 /// commands across all pipelines (lint, test, build, etc.).
286 #[serde(default)]
287 pub run_wrapper: Option<String>,
288 /// Extra paths to append to default lint commands (format, check, typecheck).
289 #[serde(default)]
290 pub extra_lint_paths: Vec<String>,
291 /// Functions that should be scheduled on the dirty CPU scheduler.
292 /// HTML parsing and other CPU-intensive NIFs should be listed here to avoid
293 /// blocking BEAM scheduler threads.
294 #[serde(default)]
295 pub cpu_bound_functions: Vec<String>,
296}
297
298#[derive(Debug, Clone, Serialize, Deserialize)]
299pub struct WasmConfig {
300 #[serde(default)]
301 pub exclude_functions: Vec<String>,
302 #[serde(default)]
303 pub exclude_types: Vec<String>,
304 #[serde(default)]
305 pub type_overrides: HashMap<String, String>,
306 #[serde(default)]
307 pub features: Option<Vec<String>>,
308 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
309 /// When set, this takes priority over the IR type-level serde_rename_all.
310 #[serde(default)]
311 pub serde_rename_all: Option<String>,
312 /// Prefix for generated type names (e.g. "Wasm" produces `WasmConversionOptions`).
313 /// Defaults to `"Wasm"`.
314 #[serde(default)]
315 pub type_prefix: Option<String>,
316 /// Functions to exclude from the public TypeScript re-export (index.ts) while still
317 /// generating the Rust binding. Use this when a custom module provides a wrapper.
318 #[serde(default)]
319 pub exclude_reexports: Vec<String>,
320 /// Wide-character C functions to shim for WASM external scanner interop.
321 #[serde(default)]
322 pub env_shims: Vec<String>,
323 /// Additional Cargo dependencies for the WASM binding crate only.
324 #[serde(default)]
325 pub extra_dependencies: HashMap<String, toml::Value>,
326 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
327 /// desired binding field name. Applied after automatic keyword escaping.
328 #[serde(default)]
329 pub rename_fields: HashMap<String, String>,
330 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
331 /// commands across all pipelines (lint, test, build, etc.).
332 #[serde(default)]
333 pub run_wrapper: Option<String>,
334 /// Extra paths to append to default lint commands (format, check, typecheck).
335 #[serde(default)]
336 pub extra_lint_paths: Vec<String>,
337 /// Override the core Cargo dependency name and path for the WASM binding crate.
338 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
339 /// `../<override>`) instead of the umbrella `[crate.name]`. Use this to point
340 /// the WASM binding at a wasm-safe sub-crate while other languages keep the
341 /// facade. Defaults to unset.
342 #[serde(default)]
343 pub core_crate_override: Option<String>,
344 /// Keys to subtract from the merged `extra_dependencies` set for this
345 /// language only. Useful when `[crate.extra_dependencies]` lists sibling
346 /// crates that the WASM target cannot link.
347 #[serde(default)]
348 pub exclude_extra_dependencies: Vec<String>,
349 /// Hand-written Rust modules to declare in the generated lib.rs with `pub mod <name>;`
350 /// and re-export with `pub use <name>::*;`. Separate from `[custom_modules].wasm` which
351 /// only adds TypeScript `export *` re-exports. Use this for Rust-side dispatch/glue modules.
352 #[serde(default)]
353 pub custom_rust_modules: Vec<String>,
354 /// Per-type field exclusions for the generated From impls and binding struct.
355 /// Key is the type name (e.g. "ServerConfig"), value is a list of field names to skip.
356 /// Use when source fields are gated behind `#[cfg(not(target_arch = "wasm32"))]` and
357 /// therefore don't exist in the wasm32 compilation environment.
358 #[serde(default)]
359 pub exclude_fields: HashMap<String, Vec<String>>,
360 /// Source crate names whose types are re-exported by the `core_crate_override`
361 /// crate. References to `<original_crate>::TypeName` in generated code are
362 /// rewritten to `<override_crate>::TypeName`. Only meaningful when
363 /// `core_crate_override` is set.
364 /// Example: with `core_crate_override = "mylib-http"`, setting
365 /// `source_crate_remaps = ["mylib-core", "mylib"]` rewrites
366 /// `mylib_core::Method` and `mylib::Method` references to
367 /// `mylib_http::Method` (assumes `mylib-http` re-exports them via
368 /// `pub use mylib_core::*`).
369 #[serde(default)]
370 pub source_crate_remaps: Vec<String>,
371}
372
373#[derive(Debug, Clone, Serialize, Deserialize)]
374pub struct FfiConfig {
375 pub prefix: Option<String>,
376 #[serde(default = "default_error_style")]
377 pub error_style: String,
378 pub header_name: Option<String>,
379 /// Native library name for Go cgo/Java Panama/C# P/Invoke (e.g., "ts_pack_ffi").
380 /// Defaults to `{prefix}_ffi`.
381 #[serde(default)]
382 pub lib_name: Option<String>,
383 /// If true, generate visitor/callback FFI support.
384 #[serde(default)]
385 pub visitor_callbacks: bool,
386 #[serde(default)]
387 pub features: Option<Vec<String>>,
388 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
389 /// When set, this takes priority over the IR type-level serde_rename_all.
390 #[serde(default)]
391 pub serde_rename_all: Option<String>,
392 /// Functions to exclude from FFI binding generation.
393 #[serde(default)]
394 pub exclude_functions: Vec<String>,
395 /// Types to exclude from FFI binding generation.
396 #[serde(default)]
397 pub exclude_types: Vec<String>,
398 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
399 /// desired binding field name. Applied after automatic keyword escaping.
400 #[serde(default)]
401 pub rename_fields: HashMap<String, String>,
402 /// Rust expression used to construct an error value of this crate's
403 /// `error_type` from a runtime `String` message inside generated FFI
404 /// trait-bridge plugin shims (`plugin_impl_initialize`, `plugin_impl_shutdown`).
405 ///
406 /// The expression has access to a local variable `msg: String` containing
407 /// the underlying error message and is interpolated verbatim. Example
408 /// values:
409 ///
410 /// ```toml
411 /// # downstream whose error type has a struct variant with two fields:
412 /// plugin_error_constructor = """
413 /// kreuzberg::KreuzbergError::Plugin { message: msg, plugin_name: String::new() }
414 /// """
415 ///
416 /// # downstream whose error type implements `From<String>`:
417 /// plugin_error_constructor = "MyError::from(msg)"
418 /// ```
419 ///
420 /// Defaults to `None`. When unset, the plugin shim still emits — backends
421 /// fall back to a `format!("{}: {}", prefix, msg)`-style construction via
422 /// the configured `error_constructor`. Downstreams that don't expose
423 /// trait-bridged plugins can ignore this knob entirely.
424 #[serde(default)]
425 pub plugin_error_constructor: Option<String>,
426}
427
428fn default_error_style() -> String {
429 "last_error".to_string()
430}
431
432#[derive(Debug, Clone, Serialize, Deserialize)]
433pub struct GoConfig {
434 pub module: Option<String>,
435 /// Override the Go package name (default: derived from module path)
436 pub package_name: Option<String>,
437 #[serde(default)]
438 pub features: Option<Vec<String>>,
439 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
440 /// When set, this takes priority over the IR type-level serde_rename_all.
441 #[serde(default)]
442 pub serde_rename_all: Option<String>,
443 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
444 /// desired binding field name. Applied after automatic keyword escaping.
445 #[serde(default)]
446 pub rename_fields: HashMap<String, String>,
447 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
448 /// commands across all pipelines (lint, test, build, etc.).
449 #[serde(default)]
450 pub run_wrapper: Option<String>,
451 /// Extra paths to append to default lint commands (format, check, typecheck).
452 #[serde(default)]
453 pub extra_lint_paths: Vec<String>,
454}
455
456#[derive(Debug, Clone, Serialize, Deserialize)]
457pub struct JavaConfig {
458 pub package: Option<String>,
459 /// Override the Maven `<groupId>` emitted by alef-scaffold and alef-e2e. When unset,
460 /// `java_group_id()` falls back to the Java `package` value. Set this when the
461 /// published Maven coords differ from the Java package path (e.g. group
462 /// `dev.kreuzberg`, package `dev.kreuzberg.htmltomarkdown`).
463 #[serde(default)]
464 pub group_id: Option<String>,
465 /// Override the Maven `<artifactId>` emitted by alef-scaffold and alef-e2e. When
466 /// unset, defaults to the crate name (the `[[crates]] name = "..."`). Set this when
467 /// the published artifactId differs from the source crate name (e.g. crate
468 /// `html-to-markdown-rs` published as `html-to-markdown`).
469 #[serde(default)]
470 pub artifact_id: Option<String>,
471 #[serde(default = "default_java_ffi_style")]
472 pub ffi_style: String,
473 #[serde(default)]
474 pub features: Option<Vec<String>>,
475 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
476 /// When set, this takes priority over the IR type-level serde_rename_all.
477 #[serde(default)]
478 pub serde_rename_all: Option<String>,
479 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
480 /// desired binding field name. Applied after automatic keyword escaping.
481 #[serde(default)]
482 pub rename_fields: HashMap<String, String>,
483 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
484 /// commands across all pipelines (lint, test, build, etc.).
485 #[serde(default)]
486 pub run_wrapper: Option<String>,
487 /// Extra paths to append to default lint commands (format, check, typecheck).
488 /// Ignored when project_file is set.
489 #[serde(default)]
490 pub extra_lint_paths: Vec<String>,
491 /// Project file for Maven/Gradle (e.g., "pom.xml", "build.gradle"). When set, default
492 /// lint/build/test commands target this file instead of the output directory.
493 #[serde(default)]
494 pub project_file: Option<String>,
495}
496
497fn default_java_ffi_style() -> String {
498 "panama".to_string()
499}
500
501/// Target platform for Kotlin code generation.
502///
503/// - `"jvm"` (default): emits source consuming the Java/Panama FFM facade.
504/// - `"native"`: emits Kotlin/Native source consuming the cbindgen C FFI library.
505/// - `"multiplatform"`: reserved for the KMP stage (Phase 3 follow-up).
506#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
507#[serde(rename_all = "lowercase")]
508pub enum KotlinTarget {
509 #[default]
510 Jvm,
511 Native,
512 // Multiplatform — Phase 3 KMP stage; placeholder so the enum is forward-compatible.
513 Multiplatform,
514}
515
516#[derive(Debug, Clone, Serialize, Deserialize)]
517pub struct KotlinConfig {
518 pub package: Option<String>,
519 #[serde(default)]
520 pub features: Option<Vec<String>>,
521 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
522 /// When set, this takes priority over the IR type-level serde_rename_all.
523 #[serde(default)]
524 pub serde_rename_all: Option<String>,
525 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
526 /// desired binding field name. Applied after automatic keyword escaping.
527 #[serde(default)]
528 pub rename_fields: HashMap<String, String>,
529 /// Functions to exclude from Kotlin binding generation.
530 #[serde(default)]
531 pub exclude_functions: Vec<String>,
532 /// Types to exclude from Kotlin binding generation.
533 #[serde(default)]
534 pub exclude_types: Vec<String>,
535 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
536 /// commands across all pipelines (lint, test, build, etc.).
537 #[serde(default)]
538 pub run_wrapper: Option<String>,
539 /// Extra paths to append to default lint commands (format, check, typecheck).
540 #[serde(default)]
541 pub extra_lint_paths: Vec<String>,
542 /// Target platform for Kotlin output. `"jvm"` (default) emits source consuming
543 /// the Java/Panama FFM facade; `"native"` emits Kotlin/Native source consuming
544 /// the cbindgen C FFI library. `"multiplatform"` is reserved for the KMP stage.
545 #[serde(default)]
546 pub target: KotlinTarget,
547 /// Emission mode controlling which Kotlin project layout is generated.
548 ///
549 /// Accepted values:
550 /// - `"jvm"` (default) — standard JVM-only project under `packages/kotlin/`
551 /// - `"kmp"` — Kotlin Multiplatform project under `packages/kotlin-mpp/`
552 /// - `"android"` — Android library project under `packages/kotlin-android/`
553 ///
554 /// When `None`, defaults to `"jvm"`.
555 #[serde(default)]
556 pub mode: Option<String>,
557}
558
559/// Dart bridging style: FRB (default) or raw `dart:ffi`.
560#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
561#[serde(rename_all = "lowercase")]
562pub enum DartStyle {
563 /// flutter_rust_bridge — emits a Rust crate plus Dart wrappers using
564 /// FRB-generated bridge symbols. Default.
565 #[default]
566 Frb,
567 /// Raw `dart:ffi` over the cbindgen C ABI — emits Dart-only source that
568 /// loads the shared library at runtime. Cheaper to ship; loses FRB's
569 /// async ergonomics and freezed-style data classes.
570 Ffi,
571}
572
573#[derive(Debug, Clone, Default, Serialize, Deserialize)]
574pub struct DartConfig {
575 /// Dart pub.dev package name (e.g. `"my_package"`). Used as the `name` in
576 /// `pubspec.yaml`. Defaults to a snake_case derivation of the crate name.
577 #[serde(default)]
578 pub pubspec_name: Option<String>,
579 /// Dart library name (the `library` declaration). Defaults to the pubspec name.
580 #[serde(default)]
581 pub lib_name: Option<String>,
582 /// Dart package name override (e.g. for pub.dev scoped packages).
583 #[serde(default)]
584 pub package_name: Option<String>,
585 /// Bridging style. `"frb"` (default) uses flutter_rust_bridge; `"ffi"` emits
586 /// raw `dart:ffi` source over the cbindgen C library.
587 #[serde(default)]
588 pub style: DartStyle,
589 /// flutter_rust_bridge version to pin in generated pubspec.yaml.
590 /// Defaults to `template_versions::cargo::FLUTTER_RUST_BRIDGE` when unset.
591 #[serde(default)]
592 pub frb_version: Option<String>,
593 /// Cargo features to enable on the binding crate.
594 #[serde(default)]
595 pub features: Option<Vec<String>>,
596 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
597 #[serde(default)]
598 pub serde_rename_all: Option<String>,
599 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
600 /// desired binding field name. Applied after automatic keyword escaping.
601 #[serde(default)]
602 pub rename_fields: HashMap<String, String>,
603 /// Functions to exclude from Dart binding generation.
604 #[serde(default)]
605 pub exclude_functions: Vec<String>,
606 /// Types to exclude from Dart binding generation.
607 #[serde(default)]
608 pub exclude_types: Vec<String>,
609 /// Prefix wrapper for default tool invocations.
610 #[serde(default)]
611 pub run_wrapper: Option<String>,
612 /// Extra paths to append to default lint commands.
613 #[serde(default)]
614 pub extra_lint_paths: Vec<String>,
615 /// Override the core Cargo dependency name and path for the Dart binding crate.
616 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
617 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
618 /// Defaults to unset.
619 #[serde(default)]
620 pub core_crate_override: Option<String>,
621 /// Keys to subtract from the merged `extra_dependencies` set for this
622 /// language only.
623 #[serde(default)]
624 pub exclude_extra_dependencies: Vec<String>,
625 /// Method names whose Rust bridge body should be emitted as `unimplemented!()`.
626 ///
627 /// Use this when a function's FFI signature (e.g. nested tuples containing
628 /// `Vec<u8>`) cannot be represented across the FRB bridge at all. Consumers must
629 /// list the method names explicitly — this field has no built-in defaults so the
630 /// knob is library-agnostic.
631 ///
632 /// Example (`alef.toml`):
633 /// ```toml
634 /// [crates.dart]
635 /// stub_methods = ["batch_extract_bytes", "batch_extract_bytes_sync"]
636 /// ```
637 #[serde(default)]
638 pub stub_methods: Vec<String>,
639}
640
641#[derive(Debug, Clone, Default, Serialize, Deserialize)]
642pub struct SwiftConfig {
643 /// Swift module name (e.g. `"MyLibrary"`). Defaults to PascalCase of the crate name.
644 #[serde(default)]
645 pub module_name: Option<String>,
646 /// Swift package name. Defaults to the module name.
647 #[serde(default)]
648 pub package_name: Option<String>,
649 /// swift-bridge version. Defaults to `template_versions::cargo::SWIFT_BRIDGE` when unset.
650 #[serde(default)]
651 pub swift_bridge_version: Option<String>,
652 /// Minimum macOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_MACOS` when unset.
653 #[serde(default)]
654 pub min_macos_version: Option<String>,
655 /// Minimum iOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_IOS` when unset.
656 #[serde(default)]
657 pub min_ios_version: Option<String>,
658 /// Cargo features to enable on the binding crate.
659 #[serde(default)]
660 pub features: Option<Vec<String>>,
661 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
662 #[serde(default)]
663 pub serde_rename_all: Option<String>,
664 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
665 /// desired binding field name. Applied after automatic keyword escaping.
666 #[serde(default)]
667 pub rename_fields: HashMap<String, String>,
668 /// Functions to exclude from Swift binding generation.
669 #[serde(default)]
670 pub exclude_functions: Vec<String>,
671 /// Types to exclude from Swift binding generation.
672 #[serde(default)]
673 pub exclude_types: Vec<String>,
674 /// Fields to exclude from Swift binding generation.
675 /// Format: `"TypeName.field_name"`.
676 #[serde(default)]
677 pub exclude_fields: Vec<String>,
678 /// Prefix wrapper for default tool invocations.
679 #[serde(default)]
680 pub run_wrapper: Option<String>,
681 /// Extra paths to append to default lint commands.
682 #[serde(default)]
683 pub extra_lint_paths: Vec<String>,
684 /// Override the core Cargo dependency name and path for the Swift binding crate.
685 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
686 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
687 /// Defaults to unset.
688 #[serde(default)]
689 pub core_crate_override: Option<String>,
690 /// Keys to subtract from the merged `extra_dependencies` set for this
691 /// language only.
692 #[serde(default)]
693 pub exclude_extra_dependencies: Vec<String>,
694 /// Override the auto-generated `create_<type>(api_key, base_url)` constructor
695 /// body for opaque client types that expose methods. When set, the swift backend
696 /// emits this snippet verbatim as the function body (no implicit `Ok(...)`).
697 ///
698 /// Use this when the source crate's constructor signature differs from the
699 /// default `Type::new(api_key, base_url)` shape — e.g. liter-llm uses
700 /// `DefaultClient::new(ClientConfig, Option<&str>)` and needs to build a
701 /// `ClientConfig` from the bridge inputs first.
702 ///
703 /// The snippet is parameterised by `{type_name}` (the wrapper newtype name)
704 /// and runs in a function body with `api_key: String` and `base_url: Option<String>`
705 /// already in scope. It must return `Result<{type_name}, String>`.
706 #[serde(default)]
707 pub client_constructor_body: HashMap<String, String>,
708}
709
710#[derive(Debug, Clone, Serialize, Deserialize)]
711pub struct GleamConfig {
712 pub app_name: Option<String>,
713 /// Erlang atom name for @external(erlang, "<nif>", ...) lookups (e.g., "my_app_nif").
714 /// Defaults to the app_name.
715 #[serde(default)]
716 pub nif_module: Option<String>,
717 #[serde(default)]
718 pub features: Option<Vec<String>>,
719 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
720 /// When set, this takes priority over the IR type-level serde_rename_all.
721 #[serde(default)]
722 pub serde_rename_all: Option<String>,
723 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
724 /// desired binding field name. Applied after automatic keyword escaping.
725 #[serde(default)]
726 pub rename_fields: HashMap<String, String>,
727 /// Functions to exclude from Gleam binding generation.
728 #[serde(default)]
729 pub exclude_functions: Vec<String>,
730 /// Types to exclude from Gleam binding generation.
731 #[serde(default)]
732 pub exclude_types: Vec<String>,
733 /// Prefix wrapper for default tool invocations.
734 #[serde(default)]
735 pub run_wrapper: Option<String>,
736 /// Extra paths to append to default lint commands.
737 #[serde(default)]
738 pub extra_lint_paths: Vec<String>,
739 /// Per-`element_type` Gleam record-constructor recipes used by the e2e
740 /// generator when emitting `json_object` arg literals. Each entry maps a
741 /// fixture-side `element_type` string (e.g. `"BatchFileItem"`) to a
742 /// structured constructor description that the codegen interpolates per
743 /// JSON-array item. Without an entry the codegen falls back to the
744 /// `json_object_wrapper` (or a plain `json_to_gleam`).
745 ///
746 /// Example:
747 ///
748 /// ```toml
749 /// [[crates.gleam.element_constructors]]
750 /// element_type = "BatchFileItem"
751 /// constructor = "kreuzberg.BatchFileItem"
752 /// [[crates.gleam.element_constructors.fields]]
753 /// gleam_field = "path"
754 /// kind = "file_path"
755 /// json_field = "path"
756 /// [[crates.gleam.element_constructors.fields]]
757 /// gleam_field = "config"
758 /// kind = "literal"
759 /// value = "option.None"
760 /// ```
761 #[serde(default)]
762 pub element_constructors: Vec<GleamElementConstructor>,
763 /// Optional Gleam expression template used to wrap `json_object` arg
764 /// values when no `element_type` recipe matches. The placeholder
765 /// `{json}` is replaced with a Gleam string literal containing the JSON
766 /// form of the arg value, allowing the downstream's Gleam binding to do
767 /// its own parsing.
768 ///
769 /// Example:
770 ///
771 /// ```toml
772 /// [crates.gleam]
773 /// json_object_wrapper = "kreuzberg.config_from_json_string({json})"
774 /// ```
775 ///
776 /// When `None`, the codegen emits `{json}` verbatim (a plain Gleam
777 /// string), matching the iter15 default.
778 #[serde(default)]
779 pub json_object_wrapper: Option<String>,
780}
781
782/// One per-`element_type` Gleam record-constructor recipe. Keyed by the
783/// fixture-side `element_type` string and consumed by the e2e Gleam codegen
784/// when building `json_object` arg literals.
785#[derive(Debug, Clone, Serialize, Deserialize)]
786pub struct GleamElementConstructor {
787 /// Fixture-side `element_type` value this recipe applies to (e.g.
788 /// `"BatchFileItem"`).
789 pub element_type: String,
790 /// Fully-qualified Gleam constructor identifier (e.g.
791 /// `"kreuzberg.BatchFileItem"`). Emitted verbatim before the `(...)` field
792 /// list.
793 pub constructor: String,
794 /// Ordered list of fields to emit inside the constructor's `(...)` block,
795 /// in argument-position order. Each field describes how its value is
796 /// derived from the per-item JSON object.
797 pub fields: Vec<GleamElementField>,
798}
799
800/// One field inside a [`GleamElementConstructor`]'s argument list.
801///
802/// `kind` selects the source/encoding strategy:
803/// * `"file_path"` — read `json_field` from the JSON object as a string,
804/// prefix with the configured `test_documents_dir` when the value does not
805/// start with `/`, and emit as a Gleam string literal.
806/// * `"byte_array"` — read `json_field` from the JSON object as a JSON
807/// `Array(Number)` and emit as a Gleam BitArray literal `<<n1, n2, …>>`.
808/// * `"string"` — read `json_field` as a string, emit as a Gleam string
809/// literal; falls back to `default` (or empty) if missing.
810/// * `"literal"` — emit `value` verbatim (no JSON lookup). Use for
811/// constant fields like `config: option.None`.
812#[derive(Debug, Clone, Serialize, Deserialize)]
813pub struct GleamElementField {
814 /// Gleam record field name (e.g. `"path"`, `"config"`).
815 pub gleam_field: String,
816 /// Source/encoding strategy. See struct doc.
817 pub kind: String,
818 /// JSON object key to read, when `kind` is one of the JSON-driven
819 /// strategies. Required for `"file_path"`, `"byte_array"`, `"string"`;
820 /// ignored for `"literal"`.
821 #[serde(default)]
822 pub json_field: Option<String>,
823 /// Default Gleam expression when `json_field` is missing/null. Only
824 /// honoured by the `"string"` strategy today.
825 #[serde(default)]
826 pub default: Option<String>,
827 /// Verbatim Gleam expression to emit when `kind = "literal"`.
828 #[serde(default)]
829 pub value: Option<String>,
830}
831
832#[derive(Debug, Clone, Serialize, Deserialize)]
833pub struct ZigConfig {
834 pub module_name: Option<String>,
835 #[serde(default)]
836 pub features: Option<Vec<String>>,
837 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
838 /// When set, this takes priority over the IR type-level serde_rename_all.
839 #[serde(default)]
840 pub serde_rename_all: Option<String>,
841 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
842 /// desired binding field name. Applied after automatic keyword escaping.
843 #[serde(default)]
844 pub rename_fields: HashMap<String, String>,
845 /// Functions to exclude from Zig binding generation.
846 #[serde(default)]
847 pub exclude_functions: Vec<String>,
848 /// Types to exclude from Zig binding generation.
849 #[serde(default)]
850 pub exclude_types: Vec<String>,
851 /// Prefix wrapper for default tool invocations.
852 #[serde(default)]
853 pub run_wrapper: Option<String>,
854 /// Extra paths to append to default lint commands.
855 #[serde(default)]
856 pub extra_lint_paths: Vec<String>,
857}
858
859#[derive(Debug, Clone, Serialize, Deserialize)]
860pub struct CSharpConfig {
861 pub namespace: Option<String>,
862 /// NuGet `<PackageId>` to publish under. When unset, falls back to `namespace`.
863 /// Use this when the published artifact id must differ from the C# `RootNamespace` —
864 /// e.g. when the unprefixed name is owned by a third party on nuget.org and
865 /// you publish under a vendor-prefixed id like `KreuzbergDev.<Lib>`.
866 #[serde(default)]
867 pub package_id: Option<String>,
868 pub target_framework: Option<String>,
869 #[serde(default)]
870 pub features: Option<Vec<String>>,
871 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
872 /// When set, this takes priority over the IR type-level serde_rename_all.
873 #[serde(default)]
874 pub serde_rename_all: Option<String>,
875 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
876 /// desired binding field name. Applied after automatic keyword escaping.
877 #[serde(default)]
878 pub rename_fields: HashMap<String, String>,
879 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
880 /// commands across all pipelines (lint, test, build, etc.).
881 #[serde(default)]
882 pub run_wrapper: Option<String>,
883 /// Extra paths to append to default lint commands (format, check, typecheck).
884 /// Ignored when project_file is set.
885 #[serde(default)]
886 pub extra_lint_paths: Vec<String>,
887 /// Project file for C# (e.g., "MyProject.csproj", "MySolution.sln"). When set, default
888 /// lint/build/test commands target this file instead of the output directory.
889 #[serde(default)]
890 pub project_file: Option<String>,
891 /// Functions to exclude from C# binding generation (e.g., functions not present in the
892 /// C FFI layer). Excluded functions are omitted from both NativeMethods.cs and the
893 /// wrapper class.
894 #[serde(default)]
895 pub exclude_functions: Vec<String>,
896}
897
898#[derive(Debug, Clone, Serialize, Deserialize)]
899pub struct RConfig {
900 pub package_name: Option<String>,
901 #[serde(default)]
902 pub features: Option<Vec<String>>,
903 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
904 /// When set, this takes priority over the IR type-level serde_rename_all.
905 #[serde(default)]
906 pub serde_rename_all: Option<String>,
907 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
908 /// desired binding field name. Applied after automatic keyword escaping.
909 #[serde(default)]
910 pub rename_fields: HashMap<String, String>,
911 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
912 /// commands across all pipelines (lint, test, build, etc.).
913 #[serde(default)]
914 pub run_wrapper: Option<String>,
915 /// Extra paths to append to default lint commands (format, check, typecheck).
916 #[serde(default)]
917 pub extra_lint_paths: Vec<String>,
918}
919
920/// Custom modules that alef should declare (mod X;) but not generate.
921/// These are hand-written modules imported by the generated lib.rs.
922#[derive(Debug, Clone, Default, Serialize, Deserialize)]
923pub struct CustomModulesConfig {
924 #[serde(default)]
925 pub python: Vec<String>,
926 #[serde(default)]
927 pub node: Vec<String>,
928 #[serde(default)]
929 pub ruby: Vec<String>,
930 #[serde(default)]
931 pub php: Vec<String>,
932 #[serde(default)]
933 pub elixir: Vec<String>,
934 #[serde(default)]
935 pub wasm: Vec<String>,
936 #[serde(default)]
937 pub ffi: Vec<String>,
938 #[serde(default)]
939 pub go: Vec<String>,
940 #[serde(default)]
941 pub java: Vec<String>,
942 #[serde(default)]
943 pub csharp: Vec<String>,
944 #[serde(default)]
945 pub r: Vec<String>,
946}
947
948impl CustomModulesConfig {
949 pub fn for_language(&self, lang: Language) -> &[String] {
950 match lang {
951 Language::Python => &self.python,
952 Language::Node => &self.node,
953 Language::Ruby => &self.ruby,
954 Language::Php => &self.php,
955 Language::Elixir => &self.elixir,
956 Language::Wasm => &self.wasm,
957 Language::Ffi => &self.ffi,
958 Language::Go => &self.go,
959 Language::Java => &self.java,
960 Language::Csharp => &self.csharp,
961 Language::R => &self.r,
962 Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
963 Language::Kotlin | Language::Swift | Language::Dart | Language::Gleam | Language::Zig | Language::C => &[],
964 }
965 }
966}
967
968/// Custom classes/functions from hand-written modules to register in module init.
969#[derive(Debug, Clone, Default, Serialize, Deserialize)]
970pub struct CustomRegistration {
971 #[serde(default)]
972 pub classes: Vec<String>,
973 #[serde(default)]
974 pub functions: Vec<String>,
975 #[serde(default)]
976 pub init_calls: Vec<String>,
977}
978
979/// Per-language custom registrations.
980#[derive(Debug, Clone, Default, Serialize, Deserialize)]
981pub struct CustomRegistrationsConfig {
982 #[serde(default)]
983 pub python: Option<CustomRegistration>,
984 #[serde(default)]
985 pub node: Option<CustomRegistration>,
986 #[serde(default)]
987 pub ruby: Option<CustomRegistration>,
988 #[serde(default)]
989 pub php: Option<CustomRegistration>,
990 #[serde(default)]
991 pub elixir: Option<CustomRegistration>,
992 #[serde(default)]
993 pub wasm: Option<CustomRegistration>,
994}
995
996impl CustomRegistrationsConfig {
997 pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
998 match lang {
999 Language::Python => self.python.as_ref(),
1000 Language::Node => self.node.as_ref(),
1001 Language::Ruby => self.ruby.as_ref(),
1002 Language::Php => self.php.as_ref(),
1003 Language::Elixir => self.elixir.as_ref(),
1004 Language::Wasm => self.wasm.as_ref(),
1005 _ => None,
1006 }
1007 }
1008}