Skip to content

Latest commit

 

History

History
100 lines (83 loc) · 4.31 KB

CONFIGURATION.md

File metadata and controls

100 lines (83 loc) · 4.31 KB

Configuration options

It's possible to configure some settings by passing --config argument to the generator. All configuration keys are defined in bindings.csharp section.

uniffi-bindgen-cs path/to/definitions.udl --config path/to/uniffi.toml
  • cdylib_name - override the dynamic library name linked by generated bindings, excluding lib prefix and .dll file extension. When using --library mode, defaults to library's name. In standalone mode this value is required, and error will be produced if its missing.

    # For library `libgreeter.dll`
    [bindings.csharp]
    cdylib_name = "greeter"
  • custom_types - properties for custom type defined in UDL with [Custom] typedef string Url;.

    # Represent URL as a C# native `Uri` class. The underlying type of URL is a string.
    [bindings.csharp.custom_types.Url]
    imports = ["System"]
    type_name = "Uri"
    into_custom = "new Uri({})"
    from_custom = "{}.AbsoluteUri"
    • imports (optional) - any imports required to satisfy this type.

    • type_name (optional) - the name to represent the type in generated bindings. Default is the type alias name from UDL, e.g. Url.

    • into_custom (required) - an expression to convert from the underlying type into custom type. {} will will be expanded into variable containing the underlying value. The expression is used in a return statement, i.e. return <expression(value)>;.

    • from_custom (required) - an expression to convert from the custom type into underlying type. {} will will be expanded into variable containing the custom value. The expression is used in a return statement, i.e. return <expression(value);>.

  • namespace - override the namespace ..; declaration in generated bindings file. The default is uniffi.{{namespace}}, where namespace is the namespace from UDL file.

    # emits `namespace com.example.greeter;` in generated bindings file
    [bindings.csharp]
    namespace = "com.example.greeter"
  • global_methods_class_name - override the class name containing top level functions. The default is {{namespace}}Methods, where namespace is the namespace from UDL file.

    # emits `public static class LibGreeter { .. }` in generated bindings file
    [bindings.csharp]
    global_methods_class_name = "LibGreeter"
  • access_modifier - override the default internal access modifier for "exported" uniffi symbols.

  • null_string_to_empty - when set to true, null strings will be converted to empty strings even if they are not optional.

  • omit_checksums - when set to true, the generated bindings will skip verifying API checksums when the library is initialized. This may speed up initialization but removes a safety check that catches mismatches between the generated bindings and the Rust library. Only use this if you tightly control your build pipeline.

    [bindings.csharp]
    omit_checksums = true
  • rename - override the generated C# name for types, variants, methods, and fields. Keys are dotted paths to the component being renamed; values are tables with a name field.

    # Rename a type
    [bindings.csharp.rename.MyRustType]
    name = "MyRenamedType"
    
    # Rename a method on a type
    [bindings.csharp.rename."MyObject.my_method"]
    name = "BetterMethodName"
    
    # Rename a variant of an enum
    [bindings.csharp.rename."MyEnum.variant_name"]
    name = "RenamedVariant"
    
    # Rename a field inside a record or enum variant
    [bindings.csharp.rename."MyRecord.field_name"]
    name = "RenamedField"

    Renaming is applied before code generation, so all generated references (interface declarations, FFI converter names, etc.) use the new name throughout.

  • external_packages - map Rust crate names to C# namespaces for types imported from external uniffi crates (i.e., types declared with [External] in UDL or via #[uniffi::remote]). If a crate is not listed here, the generated namespace defaults to uniffi.<namespace>.

    # Types from the "my_base_crate" Rust crate will be looked up in the "com.example.base" namespace
    [bindings.csharp]
    [bindings.csharp.external_packages]
    my_base_crate = "com.example.base"