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