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/// Most identifiers are derived from the paired `[crates.kotlin_android]`
730/// section (package, features, etc.). Set `crate_dir` when the JNI crate
731/// directory should differ from the default `<config.name>-jni/` — for
732/// example when `config.name` carries a language-specific suffix (e.g.
733/// `"html-to-markdown-rs"`) but you want the JNI crate to live at
734/// `crates/html-to-markdown-jni/` to match every other binding crate.
735#[derive(Debug, Clone, Default, Serialize, Deserialize)]
736pub struct JniConfig {
737 /// Override the JNI crate directory name.
738 ///
739 /// When set, the JNI crate is placed at `crates/<crate_dir>-jni/` and the
740 /// `[package] name` in the generated `Cargo.toml` is `<crate_dir>-jni`.
741 /// When unset, both derive from `config.name` (the default, which matches
742 /// the behavior used by `alef-backend-jni::gen_shims::jni_output_path`).
743 #[serde(default)]
744 pub crate_dir: Option<String>,
745}
746
747/// Dart bridging style: FRB (default) or raw `dart:ffi`.
748#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
749#[serde(rename_all = "lowercase")]
750pub enum DartStyle {
751 /// flutter_rust_bridge — emits a Rust crate plus Dart wrappers using
752 /// FRB-generated bridge symbols. Default.
753 #[default]
754 Frb,
755 /// Raw `dart:ffi` over the cbindgen C ABI — emits Dart-only source that
756 /// loads the shared library at runtime. Cheaper to ship; loses FRB's
757 /// async ergonomics and freezed-style data classes.
758 Ffi,
759}
760
761#[derive(Debug, Clone, Serialize, Deserialize)]
762pub struct GleamConfig {
763 pub app_name: Option<String>,
764 /// Erlang atom name for @external(erlang, "<nif>", ...) lookups (e.g., "my_app_nif").
765 /// Defaults to the app_name.
766 #[serde(default)]
767 pub nif_module: Option<String>,
768 #[serde(default)]
769 pub features: Option<Vec<String>>,
770 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
771 /// When set, this takes priority over the IR type-level serde_rename_all.
772 #[serde(default)]
773 pub serde_rename_all: Option<String>,
774 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
775 /// desired binding field name. Applied after automatic keyword escaping.
776 #[serde(default)]
777 pub rename_fields: HashMap<String, String>,
778 /// Functions to exclude from Gleam binding generation.
779 #[serde(default)]
780 pub exclude_functions: Vec<String>,
781 /// Types to exclude from Gleam binding generation.
782 #[serde(default)]
783 pub exclude_types: Vec<String>,
784 /// Prefix wrapper for default tool invocations.
785 #[serde(default)]
786 pub run_wrapper: Option<String>,
787 /// Extra paths to append to default lint commands.
788 #[serde(default)]
789 pub extra_lint_paths: Vec<String>,
790 /// Per-`element_type` Gleam record-constructor recipes used by the e2e
791 /// generator when emitting `json_object` arg literals. Each entry maps a
792 /// fixture-side `element_type` string (e.g. `"BatchFileItem"`) to a
793 /// structured constructor description that the codegen interpolates per
794 /// JSON-array item. Without an entry the codegen falls back to the
795 /// `json_object_wrapper` (or a plain `json_to_gleam`).
796 ///
797 /// Example:
798 ///
799 /// ```toml
800 /// [[crates.gleam.element_constructors]]
801 /// element_type = "BatchFileItem"
802 /// constructor = "kreuzberg.BatchFileItem"
803 /// [[crates.gleam.element_constructors.fields]]
804 /// gleam_field = "path"
805 /// kind = "file_path"
806 /// json_field = "path"
807 /// [[crates.gleam.element_constructors.fields]]
808 /// gleam_field = "config"
809 /// kind = "literal"
810 /// value = "option.None"
811 /// ```
812 #[serde(default)]
813 pub element_constructors: Vec<GleamElementConstructor>,
814 /// Optional Gleam expression template used to wrap `json_object` arg
815 /// values when no `element_type` recipe matches. The placeholder
816 /// `{json}` is replaced with a Gleam string literal containing the JSON
817 /// form of the arg value, allowing the downstream's Gleam binding to do
818 /// its own parsing.
819 ///
820 /// Example:
821 ///
822 /// ```toml
823 /// [crates.gleam]
824 /// json_object_wrapper = "kreuzberg.config_from_json_string({json})"
825 /// ```
826 ///
827 /// When `None`, the codegen emits `{json}` verbatim (a plain Gleam
828 /// string), matching the iter15 default.
829 #[serde(default)]
830 pub json_object_wrapper: Option<String>,
831}
832
833/// One per-`element_type` Gleam record-constructor recipe. Keyed by the
834/// fixture-side `element_type` string and consumed by the e2e Gleam codegen
835/// when building `json_object` arg literals.
836#[derive(Debug, Clone, Serialize, Deserialize)]
837pub struct GleamElementConstructor {
838 /// Fixture-side `element_type` value this recipe applies to (e.g.
839 /// `"BatchFileItem"`).
840 pub element_type: String,
841 /// Fully-qualified Gleam constructor identifier (e.g.
842 /// `"kreuzberg.BatchFileItem"`). Emitted verbatim before the `(...)` field
843 /// list.
844 pub constructor: String,
845 /// Ordered list of fields to emit inside the constructor's `(...)` block,
846 /// in argument-position order. Each field describes how its value is
847 /// derived from the per-item JSON object.
848 pub fields: Vec<GleamElementField>,
849}
850
851/// One field inside a [`GleamElementConstructor`]'s argument list.
852///
853/// `kind` selects the source/encoding strategy:
854/// * `"file_path"` — read `json_field` from the JSON object as a string,
855/// prefix with the configured `test_documents_dir` when the value does not
856/// start with `/`, and emit as a Gleam string literal.
857/// * `"byte_array"` — read `json_field` from the JSON object as a JSON
858/// `Array(Number)` and emit as a Gleam BitArray literal `<<n1, n2, …>>`.
859/// * `"string"` — read `json_field` as a string, emit as a Gleam string
860/// literal; falls back to `default` (or empty) if missing.
861/// * `"literal"` — emit `value` verbatim (no JSON lookup). Use for
862/// constant fields like `config: option.None`.
863#[derive(Debug, Clone, Serialize, Deserialize)]
864pub struct GleamElementField {
865 /// Gleam record field name (e.g. `"path"`, `"config"`).
866 pub gleam_field: String,
867 /// Source/encoding strategy. See struct doc.
868 pub kind: String,
869 /// JSON object key to read, when `kind` is one of the JSON-driven
870 /// strategies. Required for `"file_path"`, `"byte_array"`, `"string"`;
871 /// ignored for `"literal"`.
872 #[serde(default)]
873 pub json_field: Option<String>,
874 /// Default Gleam expression when `json_field` is missing/null. Only
875 /// honoured by the `"string"` strategy today.
876 #[serde(default)]
877 pub default: Option<String>,
878 /// Verbatim Gleam expression to emit when `kind = "literal"`.
879 #[serde(default)]
880 pub value: Option<String>,
881}
882
883#[derive(Debug, Clone, Default, Serialize, Deserialize)]
884pub struct DartConfig {
885 /// Dart pub.dev package name (e.g. `"my_package"`). Used as the `name` in
886 /// `pubspec.yaml`. Defaults to a snake_case derivation of the crate name.
887 #[serde(default)]
888 pub pubspec_name: Option<String>,
889 /// Dart library name (the `library` declaration). Defaults to the pubspec name.
890 #[serde(default)]
891 pub lib_name: Option<String>,
892 /// Dart package name override (e.g. for pub.dev scoped packages).
893 #[serde(default)]
894 pub package_name: Option<String>,
895 /// Bridging style. `"frb"` (default) uses flutter_rust_bridge; `"ffi"` emits
896 /// raw `dart:ffi` source over the cbindgen C library.
897 #[serde(default)]
898 pub style: DartStyle,
899 /// flutter_rust_bridge version to pin in generated pubspec.yaml.
900 /// Defaults to `template_versions::cargo::FLUTTER_RUST_BRIDGE` when unset.
901 #[serde(default)]
902 pub frb_version: Option<String>,
903 /// Cargo features to enable on the binding crate.
904 #[serde(default)]
905 pub features: Option<Vec<String>>,
906 /// Additional Cargo dependencies for the generated Dart Rust bridge crate.
907 #[serde(default)]
908 pub extra_dependencies: HashMap<String, toml::Value>,
909 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
910 #[serde(default)]
911 pub serde_rename_all: Option<String>,
912 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
913 /// desired binding field name. Applied after automatic keyword escaping.
914 #[serde(default)]
915 pub rename_fields: HashMap<String, String>,
916 /// Functions to exclude from Dart binding generation.
917 #[serde(default)]
918 pub exclude_functions: Vec<String>,
919 /// Types to exclude from Dart binding generation.
920 #[serde(default)]
921 pub exclude_types: Vec<String>,
922 /// Prefix wrapper for default tool invocations.
923 #[serde(default)]
924 pub run_wrapper: Option<String>,
925 /// Extra paths to append to default lint commands.
926 #[serde(default)]
927 pub extra_lint_paths: Vec<String>,
928 /// Override the core Cargo dependency name and path for the Dart binding crate.
929 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
930 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
931 /// Defaults to unset.
932 #[serde(default)]
933 pub core_crate_override: Option<String>,
934 /// Keys to subtract from the merged `extra_dependencies` set for this
935 /// language only.
936 #[serde(default)]
937 pub exclude_extra_dependencies: Vec<String>,
938 /// Method names whose Rust bridge body should be emitted as `unimplemented!()`.
939 ///
940 /// Use this when a function's FFI signature (e.g. nested tuples containing
941 /// `Vec<u8>`) cannot be represented across the FRB bridge at all. Consumers must
942 /// list the method names explicitly — this field has no built-in defaults so the
943 /// knob is library-agnostic.
944 ///
945 /// Example (`alef.toml`):
946 /// ```toml
947 /// [crates.dart]
948 /// stub_methods = ["batch_extract_bytes", "batch_extract_bytes_sync"]
949 /// ```
950 #[serde(default)]
951 pub stub_methods: Vec<String>,
952 /// Per-target Cargo dependency overrides for the binding crate.
953 ///
954 /// When set, the emitted `Cargo.toml` wraps the base core dependency in a
955 /// `[target.'cfg(not(<cfg>))'.dependencies]` section and adds a matching
956 /// `[target.'cfg(<cfg>)'.dependencies]` block using `override_features`
957 /// (and `default_features = false` when `override_default_features = false`).
958 /// Required when the binding has to swap the feature set on a specific
959 /// target triple, e.g. Android x86_64 dropping ORT-dependent features.
960 ///
961 /// Example (`alef.toml`):
962 /// ```toml
963 /// [[crates.dart.target_dep_overrides]]
964 /// cfg = "all(target_os = \"android\", target_arch = \"x86_64\")"
965 /// features = ["android-target"]
966 /// default_features = false
967 /// ```
968 #[serde(default)]
969 pub target_dep_overrides: Vec<DartTargetDepOverride>,
970}
971
972#[derive(Debug, Clone, Serialize, Deserialize)]
973pub struct DartTargetDepOverride {
974 /// Cargo `cfg(...)` predicate (without the `cfg(...)` wrapper). Example:
975 /// `all(target_os = "android", target_arch = "x86_64")`.
976 pub cfg: String,
977 /// Features to enable on the core dependency for this target.
978 #[serde(default)]
979 pub features: Vec<String>,
980 /// When false (default), emit `default-features = false` for this target.
981 /// When true, allow the core dep's default features through.
982 #[serde(default)]
983 pub default_features: bool,
984}
985
986#[derive(Debug, Clone, Default, Serialize, Deserialize)]
987pub struct SwiftConfig {
988 /// Swift module name (e.g. `"MyLibrary"`). Defaults to PascalCase of the crate name.
989 #[serde(default)]
990 pub module_name: Option<String>,
991 /// Swift package name. Defaults to the module name.
992 #[serde(default)]
993 pub package_name: Option<String>,
994 /// swift-bridge version. Defaults to `template_versions::cargo::SWIFT_BRIDGE` when unset.
995 #[serde(default)]
996 pub swift_bridge_version: Option<String>,
997 /// Minimum macOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_MACOS` when unset.
998 #[serde(default)]
999 pub min_macos_version: Option<String>,
1000 /// Minimum iOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_IOS` when unset.
1001 #[serde(default)]
1002 pub min_ios_version: Option<String>,
1003 /// Cargo features to enable on the binding crate.
1004 #[serde(default)]
1005 pub features: Option<Vec<String>>,
1006 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1007 #[serde(default)]
1008 pub serde_rename_all: Option<String>,
1009 /// Per-field name remapping. Key is `TypeName.field_name`, value is the
1010 /// desired binding field name. Applied after automatic keyword escaping.
1011 #[serde(default)]
1012 pub rename_fields: HashMap<String, String>,
1013 /// Functions to exclude from Swift binding generation.
1014 #[serde(default)]
1015 pub exclude_functions: Vec<String>,
1016 /// Types to exclude from Swift binding generation.
1017 #[serde(default)]
1018 pub exclude_types: Vec<String>,
1019 /// Fields to exclude from Swift binding generation.
1020 /// Format: `"TypeName.field_name"`.
1021 #[serde(default)]
1022 pub exclude_fields: Vec<String>,
1023 /// Prefix wrapper for default tool invocations.
1024 #[serde(default)]
1025 pub run_wrapper: Option<String>,
1026 /// Extra paths to append to default lint commands.
1027 #[serde(default)]
1028 pub extra_lint_paths: Vec<String>,
1029 /// Override the core Cargo dependency name and path for the Swift binding crate.
1030 /// When set, the binding `Cargo.toml` depends on this crate (resolved as
1031 /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
1032 /// Defaults to unset.
1033 #[serde(default)]
1034 pub core_crate_override: Option<String>,
1035 /// Extra Cargo dependencies merged into the generated Swift Rust bridge crate.
1036 #[serde(default)]
1037 pub extra_dependencies: HashMap<String, toml::Value>,
1038 /// Keys to subtract from the merged `extra_dependencies` set for this
1039 /// language only.
1040 #[serde(default)]
1041 pub exclude_extra_dependencies: Vec<String>,
1042 /// Override the auto-generated `create_<type>(api_key, base_url)` constructor
1043 /// body for opaque client types that expose methods. When set, the swift backend
1044 /// emits this snippet verbatim as the function body (no implicit `Ok(...)`).
1045 ///
1046 /// Use this when the source crate's constructor signature differs from the
1047 /// default `Type::new(api_key, base_url)` shape — e.g. liter-llm uses
1048 /// `DefaultClient::new(ClientConfig, Option<&str>)` and needs to build a
1049 /// `ClientConfig` from the bridge inputs first.
1050 ///
1051 /// The snippet is parameterised by `{type_name}` (the wrapper newtype name)
1052 /// and runs in a function body with `api_key: String` and `base_url: Option<String>`
1053 /// already in scope. It must return `Result<{type_name}, String>`.
1054 #[serde(default)]
1055 pub client_constructor_body: HashMap<String, String>,
1056}
1057
1058#[derive(Debug, Clone, Serialize, Deserialize)]
1059pub struct ZigConfig {
1060 pub module_name: Option<String>,
1061 #[serde(default)]
1062 pub features: Option<Vec<String>>,
1063 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1064 /// When set, this takes priority over the IR type-level serde_rename_all.
1065 #[serde(default)]
1066 pub serde_rename_all: Option<String>,
1067 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1068 /// desired binding field name. Applied after automatic keyword escaping.
1069 #[serde(default)]
1070 pub rename_fields: HashMap<String, String>,
1071 /// Functions to exclude from Zig binding generation.
1072 #[serde(default)]
1073 pub exclude_functions: Vec<String>,
1074 /// Types to exclude from Zig binding generation.
1075 #[serde(default)]
1076 pub exclude_types: Vec<String>,
1077 /// Prefix wrapper for default tool invocations.
1078 #[serde(default)]
1079 pub run_wrapper: Option<String>,
1080 /// Extra paths to append to default lint commands.
1081 #[serde(default)]
1082 pub extra_lint_paths: Vec<String>,
1083}
1084
1085#[derive(Debug, Clone, Serialize, Deserialize)]
1086pub struct CSharpConfig {
1087 pub namespace: Option<String>,
1088 /// NuGet `<PackageId>` to publish under. When unset, falls back to `namespace`.
1089 /// Use this when the published artifact id must differ from the C# `RootNamespace` —
1090 /// e.g. when the unprefixed name is owned by a third party on nuget.org and
1091 /// you publish under a vendor-prefixed id like `KreuzbergDev.<Lib>`.
1092 #[serde(default)]
1093 pub package_id: Option<String>,
1094 pub target_framework: Option<String>,
1095 #[serde(default)]
1096 pub features: Option<Vec<String>>,
1097 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1098 /// When set, this takes priority over the IR type-level serde_rename_all.
1099 #[serde(default)]
1100 pub serde_rename_all: Option<String>,
1101 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1102 /// desired binding field name. Applied after automatic keyword escaping.
1103 #[serde(default)]
1104 pub rename_fields: HashMap<String, String>,
1105 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
1106 /// commands across all pipelines (lint, test, build, etc.).
1107 #[serde(default)]
1108 pub run_wrapper: Option<String>,
1109 /// Extra paths to append to default lint commands (format, check, typecheck).
1110 /// Ignored when project_file is set.
1111 #[serde(default)]
1112 pub extra_lint_paths: Vec<String>,
1113 /// Project file for C# (e.g., "MyProject.csproj", "MySolution.sln"). When set, default
1114 /// lint/build/test commands target this file instead of the output directory.
1115 #[serde(default)]
1116 pub project_file: Option<String>,
1117 /// Types to exclude from C# binding generation.
1118 ///
1119 /// C# bindings call the generated C FFI through P/Invoke, so types excluded from
1120 /// `[crates.ffi].exclude_types` are also excluded automatically by the C# backend.
1121 #[serde(default)]
1122 pub exclude_types: Vec<String>,
1123 /// Functions to exclude from C# binding generation (e.g., functions not present in the
1124 /// C FFI layer). Excluded functions are omitted from both NativeMethods.cs and the
1125 /// wrapper class.
1126 #[serde(default)]
1127 pub exclude_functions: Vec<String>,
1128}
1129
1130#[derive(Debug, Clone, Serialize, Deserialize)]
1131pub struct RConfig {
1132 pub package_name: Option<String>,
1133 #[serde(default)]
1134 pub features: Option<Vec<String>>,
1135 /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1136 /// When set, this takes priority over the IR type-level serde_rename_all.
1137 #[serde(default)]
1138 pub serde_rename_all: Option<String>,
1139 /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1140 /// desired binding field name. Applied after automatic keyword escaping.
1141 #[serde(default)]
1142 pub rename_fields: HashMap<String, String>,
1143 /// Prefix wrapper for default tool invocations. When set, prepends this string to default
1144 /// commands across all pipelines (lint, test, build, etc.).
1145 #[serde(default)]
1146 pub run_wrapper: Option<String>,
1147 /// Extra paths to append to default lint commands (format, check, typecheck).
1148 #[serde(default)]
1149 pub extra_lint_paths: Vec<String>,
1150}
1151
1152/// Custom modules that alef should declare (mod X;) but not generate.
1153/// These are hand-written modules imported by the generated lib.rs.
1154#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1155pub struct CustomModulesConfig {
1156 #[serde(default)]
1157 pub python: Vec<String>,
1158 #[serde(default)]
1159 pub node: Vec<String>,
1160 #[serde(default)]
1161 pub ruby: Vec<String>,
1162 #[serde(default)]
1163 pub php: Vec<String>,
1164 #[serde(default)]
1165 pub elixir: Vec<String>,
1166 #[serde(default)]
1167 pub wasm: Vec<String>,
1168 #[serde(default)]
1169 pub ffi: Vec<String>,
1170 #[serde(default)]
1171 pub go: Vec<String>,
1172 #[serde(default)]
1173 pub java: Vec<String>,
1174 #[serde(default)]
1175 pub csharp: Vec<String>,
1176 #[serde(default)]
1177 pub r: Vec<String>,
1178}
1179
1180impl CustomModulesConfig {
1181 pub fn for_language(&self, lang: Language) -> &[String] {
1182 match lang {
1183 Language::Python => &self.python,
1184 Language::Node => &self.node,
1185 Language::Ruby => &self.ruby,
1186 Language::Php => &self.php,
1187 Language::Elixir => &self.elixir,
1188 Language::Wasm => &self.wasm,
1189 Language::Ffi => &self.ffi,
1190 Language::Go => &self.go,
1191 Language::Java => &self.java,
1192 Language::Csharp => &self.csharp,
1193 Language::R => &self.r,
1194 Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
1195 Language::Kotlin
1196 | Language::KotlinAndroid
1197 | Language::Swift
1198 | Language::Dart
1199 | Language::Gleam
1200 | Language::Zig
1201 | Language::Jni
1202 | Language::C => &[],
1203 }
1204 }
1205}
1206
1207/// Custom classes/functions from hand-written modules to register in module init.
1208#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1209pub struct CustomRegistration {
1210 #[serde(default)]
1211 pub classes: Vec<String>,
1212 #[serde(default)]
1213 pub functions: Vec<String>,
1214 #[serde(default)]
1215 pub init_calls: Vec<String>,
1216}
1217
1218/// Per-language custom registrations.
1219#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1220pub struct CustomRegistrationsConfig {
1221 #[serde(default)]
1222 pub python: Option<CustomRegistration>,
1223 #[serde(default)]
1224 pub node: Option<CustomRegistration>,
1225 #[serde(default)]
1226 pub ruby: Option<CustomRegistration>,
1227 #[serde(default)]
1228 pub php: Option<CustomRegistration>,
1229 #[serde(default)]
1230 pub elixir: Option<CustomRegistration>,
1231 #[serde(default)]
1232 pub wasm: Option<CustomRegistration>,
1233}
1234
1235impl CustomRegistrationsConfig {
1236 pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
1237 match lang {
1238 Language::Python => self.python.as_ref(),
1239 Language::Node => self.node.as_ref(),
1240 Language::Ruby => self.ruby.as_ref(),
1241 Language::Php => self.php.as_ref(),
1242 Language::Elixir => self.elixir.as_ref(),
1243 Language::Wasm => self.wasm.as_ref(),
1244 _ => None,
1245 }
1246 }
1247}