Add initial documentation for the projection tooling#2512
Add initial documentation for the projection tooling#2512kotlarmilos merged 11 commits intofeature/swift-bindingsfrom
Conversation
docs/README.md
Outdated
| public BarInt(nint x) | ||
| { | ||
| } | ||
| internal BarInt(SwiftNominalCtorArgument unused) |
There was a problem hiding this comment.
The internal constructor won't work well if the bindings are spanning multiple assemblies. I assume that we will eventually want to have one assembly per component for pre-generated bindings.
There was a problem hiding this comment.
What do you consider a component? Should we split them by Swift namespaces?
@stephen-hawley Is there any particular reason the constructor has been set to internal?
There was a problem hiding this comment.
I would consider each .framework a separate component.
docs/README.md
Outdated
| [SwiftStruct("libNewClassCompilerTests.dylib", | ||
| "$s21NewClassCompilerTests6BarIntVMn", | ||
| "$s21NewClassCompilerTests6BarIntVN", "")] |
There was a problem hiding this comment.
Can you add an explanation of what these parameters mean to this doc?
There was a problem hiding this comment.
Here is the current definition:
[AttributeUsage (AttributeTargets.Class, AllowMultiple = false)]
public sealed class SwiftStructAttribute : SwiftValueTypeAttribute {
public SwiftStructAttribute (string libraryName, string nominalTypeDescriptor, string metadata, string witnessTable)
: base (libraryName, nominalTypeDescriptor, metadata, witnessTable)
{
}
}It seems to be intended for future extensibility. If that's the case, I would removing it to simplify and narrow the scope.
There was a problem hiding this comment.
It would make sense to have a way to identify the Swift type - specifically for the Projection B relies on Projection A scenario - B will need to be able to find which C# type is a specific Swift type from A.
There was a problem hiding this comment.
Is the implemented interface sufficient for identifying the Swift type?
docs/README.md
Outdated
| The tooling consists of the following components: | ||
| - **CLIInterface**: A command-line interface that orchestrates the tooling workflow. | ||
| - **SwiftReflector**: A component that aggregates public API definitions from Swift modules. | ||
| - **Dynamo**: A component that provides API for C# code generation. |
There was a problem hiding this comment.
Any particular reason Roslyn wouldn't work?
There was a problem hiding this comment.
I agree with Rolf that we should use Roslyn. But I think it's OK to stick with the existing code for now and change this as a subsequent PR - but Roslyn should be the plan (unless there's some technical reason not to)
There was a problem hiding this comment.
FWIW, Roslyn is not a particularly great API for generating source code. Most source generators generate the source by printing it one line at time, without much help from Roslyn. Random example: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Emitter.cs#L461-L485
There was a problem hiding this comment.
Another facet of this that has been mentioned is that source generators aren't the best solution when C# isn't the "source of truth". When the C# is the "source of truth", the source generators are appropriate - see LibraryImport or the COM source generator.
docs/README.md
Outdated
| ~BarInt() | ||
| { | ||
| } | ||
| public byte[] SwiftData |
There was a problem hiding this comment.
What happens if code modifies the array directly?
var value = new BarInt ();
value.SwiftData [1] = 42;I'm assuming nothing good... so maybe we should figure out a way to expose this so that users can't shoot themselves in the foot (as easily at least)?
One simple solution might be to mark it as EditorBrowseable.Never.
There was a problem hiding this comment.
Does it need to be a public member?
There was a problem hiding this comment.
If it needs to be public, could we use ReadOnlySpan or ReadOnlyMemory?
docs/README.md
Outdated
| ~BarInt() | ||
| { | ||
| } | ||
| public byte[] SwiftData |
There was a problem hiding this comment.
Is there a description somewhere how exactly this works and what is it for?
There was a problem hiding this comment.
According to the docs, it is an interface that represents Swift named value types.
byte[] SwiftData { get; set }- gets an array of opaque data that represents the swift value type. The size of the array can be found by callingStructMarshal.Marshal.Strideof().
@stephen-hawley Could you please provide additional context on this?
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
|
This PR has been updated to align with the implementation in #2517. The scope has been narrowed to only include static methods and P/Invoke calls. |
Description
This PR adds initial documentation for the tooling focusing on static methods and P/Invoke declarations.