Skip to content

Commit

Permalink
[wasm] WBT: Override runtime pack with the locally built one
Browse files Browse the repository at this point in the history
  • Loading branch information
radical committed Aug 29, 2023
1 parent b7b8bb3 commit fcceee9
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public BuildEnvironment()
EnvVars["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1";
EnvVars["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}";
EnvVars["EM_WORKAROUND_PYTHON_BUG_34780"] = "1";
EnvVars["WBTOverrideRuntimePack"] = "true";

if (!UseWebcil)
{
Expand Down
63 changes: 63 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/data/Blazor.Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,67 @@
<Target Name="PrintRuntimePackPath" BeforeTargets="Build">
<Message Text="** MicrosoftNetCoreAppRuntimePackDir : '@(ResolvedRuntimePack -> '%(PackageDirectory)')'" Importance="High" Condition="@(ResolvedRuntimePack->Count()) > 0" />
</Target>

<!-- SDK tries to download runtime packs when RuntimeIdentifier is set, remove them from PackageDownload item. -->
<Target Name="RemoveRuntimePackFromDownloadItem"
AfterTargets="ProcessFrameworkReferences"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'">
<ItemGroup>
<PackageDownload Remove="@(PackageDownload)"
Condition="'$(UsePackageDownload)' == 'true' and $([System.String]::Copy('%(Identity)').StartsWith('Microsoft.NETCore.App.Runtime'))" />
<PackageReference Remove="@(PackageReference)"
Condition="'$(UsePackageDownload)' != 'true' and $([System.String]::Copy('%(Identity)').StartsWith('Microsoft.NETCore.App.Runtime'))" />
</ItemGroup>
</Target>

<!-- Use local targeting pack for NetCoreAppCurrent. -->
<Target Name="UpdateTargetingAndRuntimePack"
AfterTargets="ResolveFrameworkReferences"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'">
<ItemGroup>
<ResolvedRuntimePack
Update="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
FrameworkName="Microsoft.NETCore.App"
NuGetPackageId="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
NuGetPackageVersion="$(_RuntimePackInWorkloadVersionCurrent)"
PackageDirectory="$(NetCoreTargetingPackRoot)\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\$(_RuntimePackInWorkloadVersionCurrent)"
RuntimeIdentifier="browser-wasm" />

<ResolvedFrameworkReference Update="Microsoft.NETCore.App"
RuntimePackName="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
RuntimePackVersion="$(_RuntimePackInWorkloadVersionCurrent)"
RuntimePackPath="$(NetCoreTargetingPackRoot)\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\$(_RuntimePackInWorkloadVersionCurrent)"
RuntimeIdentifier="browser-wasm" />
</ItemGroup>
</Target>

<!-- Update the local targeting pack's version as it's written into the runtimeconfig.json file to select the right framework. -->
<Target Name="UpdateRuntimeFrameworkVersion"
AfterTargets="ResolveTargetingPackAssets"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'">
<ItemGroup>
<RuntimeFramework Version="$(_RuntimePackInWorkloadVersionCurrent)"
Condition="'%(RuntimeFramework.FrameworkName)' == 'Microsoft.NETCore.App'" />
</ItemGroup>
</Target>

<!-- Filter out conflicting implicit assembly references. -->
<Target Name="FilterImplicitAssemblyReferences"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'"
DependsOnTargets="ResolveProjectReferences"
AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<_targetingPackReferenceExclusion Include="$(TargetName)" />
<_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->'%(Filename)')" />
<_targetingPackReferenceExclusion Include="@(DefaultReferenceExclusion)" />
</ItemGroup>

<ItemGroup>
<_targetingPackReferenceWithExclusion Include="@(Reference)">
<Exclusion>%(_targetingPackReferenceExclusion.Identity)</Exclusion>
</_targetingPackReferenceWithExclusion>
<Reference Remove="@(_targetingPackReferenceWithExclusion)"
Condition="'%(_targetingPackReferenceWithExclusion.ExternallyResolved)' == 'true' and '%(_targetingPackReferenceWithExclusion.Filename)' == '%(_targetingPackReferenceWithExclusion.Exclusion)'" />
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<Target Name="PrintRuntimePackPath" BeforeTargets="Build">
<Message Text="** MicrosoftNetCoreAppRuntimePackDir : '@(ResolvedRuntimePack -> '%(PackageDirectory)')'" Importance="High" Condition="@(ResolvedRuntimePack->Count()) > 0" />
<Message Text="** MicrosoftNetCoreAppRuntimePackDir : %(ResolvedRuntimePack.PackageDirectory)" Importance="High" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,77 @@
<Target Name="PrintRuntimePackPath" BeforeTargets="Build">
<Message Text="** MicrosoftNetCoreAppRuntimePackDir : '@(ResolvedRuntimePack -> '%(PackageDirectory)')'" Importance="High" Condition="@(ResolvedRuntimePack->Count()) > 0" />
</Target>

<!-- Add the resolved targeting pack to the assembly search path. -->
<!-- <Target Name="UseTargetingPackForAssemblySearchPaths"
BeforeTargets="ResolveAssemblyReferences;
DesignTimeResolveAssemblyReferences"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<PropertyGroup>
<AssemblySearchPaths>$(AssemblySearchPaths);$(MicrosoftNetCoreAppRefPackRefDir.TrimEnd('/\'))</AssemblySearchPaths>
<DesignTimeAssemblySearchPaths>$(DesignTimeAssemblySearchPaths);$(MicrosoftNetCoreAppRefPackRefDir.TrimEnd('/\'))</DesignTimeAssemblySearchPaths>
</PropertyGroup>
</Target> -->

<!-- SDK tries to download runtime packs when RuntimeIdentifier is set, remove them from PackageDownload item. -->
<Target Name="RemoveRuntimePackFromDownloadItem"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'"
AfterTargets="ProcessFrameworkReferences">
<ItemGroup>
<PackageDownload Remove="@(PackageDownload)"
Condition="'$(UsePackageDownload)' == 'true' and $([System.String]::Copy('%(Identity)').StartsWith('Microsoft.NETCore.App.Runtime'))" />
<PackageReference Remove="@(PackageReference)"
Condition="'$(UsePackageDownload)' != 'true' and $([System.String]::Copy('%(Identity)').StartsWith('Microsoft.NETCore.App.Runtime'))" />
</ItemGroup>
</Target>

<!-- Use local targeting pack for NetCoreAppCurrent. -->
<Target Name="UpdateTargetingAndRuntimePack"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'"
AfterTargets="ResolveFrameworkReferences">
<ItemGroup>
<ResolvedRuntimePack
Update="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
FrameworkName="Microsoft.NETCore.App"
NuGetPackageId="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
NuGetPackageVersion="$(_RuntimePackInWorkloadVersionCurrent)"
PackageDirectory="$(NetCoreTargetingPackRoot)\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\$(_RuntimePackInWorkloadVersionCurrent)"
RuntimeIdentifier="browser-wasm" />

<ResolvedFrameworkReference Update="Microsoft.NETCore.App"
RuntimePackName="Microsoft.NETCore.App.Runtime.Mono.browser-wasm"
RuntimePackVersion="$(_RuntimePackInWorkloadVersionCurrent)"
RuntimePackPath="$(NetCoreTargetingPackRoot)\Microsoft.NETCore.App.Runtime.Mono.browser-wasm\$(_RuntimePackInWorkloadVersionCurrent)"
RuntimeIdentifier="browser-wasm" />
</ItemGroup>
</Target>

<!-- Update the local targeting pack's version as it's written into the runtimeconfig.json file to select the right framework. -->
<Target Name="UpdateRuntimeFrameworkVersion"
AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<RuntimeFramework Version="$(_RuntimePackInWorkloadVersionCurrent)"
Condition="'%(RuntimeFramework.FrameworkName)' == 'Microsoft.NETCore.App'" />
</ItemGroup>
</Target>

<!-- Filter out conflicting implicit assembly references. -->
<Target Name="FilterImplicitAssemblyReferences"
Condition="'$(WBTOverrideRuntimePack)' == 'true' and '$(WasmNativeWorkload)' == 'true'"
DependsOnTargets="ResolveProjectReferences"
AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<_targetingPackReferenceExclusion Include="$(TargetName)" />
<_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->'%(Filename)')" />
<_targetingPackReferenceExclusion Include="@(DefaultReferenceExclusion)" />
</ItemGroup>

<ItemGroup>
<_targetingPackReferenceWithExclusion Include="@(Reference)">
<Exclusion>%(_targetingPackReferenceExclusion.Identity)</Exclusion>
</_targetingPackReferenceWithExclusion>
<Reference Remove="@(_targetingPackReferenceWithExclusion)"
Condition="'%(_targetingPackReferenceWithExclusion.ExternallyResolved)' == 'true' and '%(_targetingPackReferenceWithExclusion.Filename)' == '%(_targetingPackReferenceWithExclusion.Exclusion)'" />
</ItemGroup>
</Target>
</Project>

0 comments on commit fcceee9

Please sign in to comment.