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

c#: Encode version in namespace to support wit versions #781

Merged
merged 3 commits into from
Dec 5, 2023

Conversation

jsturtevant
Copy link
Collaborator

@jsturtevant jsturtevant commented Dec 2, 2023

Prior to this change the multi-version wit was putting the functions from different versions into the same class which was causing the test to fail as there were multiple implementations of the same function:

C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\Wit.imports.my.dep.AInterop.cs(25,27): error CS0102: The type 'AInterop' already contains a definition for 'XInterop' [C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\TheWorld.csproj]
C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\Wit.imports.my.dep.AInterop.cs(31,33): error CS0111: Type 'AInterop' already defines a member called 'X' with the same parameter types [C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\TheWorld.csproj]
C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\Wit.imports.my.dep.AInterop.cs(28,36): error CS0111: Type 'AInterop.XInterop' already defines a member called 'wasmImportX' with the same parameter types [C:\Users\jstur\projects\wit-bindgen\target\codegen-tests\guest-csharp-multiversion\foo\TheWorld.csproj]

Now the it generates a file for each version (if present) with the functions namespaced by version:

wit_foo.wit.imports.my.dep.v0_1_0.A;

It also creates a file per version:

file per version of wit

To note:

  • namespaces parts can't start with numbers so put v in front.
  • This also lowercases all the names in the namespace, but we had a mixture of upper and lower case so this makes it atleast consistent. Can maybe follow up to make it more csharp like

@jsturtevant
Copy link
Collaborator Author

The refactor here exposed an issue with the way namespaces and files where generating:

Prior to this change (on main) we were getting files like

namespace wit_w.wit.exports.name3Name3Name3;

## file name
Wit.exports.name3Name3Name3.cs

image

Now we get

namespace wit_w.wit.exports.name3.name3.Name3;

## file name
Wit.exports.name3.name3.Name3.cs

Which is actual what we really want. With #782 and a small tweak to the import Interop class this will pass

@jsturtevant jsturtevant changed the title c#: Encode version in ns to support wit versions c#: Encode version in namespace to support wit versions Dec 4, 2023
@jsturtevant
Copy link
Collaborator Author

jsturtevant commented Dec 4, 2023

has cherry-pick from #782

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
Copy link
Member

@silesmo silesmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you!

@silesmo silesmo merged commit 51dad13 into bytecodealliance:main Dec 5, 2023
9 checks passed
@yowl
Copy link
Collaborator

yowl commented Dec 6, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants