wit_bindgen_csharp/
lib.rs

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
use wit_bindgen_core::WorldGenerator;
use wit_component::StringEncoding;

mod csharp_ident;
mod csproj;
mod function;
mod interface;
mod world_generator;

pub use csproj::CSProject;

#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "clap", derive(clap::Args))]
pub struct Opts {
    #[cfg_attr(feature = "clap", arg(long, default_value_t = StringEncoding::default()))]
    pub string_encoding: StringEncoding,

    /// Whether or not to generate a stub class for exported functions
    #[cfg_attr(feature = "clap", arg(long))]
    pub generate_stub: bool,

    // TODO: This should only temporarily needed until mono and native aot aligns.
    #[cfg_attr(feature = "clap", arg(short, long, value_enum))]
    pub runtime: CSharpRuntime,

    /// Use the `internal` access modifier by default instead of `public`
    #[cfg_attr(feature = "clap", arg(long))]
    pub internal: bool,

    /// Skip generating `cabi_realloc`, `WasmImportLinkageAttribute`, and component type files
    #[cfg_attr(feature = "clap", arg(long))]
    pub skip_support_files: bool,
}

impl Opts {
    pub fn build(&self) -> Box<dyn WorldGenerator> {
        Box::new(world_generator::CSharp {
            opts: self.clone(),
            ..world_generator::CSharp::default()
        })
    }
}

#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum CSharpRuntime {
    #[default]
    NativeAOT,
    Mono,
}