1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use super::extras::Language;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PythonConfig {
pub module_name: Option<String>,
pub async_runtime: Option<String>,
pub stubs: Option<StubsConfig>,
/// PyPI package name (e.g. `"html-to-markdown"`). Used as the `[project] name` in
/// `pyproject.toml` and to derive the `python-packages` list for maturin.
/// Defaults to the crate name.
#[serde(default)]
pub pip_name: Option<String>,
/// Per-language feature override. When set, these features are used instead of
/// `[crate] features` for this language's binding crate.
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StubsConfig {
pub output: PathBuf,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeConfig {
pub package_name: Option<String>,
/// Per-language feature override. When set, these features are used instead of
/// `[crate] features` for this language's binding crate.
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
/// Prefix for generated type names (e.g. "Js" produces `JsConversionOptions`).
/// Defaults to `"Js"`.
#[serde(default)]
pub type_prefix: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RubyConfig {
pub gem_name: Option<String>,
pub stubs: Option<StubsConfig>,
/// Per-language feature override. When set, these features are used instead of
/// `[crate] features` for this language's binding crate.
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PhpConfig {
pub extension_name: Option<String>,
/// Feature gate for ext-php-rs (default: "extension-module").
/// All generated code is wrapped in `#[cfg(feature = "...")]`.
#[serde(default)]
pub feature_gate: Option<String>,
/// Output directory for generated PHP facade / stubs (e.g., `packages/php/src/`).
#[serde(default)]
pub stubs: Option<StubsConfig>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
/// Functions to exclude from PHP binding generation.
#[serde(default)]
pub exclude_functions: Vec<String>,
/// Types to exclude from PHP binding generation.
#[serde(default)]
pub exclude_types: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ElixirConfig {
pub app_name: Option<String>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
/// Functions to exclude from Elixir NIF generation.
#[serde(default)]
pub exclude_functions: Vec<String>,
/// Types to exclude from Elixir NIF generation.
#[serde(default)]
pub exclude_types: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WasmConfig {
#[serde(default)]
pub exclude_functions: Vec<String>,
#[serde(default)]
pub exclude_types: Vec<String>,
#[serde(default)]
pub type_overrides: HashMap<String, String>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
/// Prefix for generated type names (e.g. "Wasm" produces `WasmConversionOptions`).
/// Defaults to `"Wasm"`.
#[serde(default)]
pub type_prefix: Option<String>,
/// Functions to exclude from the public TypeScript re-export (index.ts) while still
/// generating the Rust binding. Use this when a custom module provides a wrapper.
#[serde(default)]
pub exclude_reexports: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FfiConfig {
pub prefix: Option<String>,
#[serde(default = "default_error_style")]
pub error_style: String,
pub header_name: Option<String>,
/// Native library name for Go cgo/Java Panama/C# P/Invoke (e.g., "ts_pack_ffi").
/// Defaults to `{prefix}_ffi`.
#[serde(default)]
pub lib_name: Option<String>,
/// If true, generate visitor/callback FFI support.
#[serde(default)]
pub visitor_callbacks: bool,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
fn default_error_style() -> String {
"last_error".to_string()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GoConfig {
pub module: Option<String>,
/// Override the Go package name (default: derived from module path)
pub package_name: Option<String>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct JavaConfig {
pub package: Option<String>,
#[serde(default = "default_java_ffi_style")]
pub ffi_style: String,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
fn default_java_ffi_style() -> String {
"panama".to_string()
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CSharpConfig {
pub namespace: Option<String>,
pub target_framework: Option<String>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RConfig {
pub package_name: Option<String>,
#[serde(default)]
pub features: Option<Vec<String>>,
/// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
/// When set, this takes priority over the IR type-level serde_rename_all.
#[serde(default)]
pub serde_rename_all: Option<String>,
}
/// Custom modules that alef should declare (mod X;) but not generate.
/// These are hand-written modules imported by the generated lib.rs.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CustomModulesConfig {
#[serde(default)]
pub python: Vec<String>,
#[serde(default)]
pub node: Vec<String>,
#[serde(default)]
pub ruby: Vec<String>,
#[serde(default)]
pub php: Vec<String>,
#[serde(default)]
pub elixir: Vec<String>,
#[serde(default)]
pub wasm: Vec<String>,
#[serde(default)]
pub ffi: Vec<String>,
#[serde(default)]
pub go: Vec<String>,
#[serde(default)]
pub java: Vec<String>,
#[serde(default)]
pub csharp: Vec<String>,
#[serde(default)]
pub r: Vec<String>,
}
impl CustomModulesConfig {
pub fn for_language(&self, lang: Language) -> &[String] {
match lang {
Language::Python => &self.python,
Language::Node => &self.node,
Language::Ruby => &self.ruby,
Language::Php => &self.php,
Language::Elixir => &self.elixir,
Language::Wasm => &self.wasm,
Language::Ffi => &self.ffi,
Language::Go => &self.go,
Language::Java => &self.java,
Language::Csharp => &self.csharp,
Language::R => &self.r,
Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
}
}
}
/// Custom classes/functions from hand-written modules to register in module init.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CustomRegistration {
#[serde(default)]
pub classes: Vec<String>,
#[serde(default)]
pub functions: Vec<String>,
#[serde(default)]
pub init_calls: Vec<String>,
}
/// Per-language custom registrations.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CustomRegistrationsConfig {
#[serde(default)]
pub python: Option<CustomRegistration>,
#[serde(default)]
pub node: Option<CustomRegistration>,
#[serde(default)]
pub ruby: Option<CustomRegistration>,
#[serde(default)]
pub php: Option<CustomRegistration>,
#[serde(default)]
pub elixir: Option<CustomRegistration>,
#[serde(default)]
pub wasm: Option<CustomRegistration>,
}
impl CustomRegistrationsConfig {
pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
match lang {
Language::Python => self.python.as_ref(),
Language::Node => self.node.as_ref(),
Language::Ruby => self.ruby.as_ref(),
Language::Php => self.php.as_ref(),
Language::Elixir => self.elixir.as_ref(),
Language::Wasm => self.wasm.as_ref(),
_ => None,
}
}
}