Closed
Description
Description
This issue is intended to discuss the user experience and bindings generated by the Swift bindings tooling available at #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, with a void return type and no exceptions.
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment