Skip to main content

uika_codegen/
config.rs

1// Configuration types for uika-codegen, deserialized from uika.config.toml.
2
3use serde::Deserialize;
4use std::collections::HashMap;
5
6/// Top-level config file.
7#[derive(Deserialize)]
8pub struct UikaConfig {
9    pub codegen: CodegenConfig,
10    #[serde(default)]
11    pub ue: Option<UeConfig>,
12    #[serde(default)]
13    pub build: Option<BuildConfig>,
14    #[serde(default)]
15    pub project: Option<ProjectConfig>,
16}
17
18#[derive(Deserialize)]
19pub struct UeConfig {
20    pub engine_path: String,
21}
22
23#[derive(Deserialize)]
24pub struct BuildConfig {
25    /// Cargo crate name of the cdylib to build. If not set, auto-detected from Cargo.toml.
26    pub crate_name: Option<String>,
27}
28
29#[derive(Deserialize)]
30pub struct ProjectConfig {
31    /// Path to the UE project directory (relative to config file location).
32    /// Defaults to "." (current directory).
33    #[serde(default = "default_project_path")]
34    pub path: String,
35}
36
37fn default_project_path() -> String {
38    ".".to_string()
39}
40
41#[derive(Deserialize)]
42pub struct CodegenConfig {
43    pub features: Vec<String>,
44    pub paths: CodegenPaths,
45    pub modules: HashMap<String, ModuleMapping>,
46    pub blocklist: Blocklist,
47}
48
49#[derive(Deserialize)]
50pub struct CodegenPaths {
51    pub uht_input: String,
52    pub rust_out: String,
53    pub cpp_out: String,
54}
55
56#[derive(Deserialize)]
57pub struct ModuleMapping {
58    pub module: String,
59    pub feature: String,
60}
61
62#[derive(Deserialize)]
63pub struct Blocklist {
64    pub classes: Vec<String>,
65    pub structs: Vec<String>,
66    /// Function blocklist in "Class.Function" format.
67    pub functions: Vec<String>,
68}
69
70impl Blocklist {
71    /// Parse function blocklist entries into (class, function) tuples.
72    pub fn function_tuples(&self) -> Vec<(String, String)> {
73        self.functions
74            .iter()
75            .filter_map(|entry| {
76                let (class, func) = entry.split_once('.')?;
77                Some((class.to_string(), func.to_string()))
78            })
79            .collect()
80    }
81}