Skip to content

Unnecessarily duplicated delegate types #122

@nihohit

Description

@nihohit

Type aliases for passed callbacks are ignored, and each function gets its own callback, even if the rust file contains information that shows.

temp.rs:

pub type SingleIntCallback = extern "C" fn(param: i32);

#[no_mangle]
pub unsafe extern "C" fn first(_callback: SingleIntCallback) {}

#[no_mangle]
pub unsafe extern "C" fn second(_callback: SingleIntCallback) {}

build.rs::

csbindgen::Builder::default()
    .input_extern_file("src/temp.rs")
    .csharp_dll_name("example")
    .always_included_types(["SingleIntCallback"])
    .csharp_use_function_pointer(false)
    .generate_csharp_file("../unity/Runtime/NativeMethods.cs")
    .unwrap()

Output:

// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;


namespace CsBindgen
{
    internal static unsafe partial class NativeMethods
    {
        const string __DllName = "example";



        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        internal delegate void first__callback_delegate(int param);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        internal delegate void second__callback_delegate(int param);



        [DllImport(__DllName, EntryPoint = "first", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
        internal static extern void first(first__callback_delegate _callback);

        [DllImport(__DllName, EntryPoint = "second", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
        internal static extern void second(second__callback_delegate _callback);


    }



}

This requires in Unity:

    [AOT.MonoPInvokeCallback(typeof(first__callback_delegate))]
    [AOT.MonoPInvokeCallback(typeof(second__callback_delegate))]

Which easily explodes with the number of generated functions.

I'd be happy to fix this, but I don't know the structure of this project, so I'll appreciate pointers on where to look.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions