Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime support for Swift Interop in .NET 9 #93631

Closed
39 of 42 tasks
Tracked by #95638
agocke opened this issue Oct 17, 2023 · 8 comments
Closed
39 of 42 tasks
Tracked by #95638

Runtime support for Swift Interop in .NET 9 #93631

agocke opened this issue Oct 17, 2023 · 8 comments
Labels
area-System.Runtime.InteropServices User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@agocke
Copy link
Member

agocke commented Oct 17, 2023

Background

The Swift programming language is developed primarily by Apple for use in their product lines. It is a successor to the previous official language for these platforms, Objective-C. C# has had limited Objective-C interop support for quite a while and it powers frameworks like MAUI and Xamarin Forms that run on Apple devices.

Swift is now becoming the dominant language on Apple devices and eclipsing Objective-C. Many important libraries are now Swift-first or Swift-only. Objective-C binding is also becoming more difficult for these libraries. To continue to interoperate with external libraries and frameworks, C# needs to be able to interoperate directly with Swift, without going through an intermediate language.

Goals

In short, we should completely eliminate the required C/assembly sandwich that's currently required to call Swift from C# code, and potentially vice versa. In particular, neither C# nor Swift users should have to deal with lower-level system state, like registers or stack state, to call Swift from C#.

Non-goals

C# and Swift are different languages with different language semantics. It is not a goal to map every construct from one language to the other. However, there are some terms in both languages that are sufficiently similar that they can be mapped to an identical semantic term in the other language. Interop should be seen as a Venn diagram where each language forms its own circle, and interop is in the (much smaller) space of equivalent terms that are shared between them.

Work

The exact scope of work is bind the CryptoKit library with the projection tooling and runtime support. We'll need the calling convention work (described above) in the runtime. Above the OS level we'll need a code generation strategy to generate C# bindings for Swift. An existing project to do that exists as Binding Tools for Swift. This work also needs further definition, but is out of scope of the .NET runtime itself.

For the runtime we can focus on system-level interfacing. For that we will need:

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 17, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 17, 2023
@agocke agocke added this to the 9.0.0 milestone Oct 17, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 17, 2023
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 17, 2023
@ghost
Copy link

ghost commented Oct 17, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Background

The Swift programming language is developed primarily by Apple for use in their product lines. It is a successor to the previous official language for these platforms, Objective-C. C# has had limited Objective-C interop support for quite a while and it powers frameworks like MAUI and Xamarin Forms that run on Apple devices.

Swift is now becoming the dominant language on Apple devices and eclipsing Objective-C. Many important libraries are now Swift-first or Swift-only. Objective-C binding is also becoming more difficult for these libraries. To continue to interoperate with external libraries and frameworks, C# needs to be able to interoperate directly with Swift, without going through an intermediate language.

Goals

In short, we should completely eliminate the required C/assembly sandwich that's currently required to call Swift from C# code, and potentially vice versa. In particular, neither C# nor Swift users should have to deal with lower-level system state, like registers or stack state, to call Swift from C#.

Non-goals

C# and Swift are different languages with different language semantics. It is not a goal to map every construct from one language to the other. However, there are some terms in both languages that are sufficiently similar that they can be mapped to an identical semantic term in the other language. Interop should be seen as a Venn diagram where each language forms its own circle, and interop is in the (much smaller) space of equivalent terms that are shared between them.

Work

The exact scope of work is TBD. We can start to outline some basic requirements. We'll need the calling convention work (described above) in the runtime. Above the OS level we'll need a code generation strategy to generate C# bindings for Swift. An existing project to do that exists as Binding Tools for Swift. This work also needs further definition, but is out of scope of the .NET runtime itself.

For the runtime we can focus on system-level interfacing. For that we will need:

  • Calling convention design
    • Spec
    • Scenarios
      • Call basic functions
      • Tuples
      • Errors
      • Existential containers
      • Struct/class marshalling
  • Unit tests in .NET runtime
  • Integration tests or in-product usage (in runtime?)
    • CryptoKit?
Author: agocke
Assignees: -
Labels:

area-System.Runtime.InteropServices, area-Interop-coreclr

Milestone: 9.0.0

@agocke agocke added the User Story A single user-facing feature. Can be grouped under an epic. label Oct 23, 2023
@kotlarmilos
Copy link
Member

@agocke Here is a list of libraries/frameworks people have asked for: https://github.com/xamarin/xamarin-macios/issues?q=is%3Aopen+is%3Aissue+label%3Arequires-swift. Most of them are Swift-only and could be used as definition of done (DoD) along with the CryptoKit.

@ShikiSuen
Copy link

ShikiSuen commented May 31, 2024

Is this PR aim to allow Swift (on Windows / Linux / macOS) to directly use dotNet 9 APIs without RemObject toolchains?

@filipnavara
Copy link
Member

Is this PR aim to allow Swift (on Windows / Linux / macOS) to directly use dotNet 9 APIs without RemObject toolchains?

No, this is mapping in the opposite direction, allowing .NET 9+ to call Swift APIs.

@jkoritzinsky
Copy link
Member

.NET Runtime support for Swift is feature complete for .NET 9. Any additional runtime work will be in .NET 10.

@ShikiSuen
Copy link

No, this is mapping in the opposite direction, allowing .NET 9+ to call Swift APIs.

Thanks for your response. I wonder whether it is now possible on Windows / Linux to use a Swift package (which is tested cross-platform) in a .NET project.

@jkoritzinsky
Copy link
Member

For .NET 9 we focused on Apple platforms. In the future we may look at supporting Swift interop on more platforms.

@Felix-Dev
Copy link

Felix-Dev commented Jul 30, 2024

.NET Runtime support for Swift is feature complete for .NET 9. Any additional runtime work will be in .NET 10.

Appreciate all the hard work you guys have been doing over the past months! Looking forward to testing out Swift interop and future improvements by the team.

amanasifkhalid added a commit to amanasifkhalid/runtime that referenced this issue Aug 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
@kotlarmilos kotlarmilos changed the title .NET Runtime Support for Swift Interop Runtime support for Swift Interop in .NET 9 Oct 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices User Story A single user-facing feature. Can be grouped under an epic.
Projects
Archived in project
Development

No branches or pull requests

8 participants