wit_bindgen_csharp/
lib.rs

1use wit_bindgen_core::WorldGenerator;
2use wit_component::StringEncoding;
3
4mod csharp_ident;
5mod csproj;
6mod function;
7mod interface;
8mod world_generator;
9
10pub use csproj::CSProject;
11
12#[derive(Default, Debug, Clone)]
13#[cfg_attr(feature = "clap", derive(clap::Args))]
14pub struct Opts {
15    #[cfg_attr(feature = "clap", arg(long, default_value_t = StringEncoding::default()))]
16    pub string_encoding: StringEncoding,
17
18    /// Whether or not to generate a stub class for exported functions
19    #[cfg_attr(feature = "clap", arg(long))]
20    pub generate_stub: bool,
21
22    // TODO: This should only temporarily needed until mono and native aot aligns.
23    #[cfg_attr(feature = "clap", arg(short, long, value_enum))]
24    pub runtime: CSharpRuntime,
25
26    /// Use the `internal` access modifier by default instead of `public`
27    #[cfg_attr(feature = "clap", arg(long))]
28    pub internal: bool,
29
30    /// Skip generating `cabi_realloc`, `WasmImportLinkageAttribute`, and component type files
31    #[cfg_attr(feature = "clap", arg(long))]
32    pub skip_support_files: bool,
33
34    /// Generate code for WIT `Result` types instead of exceptions
35    #[cfg_attr(feature = "clap", arg(long))]
36    pub with_wit_results: bool,
37}
38
39impl Opts {
40    pub fn build(&self) -> Box<dyn WorldGenerator> {
41        Box::new(world_generator::CSharp {
42            opts: self.clone(),
43            ..world_generator::CSharp::default()
44        })
45    }
46}
47
48#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
49#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
50pub enum CSharpRuntime {
51    #[default]
52    NativeAOT,
53    Mono,
54}