Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Conversation

@yowl
Copy link
Contributor

@yowl yowl commented Sep 9, 2020

This PR provides hard coded mappings to a new assembly to enable CoreRT to be a drop in replacement regards the JS interop for mono based frameworks. It follow the discussion at #8303

So far I've just tried to bring up Uno (https://github.com/unoplatform/uno) and this is one of the blockers. I've added a new project to provide an implementation for the mappings, but maybe that would be better outside of CoreRT, in another GitHub repo, and just some instructions added to the docs? Because I'm not sure what direction is best for that, I've not attempted to package this new assembly into nuget.

closes: #8303

Copy link
Member

@MichalStrehovsky MichalStrehovsky 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 otherwise! Glad to hear you're making progress with Uno!

@@ -0,0 +1,54 @@

Copy link
Member

Choose a reason for hiding this comment

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

src/BuildIntegration might be a better spot for this - I think eventually we'll need the dotnet build integration to do something with this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to BuildIntegration/WebAssembly, or you'd rather not have the subdirectory?

@@ -0,0 +1,49 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

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

Could you add copyright header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.JSInterop" Version="3.1.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Is this used? Or do we expect this to be used?

If not, we might be able to just throw the InternalCalls into CoreLib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dont need it for this at least, so have removed.

// Hard coded InternalCall mappings for mono interoperability
if (callee.IsInternalCall)
{
var ecmaType = callee.OwningType as EcmaType;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: casting to MetadataType might be better - we don't need anything specific to EcmaTypes here and MetadataType would also work if we end up needing this for things that are not backed by physical IL on disk (EcmaType represents just the types that exist in IL assemblies on disk - MetadataType is more general and includes things the compiler created out of thin air).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, done

var coreRtJsInternalCallsType = _compilation.TypeSystemContext
.GetModuleForSimpleName("CoreRT.WebAssembly.MonoBridge")
.GetKnownType("CoreRT.WebAssembly.MonoBridge", "InternalCalls");
callee = coreRtJsInternalCallsType.GetMethod(callee.Name, null);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
callee = coreRtJsInternalCallsType.GetMethod(callee.Name, null);
callee = coreRtJsInternalCallsType.GetMethod(callee.Name, callee.Signature);

Copy link
Member

Choose a reason for hiding this comment

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

Bah, never mind. I just looked what Mono is doing and the sig doesn't matter to them.

I guess messing up the sig will lead to fun debugging time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like the right thing to do, will change.

if (metadataType != null && (metadataType.Namespace == "WebAssembly.JSInterop" && metadataType.Name == "InternalCalls" || metadataType.Namespace == "WebAssembly" && metadataType.Name == "Runtime"))
{
var coreRtJsInternalCallsType = _compilation.TypeSystemContext
.GetModuleForSimpleName("CoreRT.WebAssembly.MonoBridge")
Copy link
Member

Choose a reason for hiding this comment

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

Sorry - didn't notice this earlier. We have a convention here that these kinds of libraries are called "System.Private.*".

This is hardcoded in some places, like here:

corert/src/dir.props

Lines 10 to 13 in 9fd5738

<PropertyGroup Condition="$(MSBuildProjectName.StartsWith('System.Private.')) and $(MSBuildProjectDirectory.EndsWith('src'))">
<OutputPath>$(BaseOutputPath)$(OSPlatformConfig)/sdk</OutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>

This makes sure they get properly packaged and binplaced for the dotnet integration.

Can you name this to something like System.Private.WebAssembly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, np

@MichalStrehovsky MichalStrehovsky merged commit a7ff563 into dotnet:master Sep 15, 2020
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wasm: Provide implementation for InternalCall in external project

2 participants