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 #[serde(default = "default_java_ffi_style")]
460 pub ffi_style: String,
461 #[serde(default)]
462 pub features: Option<Vec<String>>,
463 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
464 /// When set, this takes priority over the IR type-level serde_rename_all.
465 #[serde(default)]
466 pub serde_rename_all: Option<String>,
467 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
468 /// desired binding field name. Applied after automatic keyword escaping.
469 #[serde(default)]
470 pub rename_fields: HashMap<String, String>,
471 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
472 /// commands across all pipelines (lint, test, build, etc.).
473 #[serde(default)]
474 pub run_wrapper: Option<String>,
475 /// Extra paths to append to default lint commands (format, check, typecheck).
476 /// Ignored when project_file is set.
477 #[serde(default)]
478 pub extra_lint_paths: Vec<String>,
479 /// Project file for Maven/Gradle (e.g., "pom.xml", "build.gradle"). When set, default
480 /// lint/build/test commands target this file instead of the output directory.
481 #[serde(default)]
482 pub project_file: Option<String>,
483}
484
485fn default_java_ffi_style() -> String {
486 "panama".to_string()
487}
488
489/// Target platform for Kotlin code generation.
490///
491/// - `"jvm"` (default): emits source consuming the Java/Panama FFM facade.
492/// - `"native"`: emits Kotlin/Native source consuming the cbindgen C FFI library.
493/// - `"multiplatform"`: reserved for the KMP stage (Phase 3 follow-up).
494#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
495#[serde(rename_all = "lowercase")]
496pub enum KotlinTarget {
497 #[default]
498 Jvm,
499 Native,
500 // Multiplatform — Phase 3 KMP stage; placeholder so the enum is forward-compatible.
501 Multiplatform,
502}
503
504#[derive(Debug, Clone, Serialize, Deserialize)]
505pub struct KotlinConfig {
506 pub package: Option<String>,
507 #[serde(default)]
508 pub features: Option<Vec<String>>,
509 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
510 /// When set, this takes priority over the IR type-level serde_rename_all.
511 #[serde(default)]
512 pub serde_rename_all: Option<String>,
513 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
514 /// desired binding field name. Applied after automatic keyword escaping.
515 #[serde(default)]
516 pub rename_fields: HashMap<String, String>,
517 /// Functions to exclude from Kotlin binding generation.
518 #[serde(default)]
519 pub exclude_functions: Vec<String>,
520 /// Types to exclude from Kotlin binding generation.
521 #[serde(default)]
522 pub exclude_types: Vec<String>,
523 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
524 /// commands across all pipelines (lint, test, build, etc.).
525 #[serde(default)]
526 pub run_wrapper: Option<String>,
527 /// Extra paths to append to default lint commands (format, check, typecheck).
528 #[serde(default)]
529 pub extra_lint_paths: Vec<String>,
530 /// Target platform for Kotlin output. `"jvm"` (default) emits source consuming
531 /// the Java/Panama FFM facade; `"native"` emits Kotlin/Native source consuming
532 /// the cbindgen C FFI library. `"multiplatform"` is reserved for the KMP stage.
533 #[serde(default)]
534 pub target: KotlinTarget,
535}
536
537/// Dart bridging style: FRB (default) or raw `dart:ffi`.
538#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
539#[serde(rename_all = "lowercase")]
540pub enum DartStyle {
541 /// flutter_rust_bridge — emits a Rust crate plus Dart wrappers using
542 /// FRB-generated bridge symbols. Default.
543 #[default]
544 Frb,
545 /// Raw `dart:ffi` over the cbindgen C ABI — emits Dart-only source that
546 /// loads the shared library at runtime. Cheaper to ship; loses FRB's
547 /// async ergonomics and freezed-style data classes.
548 Ffi,
549}
550
551#[derive(Debug, Clone, Default, Serialize, Deserialize)]
552pub struct DartConfig {
553 /// Dart pub.dev package name (e.g. `"my_package"`). Used as the `name` in
554 /// `pubspec.yaml`. Defaults to a snake_case derivation of the crate name.
555 #[serde(default)]
556 pub pubspec_name: Option<String>,
557 /// Dart library name (the `library` declaration). Defaults to the pubspec name.
558 #[serde(default)]
559 pub lib_name: Option<String>,
560 /// Dart package name override (e.g. for pub.dev scoped packages).
561 #[serde(default)]
562 pub package_name: Option<String>,
563 /// Bridging style. `"frb"` (default) uses flutter_rust_bridge; `"ffi"` emits
564 /// raw `dart:ffi` source over the cbindgen C library.
565 #[serde(default)]
566 pub style: DartStyle,
567 /// flutter_rust_bridge version to pin in generated pubspec.yaml.
568 /// Defaults to `template_versions::cargo::FLUTTER_RUST_BRIDGE` when unset.
569 #[serde(default)]
570 pub frb_version: Option<String>,
571 /// Cargo features to enable on the binding crate.
572 #[serde(default)]
573 pub features: Option<Vec<String>>,
574 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
575 #[serde(default)]
576 pub serde_rename_all: Option<String>,
577 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
578 /// desired binding field name. Applied after automatic keyword escaping.
579 #[serde(default)]
580 pub rename_fields: HashMap<String, String>,
581 /// Functions to exclude from Dart binding generation.
582 #[serde(default)]
583 pub exclude_functions: Vec<String>,
584 /// Types to exclude from Dart binding generation.
585 #[serde(default)]
586 pub exclude_types: Vec<String>,
587 /// Prefix wrapper for default tool invocations.
588 #[serde(default)]
589 pub run_wrapper: Option<String>,
590 /// Extra paths to append to default lint commands.
591 #[serde(default)]
592 pub extra_lint_paths: Vec<String>,
593 /// Override the core Cargo dependency name and path for the Dart binding crate.
594 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
595 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
596 /// Defaults to unset.
597 #[serde(default)]
598 pub core_crate_override: Option<String>,
599 /// Keys to subtract from the merged `extra_dependencies` set for this
600 /// language only.
601 #[serde(default)]
602 pub exclude_extra_dependencies: Vec<String>,
603}
604
605#[derive(Debug, Clone, Default, Serialize, Deserialize)]
606pub struct SwiftConfig {
607 /// Swift module name (e.g. `"MyLibrary"`). Defaults to PascalCase of the crate name.
608 #[serde(default)]
609 pub module_name: Option<String>,
610 /// Swift package name. Defaults to the module name.
611 #[serde(default)]
612 pub package_name: Option<String>,
613 /// swift-bridge version. Defaults to `template_versions::cargo::SWIFT_BRIDGE` when unset.
614 #[serde(default)]
615 pub swift_bridge_version: Option<String>,
616 /// Minimum macOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_MACOS` when unset.
617 #[serde(default)]
618 pub min_macos_version: Option<String>,
619 /// Minimum iOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_IOS` when unset.
620 #[serde(default)]
621 pub min_ios_version: Option<String>,
622 /// Cargo features to enable on the binding crate.
623 #[serde(default)]
624 pub features: Option<Vec<String>>,
625 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
626 #[serde(default)]
627 pub serde_rename_all: Option<String>,
628 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
629 /// desired binding field name. Applied after automatic keyword escaping.
630 #[serde(default)]
631 pub rename_fields: HashMap<String, String>,
632 /// Functions to exclude from Swift binding generation.
633 #[serde(default)]
634 pub exclude_functions: Vec<String>,
635 /// Types to exclude from Swift binding generation.
636 #[serde(default)]
637 pub exclude_types: Vec<String>,
638 /// Fields to exclude from Swift binding generation.
639 /// Format: `"TypeName.field_name"`.
640 #[serde(default)]
641 pub exclude_fields: Vec<String>,
642 /// Prefix wrapper for default tool invocations.
643 #[serde(default)]
644 pub run_wrapper: Option<String>,
645 /// Extra paths to append to default lint commands.
646 #[serde(default)]
647 pub extra_lint_paths: Vec<String>,
648 /// Override the core Cargo dependency name and path for the Swift binding crate.
649 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
650 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
651 /// Defaults to unset.
652 #[serde(default)]
653 pub core_crate_override: Option<String>,
654 /// Keys to subtract from the merged `extra_dependencies` set for this
655 /// language only.
656 #[serde(default)]
657 pub exclude_extra_dependencies: Vec<String>,
658}
659
660#[derive(Debug, Clone, Serialize, Deserialize)]
661pub struct GleamConfig {
662 pub app_name: Option<String>,
663 /// Erlang atom name for @external(erlang, "<nif>", ...) lookups (e.g., "my_app_nif").
664 /// Defaults to the app_name.
665 #[serde(default)]
666 pub nif_module: Option<String>,
667 #[serde(default)]
668 pub features: Option<Vec<String>>,
669 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
670 /// When set, this takes priority over the IR type-level serde_rename_all.
671 #[serde(default)]
672 pub serde_rename_all: Option<String>,
673 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
674 /// desired binding field name. Applied after automatic keyword escaping.
675 #[serde(default)]
676 pub rename_fields: HashMap<String, String>,
677 /// Functions to exclude from Gleam binding generation.
678 #[serde(default)]
679 pub exclude_functions: Vec<String>,
680 /// Types to exclude from Gleam binding generation.
681 #[serde(default)]
682 pub exclude_types: Vec<String>,
683 /// Prefix wrapper for default tool invocations.
684 #[serde(default)]
685 pub run_wrapper: Option<String>,
686 /// Extra paths to append to default lint commands.
687 #[serde(default)]
688 pub extra_lint_paths: Vec<String>,
689 /// Per-`element_type` Gleam record-constructor recipes used by the e2e
690 /// generator when emitting `json_object` arg literals. Each entry maps a
691 /// fixture-side `element_type` string (e.g. `"BatchFileItem"`) to a
692 /// structured constructor description that the codegen interpolates per
693 /// JSON-array item. Without an entry the codegen falls back to the
694 /// `json_object_wrapper` (or a plain `json_to_gleam`).
695 ///
696 /// Example:
697 ///
698 /// ```toml
699 /// [[crates.gleam.element_constructors]]
700 /// element_type = "BatchFileItem"
701 /// constructor = "kreuzberg.BatchFileItem"
702 /// [[crates.gleam.element_constructors.fields]]
703 /// gleam_field = "path"
704 /// kind = "file_path"
705 /// json_field = "path"
706 /// [[crates.gleam.element_constructors.fields]]
707 /// gleam_field = "config"
708 /// kind = "literal"
709 /// value = "option.None"
710 /// ```
711 #[serde(default)]
712 pub element_constructors: Vec<GleamElementConstructor>,
713 /// Optional Gleam expression template used to wrap `json_object` arg
714 /// values when no `element_type` recipe matches. The placeholder
715 /// `{json}` is replaced with a Gleam string literal containing the JSON
716 /// form of the arg value, allowing the downstream's Gleam binding to do
717 /// its own parsing.
718 ///
719 /// Example:
720 ///
721 /// ```toml
722 /// [crates.gleam]
723 /// json_object_wrapper = "kreuzberg.config_from_json_string({json})"
724 /// ```
725 ///
726 /// When `None`, the codegen emits `{json}` verbatim (a plain Gleam
727 /// string), matching the iter15 default.
728 #[serde(default)]
729 pub json_object_wrapper: Option<String>,
730}
731
732/// One per-`element_type` Gleam record-constructor recipe. Keyed by the
733/// fixture-side `element_type` string and consumed by the e2e Gleam codegen
734/// when building `json_object` arg literals.
735#[derive(Debug, Clone, Serialize, Deserialize)]
736pub struct GleamElementConstructor {
737 /// Fixture-side `element_type` value this recipe applies to (e.g.
738 /// `"BatchFileItem"`).
739 pub element_type: String,
740 /// Fully-qualified Gleam constructor identifier (e.g.
741 /// `"kreuzberg.BatchFileItem"`). Emitted verbatim before the `(...)` field
742 /// list.
743 pub constructor: String,
744 /// Ordered list of fields to emit inside the constructor's `(...)` block,
745 /// in argument-position order. Each field describes how its value is
746 /// derived from the per-item JSON object.
747 pub fields: Vec<GleamElementField>,
748}
749
750/// One field inside a [`GleamElementConstructor`]'s argument list.
751///
752/// `kind` selects the source/encoding strategy:
753/// * `"file_path"` — read `json_field` from the JSON object as a string,
754/// prefix with the configured `test_documents_dir` when the value does not
755/// start with `/`, and emit as a Gleam string literal.
756/// * `"byte_array"` — read `json_field` from the JSON object as a JSON
757/// `Array(Number)` and emit as a Gleam BitArray literal `<<n1, n2, …>>`.
758/// * `"string"` — read `json_field` as a string, emit as a Gleam string
759/// literal; falls back to `default` (or empty) if missing.
760/// * `"literal"` — emit `value` verbatim (no JSON lookup). Use for
761/// constant fields like `config: option.None`.
762#[derive(Debug, Clone, Serialize, Deserialize)]
763pub struct GleamElementField {
764 /// Gleam record field name (e.g. `"path"`, `"config"`).
765 pub gleam_field: String,
766 /// Source/encoding strategy. See struct doc.
767 pub kind: String,
768 /// JSON object key to read, when `kind` is one of the JSON-driven
769 /// strategies. Required for `"file_path"`, `"byte_array"`, `"string"`;
770 /// ignored for `"literal"`.
771 #[serde(default)]
772 pub json_field: Option<String>,
773 /// Default Gleam expression when `json_field` is missing/null. Only
774 /// honoured by the `"string"` strategy today.
775 #[serde(default)]
776 pub default: Option<String>,
777 /// Verbatim Gleam expression to emit when `kind = "literal"`.
778 #[serde(default)]
779 pub value: Option<String>,
780}
781
782#[derive(Debug, Clone, Serialize, Deserialize)]
783pub struct ZigConfig {
784 pub module_name: Option<String>,
785 #[serde(default)]
786 pub features: Option<Vec<String>>,
787 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
788 /// When set, this takes priority over the IR type-level serde_rename_all.
789 #[serde(default)]
790 pub serde_rename_all: Option<String>,
791 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
792 /// desired binding field name. Applied after automatic keyword escaping.
793 #[serde(default)]
794 pub rename_fields: HashMap<String, String>,
795 /// Functions to exclude from Zig binding generation.
796 #[serde(default)]
797 pub exclude_functions: Vec<String>,
798 /// Types to exclude from Zig binding generation.
799 #[serde(default)]
800 pub exclude_types: Vec<String>,
801 /// Prefix wrapper for default tool invocations.
802 #[serde(default)]
803 pub run_wrapper: Option<String>,
804 /// Extra paths to append to default lint commands.
805 #[serde(default)]
806 pub extra_lint_paths: Vec<String>,
807}
808
809#[derive(Debug, Clone, Serialize, Deserialize)]
810pub struct CSharpConfig {
811 pub namespace: Option<String>,
812 /// NuGet `<PackageId>` to publish under. When unset, falls back to `namespace`.
813 /// Use this when the published artifact id must differ from the C# `RootNamespace` —
814 /// e.g. when the unprefixed name is owned by a third party on nuget.org and
815 /// you publish under a vendor-prefixed id like `KreuzbergDev.<Lib>`.
816 #[serde(default)]
817 pub package_id: Option<String>,
818 pub target_framework: Option<String>,
819 #[serde(default)]
820 pub features: Option<Vec<String>>,
821 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
822 /// When set, this takes priority over the IR type-level serde_rename_all.
823 #[serde(default)]
824 pub serde_rename_all: Option<String>,
825 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
826 /// desired binding field name. Applied after automatic keyword escaping.
827 #[serde(default)]
828 pub rename_fields: HashMap<String, String>,
829 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
830 /// commands across all pipelines (lint, test, build, etc.).
831 #[serde(default)]
832 pub run_wrapper: Option<String>,
833 /// Extra paths to append to default lint commands (format, check, typecheck).
834 /// Ignored when project_file is set.
835 #[serde(default)]
836 pub extra_lint_paths: Vec<String>,
837 /// Project file for C# (e.g., "MyProject.csproj", "MySolution.sln"). When set, default
838 /// lint/build/test commands target this file instead of the output directory.
839 #[serde(default)]
840 pub project_file: Option<String>,
841 /// Functions to exclude from C# binding generation (e.g., functions not present in the
842 /// C FFI layer). Excluded functions are omitted from both NativeMethods.cs and the
843 /// wrapper class.
844 #[serde(default)]
845 pub exclude_functions: Vec<String>,
846}
847
848#[derive(Debug, Clone, Serialize, Deserialize)]
849pub struct RConfig {
850 pub package_name: Option<String>,
851 #[serde(default)]
852 pub features: Option<Vec<String>>,
853 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
854 /// When set, this takes priority over the IR type-level serde_rename_all.
855 #[serde(default)]
856 pub serde_rename_all: Option<String>,
857 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
858 /// desired binding field name. Applied after automatic keyword escaping.
859 #[serde(default)]
860 pub rename_fields: HashMap<String, String>,
861 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
862 /// commands across all pipelines (lint, test, build, etc.).
863 #[serde(default)]
864 pub run_wrapper: Option<String>,
865 /// Extra paths to append to default lint commands (format, check, typecheck).
866 #[serde(default)]
867 pub extra_lint_paths: Vec<String>,
868}
869
870/// Custom modules that alef should declare (mod X;) but not generate.
871/// These are hand-written modules imported by the generated lib.rs.
872#[derive(Debug, Clone, Default, Serialize, Deserialize)]
873pub struct CustomModulesConfig {
874 #[serde(default)]
875 pub python: Vec<String>,
876 #[serde(default)]
877 pub node: Vec<String>,
878 #[serde(default)]
879 pub ruby: Vec<String>,
880 #[serde(default)]
881 pub php: Vec<String>,
882 #[serde(default)]
883 pub elixir: Vec<String>,
884 #[serde(default)]
885 pub wasm: Vec<String>,
886 #[serde(default)]
887 pub ffi: Vec<String>,
888 #[serde(default)]
889 pub go: Vec<String>,
890 #[serde(default)]
891 pub java: Vec<String>,
892 #[serde(default)]
893 pub csharp: Vec<String>,
894 #[serde(default)]
895 pub r: Vec<String>,
896}
897
898impl CustomModulesConfig {
899 pub fn for_language(&self, lang: Language) -> &[String] {
900 match lang {
901 Language::Python => &self.python,
902 Language::Node => &self.node,
903 Language::Ruby => &self.ruby,
904 Language::Php => &self.php,
905 Language::Elixir => &self.elixir,
906 Language::Wasm => &self.wasm,
907 Language::Ffi => &self.ffi,
908 Language::Go => &self.go,
909 Language::Java => &self.java,
910 Language::Csharp => &self.csharp,
911 Language::R => &self.r,
912 Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
913 Language::Kotlin | Language::Swift | Language::Dart | Language::Gleam | Language::Zig | Language::C => &[],
914 }
915 }
916}
917
918/// Custom classes/functions from hand-written modules to register in module init.
919#[derive(Debug, Clone, Default, Serialize, Deserialize)]
920pub struct CustomRegistration {
921 #[serde(default)]
922 pub classes: Vec<String>,
923 #[serde(default)]
924 pub functions: Vec<String>,
925 #[serde(default)]
926 pub init_calls: Vec<String>,
927}
928
929/// Per-language custom registrations.
930#[derive(Debug, Clone, Default, Serialize, Deserialize)]
931pub struct CustomRegistrationsConfig {
932 #[serde(default)]
933 pub python: Option<CustomRegistration>,
934 #[serde(default)]
935 pub node: Option<CustomRegistration>,
936 #[serde(default)]
937 pub ruby: Option<CustomRegistration>,
938 #[serde(default)]
939 pub php: Option<CustomRegistration>,
940 #[serde(default)]
941 pub elixir: Option<CustomRegistration>,
942 #[serde(default)]
943 pub wasm: Option<CustomRegistration>,
944}
945
946impl CustomRegistrationsConfig {
947 pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
948 match lang {
949 Language::Python => self.python.as_ref(),
950 Language::Node => self.node.as_ref(),
951 Language::Ruby => self.ruby.as_ref(),
952 Language::Php => self.php.as_ref(),
953 Language::Elixir => self.elixir.as_ref(),
954 Language::Wasm => self.wasm.as_ref(),
955 _ => None,
956 }
957 }
958}