dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.96k stars 4.65k forks source link

Implement .NET Swift interop support targeting Apple platforms #95638

Open kotlarmilos opened 9 months ago

kotlarmilos commented 9 months ago

Overview

The Swift programming language has a different ABI, runtime environment, and object model, making it challenging to call into from the .NET runtime. The goal is to establish .NET Interop support in the ecosystem and address Swift ABI differences. Apple's shift towards Swift highlights the importance of Maui being compatible with Swift libraries and frameworks to remain relevant in the Apple ecosystem. Ideally, the interop should operate with a minimal set of additional wrappers and enable direct calls to various Swift functions.

This project can be divided into at least three separate areas and therefore potentially three separate workstreams.

Runtime: At the lowest level, ensuring that Swift can be called from .NET without an intermediate step through C or assembly is essential. This task must be implemented across all supported .NET runtimes targeting macOS and Apple mobile platforms.

Code-Generation: This layer involves the generation of C# bindings for Swift. The projection tooling consists of importing Swift into .NET, exporting .NET to Swift, and tool distribution.

End-user scenarios: At the highest level, it is crucial to address end-user scenarios. For instance, a MAUI-iOS developer should be able to create an iOS app that interacts seamlessly with Swift libraries and frameworks. The primary task at this level includes defining and managing the end-to-end process. This includes prioritizing Swift libraries and showcasing the support for .NET Swift interop.

User stories

ghost commented 9 months ago

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

Issue Details
# Overview The Swift programming language has a [different ABI](https://github.com/apple/swift/blob/main/docs/ABIStabilityManifesto.md), runtime environment, and object model, making it challenging to call into from the .NET runtime. The goal is to establish .NET Interop support in the ecosystem and address Swift ABI differences. Apple's shift towards Swift highlights the importance of Maui being compatible with Swift libraries and frameworks to remain relevant in the Apple ecosystem. Ideally, the interop should operate with a minimal set of additional wrappers and enable direct calls to various Swift functions. This project can be divided into at least three separate areas and therefore potentially three separate workstreams. **Runtime:** At the lowest level, ensuring that Swift can be called from .NET without an intermediate step through C or assembly is essential. This task must be implemented across all supported .NET runtimes targeting OSX and Apple mobile platforms. **Code-Generation:** This layer involves the generation of C# bindings for Swift. The projection tooling consists of importing Swift into .NET, exporting .NET to Swift, and tool distribution. **End-user scenarios:** At the highest level, it is crucial to address end-user scenarios. For instance, a MAUI-iOS developer should be able to create an iOS app that interacts seamlessly with Swift libraries and frameworks. The primary task at this level includes defining and managing the end-to-end process. This includes prioritizing Swift libraries and showcasing the support for .NET Swift interop. ## User stories - https://github.com/dotnet/runtime/issues/93631 - https://github.com/dotnet/runtime/issues/95633 - https://github.com/dotnet/runtime/issues/95636
Author: kotlarmilos
Assignees: kotlarmilos
Labels: `Epic`, `area-Meta`, `tracking`
Milestone: 9.0.0
ghost commented 9 months ago

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger, @kotlarmilos See info in area-owners.md if you want to be subscribed.

Issue Details
# Overview The Swift programming language has a [different ABI](https://github.com/apple/swift/blob/main/docs/ABIStabilityManifesto.md), runtime environment, and object model, making it challenging to call into from the .NET runtime. The goal is to establish .NET Interop support in the ecosystem and address Swift ABI differences. Apple's shift towards Swift highlights the importance of Maui being compatible with Swift libraries and frameworks to remain relevant in the Apple ecosystem. Ideally, the interop should operate with a minimal set of additional wrappers and enable direct calls to various Swift functions. This project can be divided into at least three separate areas and therefore potentially three separate workstreams. **Runtime:** At the lowest level, ensuring that Swift can be called from .NET without an intermediate step through C or assembly is essential. This task must be implemented across all supported .NET runtimes targeting OSX and Apple mobile platforms. **Code-Generation:** This layer involves the generation of C# bindings for Swift. The projection tooling consists of importing Swift into .NET, exporting .NET to Swift, and tool distribution. **End-user scenarios:** At the highest level, it is crucial to address end-user scenarios. For instance, a MAUI-iOS developer should be able to create an iOS app that interacts seamlessly with Swift libraries and frameworks. The primary task at this level includes defining and managing the end-to-end process. This includes prioritizing Swift libraries and showcasing the support for .NET Swift interop. ## User stories - [ ] https://github.com/dotnet/runtime/issues/93631 - [ ] https://github.com/dotnet/runtime/issues/95633 - [ ] https://github.com/dotnet/runtime/issues/95636
Author: kotlarmilos
Assignees: kotlarmilos
Labels: `Epic`, `area-Meta`, `tracking`, `os-ios`
Milestone: 9.0.0
ShikiSuen commented 8 months ago

Sorry for the interruption, but macOS is not OSX anymore. The major version of macOS changed since 2020. It is more appropriate to use the term macOS instead.

kotlarmilos commented 8 months ago

Thanks for your suggestion. The label description mentions macOS aka OSX. @marek-safar, please inform us if we should make any changes.

marek-safar commented 8 months ago

Mixing macOS and Apple seems odd. What about just naming explicitly macOS and iOS ?

jkotas commented 8 months ago

What about just naming explicitly macOS and iOS ?

macCatalyst and tvOS too

We call these "Apple platforms" in many places in the repo, one example from many https://github.com/dotnet/runtime/blob/867250ce3cdd1a93ec08a937c99f61428b8a1082/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs#L245 .

ShikiSuen commented 8 months ago

@jkotas These platforms have differences in available frameworks. AppKit and InputMethodKit are only available on macOS.

If there is a dotNET equivalent of Swift #if canImport(XXXKit) then it should be fine.