Skip to content

Review UX and bindings for .NET Swift interop tooling in simple P/Invoke void cases #98431

@kotlarmilos

Description

@kotlarmilos

Description 

This issue is intended to discuss the user experience and bindings generated by the Swift bindings tooling available at dotnet/runtimelab#2517. The focus is on evaluating the quality of the generated C# code, scalability and trimming, and the overall UX experience.

Usage

Example usage:

dotnet SwiftBindings.dll -d "./libHelloLibrary.dylib" -s "./HelloLibrary.swiftinterface" -o "./"

Options:

  -d, --dylibs             Required. Paths to the dynamic libraries (dylibs), separated by commas.
  -s, --swiftinterfaces    Required. Paths to the Swift interface files, separated by commas.
  -o, --output             Required. Output directory for generated bindings.
  -h, --help               Display this help message.
  --version                Display version information.

When an unknown type is encountered, the tooling will report the error and proceed with bindings generation.

Simple binding

The supported scenario involves simple P/Invoke calls without arguments and with a void return type.

Swift library:

public func sayHello() {
    print("Hello world")
}

Generated C# bindings:

using System;
using System.Runtime.InteropServices;
namespace HelloLibrary
{
    public class TopLevelEntities
    {
        public static void SayHello()
        {
            NativeMethodsForTopLevelEntities.PIfunc_SayHello();
        }
    }
    internal class NativeMethodsForTopLevelEntities
    {
        [DllImport("libHelloLibrary.dylib", EntryPoint = "$s12HelloLibrary03sayA0yyF")]
        internal static extern void PIfunc_SayHello();
    }
}

User's C# code:

using System;
using HelloLibrary;

namespace HelloWorld
{
    public class Program
    {
        public static void Main(string[] args)
        {
            TopLevelEntities.SayHello();
        }
    }
}

/cc: @stephen-hawley @AaronRobinsonMSFT @vitek-karas

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions