-
-
Notifications
You must be signed in to change notification settings - Fork 38
Description
In #171 we're moving to direct invocation of the interop bindings (instead of using delegate proxies) for performance reasons.
The interop bindings are emitted at build time and not available at design-time due to .NET's SG limitation. This is usually not an issue, as most of the other interop code is also emitted at build, except for [JSFunction]
and [JSEvent]
partial methods, which require the implementations to be available at design-time.
As a workaround, the source-generated implementations for the partial methods are conditionally compiled:
bootsharp/src/cs/Bootsharp.Generate/PartialMethod.cs
Lines 12 to 19 in 009af26
public string EmitSource (Compilation compilation) | |
{ | |
method = compilation.GetSemanticModel(syntax.SyntaxTree).GetDeclaredSymbol(syntax)!; | |
return $""" | |
{syntax.Modifiers} {EmitSignature()} => | |
#if BOOTSHARP_EMITTED | |
{EmitBody()}; | |
#else |
— and the compiler constant is defined at build time after the bindings are emitted:
bootsharp/src/cs/Bootsharp/Build/Bootsharp.targets
Lines 59 to 64 in 009af26
<Target Name="BootsharpEmit" BeforeTargets="GenerateAdditionalSources" | |
Condition="'$(BootsharpSkip)' != 'true' And Exists('$(OutputPath)')"> | |
<PropertyGroup> | |
<DefineConstants>$(DefineConstants);BOOTSHARP_EMITTED</DefineConstants> | |
</PropertyGroup> |
However, the define seem to only apply to the entry assembly during the build, resulting in exception being thrown when [JSFunction]
and [JSEvent]
methods defined under none-entry assemblies are invoked.
As a workaround for the issue, use [JSImport]
to import the functions via interfaces, which works under any assembly: https://sharp.elringus.com/guide/interop-interfaces.
If anyone have an idea on how to fix this, please share.