dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.37k stars 189 forks source link

Swift bindings generator with simple parser and emitter #2525

Closed kotlarmilos closed 3 months ago

kotlarmilos commented 4 months ago

Description

This PR introduces a toolset for generating C# bindings from Swift interface files. This is the MVP aiming to support the generation of C# bindings for CryptoKit dev templates.

The tooling consists of the following components:

The parser and emitter are modular and implement ISwiftParser and ICSharpEmitter interfaces. The Swift ABI parser can be replaced with a swiftinterface parser, while the string-based emitter can be replaced with an object model-based emitter.

Workflow:

  1. Parse Swift ABI files to aggregate public ABI.
  2. Generate marshalling information if needed.
  3. Emit C# source code using a string-based emitter.

The unit tests verify the XML layout of the type database and various P/Invoke cases. Additionally, CryptoKit dev templates with unsafe (buffer) pointers are implemented.

kotlarmilos commented 4 months ago

This PR has been updated with a bindings generator that includes a simple parser and emitter (refer to the updated description and docs). Please note that this is an MVP for CryptoKit dev templates.

kotlarmilos commented 3 months ago

This PR includes projection tooling skeleton and implements CryptoKit dev templates with unsafe (buffer) pointers. We will move forward with surfacing https://developer.apple.com/documentation/cryptokit/chachapoly enum and https://developer.apple.com/documentation/cryptokit/symmetrickey struct in a subsequent PR.

Please review this PR and provide feedback.