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

[browser] Use StaticWebAssets fingerprinting in Wasm SDK #103755

Merged
merged 63 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5485ef0
Build and publish integration
maraf Jun 20, 2024
2c0d21f
Make fingerpring work at runtime for assemblies
maraf Jun 20, 2024
da8f2ec
Make fingerpring work at runtime for icu
maraf Jun 20, 2024
a923583
Remove version fingerprint check
maraf Jun 20, 2024
00695e7
Check core assembly extension
maraf Jun 20, 2024
7eb15d6
Merge branch 'main' into BrowserFingerprinting
lewing Jun 21, 2024
de7ab09
Typescript nits
maraf Jun 21, 2024
99d9b6a
JSModules and SatelliteAssemblies
maraf Jun 21, 2024
163fe82
DEBUG require newer SDK for testing
maraf Jun 21, 2024
bfbb518
Fix fingerprint for new publish assets
maraf Jun 21, 2024
574d899
Lazy loading and FP mapping boot json
maraf Jun 21, 2024
a650967
Merge branch 'main' into BrowserFingerprinting
maraf Jul 9, 2024
8848871
WBT file on disk checks
maraf Jul 9, 2024
e40c14e
WBT file on disk checks
maraf Jul 9, 2024
fd8b240
WBT file on disk checks
maraf Jul 9, 2024
d642b3c
WBT testmain no fingerprint
maraf Jul 10, 2024
4d3c657
WBT revert debug message
maraf Jul 11, 2024
a2eac11
AOT
maraf Jul 11, 2024
5cbda67
WBT fix ordering
maraf Jul 11, 2024
71f7fa3
Fingerprinting without webcil
maraf Jul 11, 2024
f25f7de
Fix GenerateWasmBootJson when FP is off
maraf Jul 11, 2024
b2e1ffa
NoFingerprint WBT variant
maraf Jul 11, 2024
a411302
DEBUG try to run WBT without fingerprinting
maraf Jul 12, 2024
fd55a18
WBT make entry comparison order agnostic
maraf Jul 12, 2024
1e88e55
WBT smoke tests for no-fingerprinting
maraf Jul 12, 2024
a3fd46a
Update sendtohelix-browser.targets
maraf Jul 12, 2024
5f662b2
Remove debug log
maraf Jul 12, 2024
1cd4de4
Fix typo
maraf Jul 16, 2024
754b5f2
Fix regex matching
maraf Jul 16, 2024
1c11007
Remove test for dotnet.js FP since we don't support that anymore
maraf Jul 16, 2024
d3a8ba1
Fix check for System.Private.CoreLib
maraf Jul 16, 2024
653643a
FP for dotnet.globalization.js
maraf Jul 16, 2024
90de8b7
Fingerprinting pdbs
maraf Jul 16, 2024
2637a00
Merge remote-tracking branch 'upstream/main' into BrowserFingerprinting
maraf Jul 16, 2024
57f1c0f
WBT fix file check
maraf Jul 16, 2024
1f880a4
Fingerprint segmentation-rules.json
maraf Jul 17, 2024
08e443a
Fix loading pdb for fingerprinted lazy assembly
maraf Jul 17, 2024
12bb74c
Ensure lazy pdb is loaded
maraf Jul 18, 2024
2b8ccb1
Remove non-WasmSDK tests from non-FP category
maraf Jul 18, 2024
51cd688
Revert drop for dotnet.js finterprinting
maraf Jul 18, 2024
a531dc8
Compute non-Fingerprinted virtualPath for pdb and resource as well
maraf Jul 18, 2024
31d1a73
Make debugger working with fingerprinted assemblies and pdbs
maraf Jul 18, 2024
dc91e20
DEBUG latest SDK for WBT
maraf Jul 18, 2024
c0d3d62
DEBUG fix wbt installation
maraf Jul 18, 2024
907ce2c
Add WorkloadBuildTasks to WasmBuild.sln
maraf Jul 18, 2024
e367713
Fix WBT
maraf Jul 19, 2024
4738dac
Merge branch 'main' into BrowserFingerprinting
maraf Jul 19, 2024
b78497f
Revert escaping URL in debugger
maraf Jul 19, 2024
7ff25a5
Merge branch 'main' into BrowserFingerprinting
maraf Jul 19, 2024
768af43
Fix lazy loading test and message emit in release config
maraf Jul 19, 2024
0e705fa
Fixes for MT after merge
maraf Jul 19, 2024
5db6c0e
Skip WBT without workloads and without fingerprinting
maraf Jul 19, 2024
79283fb
Merge branch 'main' into BrowserFingerprinting
lewing Jul 21, 2024
46cb7b3
Turn off fingerprinting when targeting downlevel versions
maraf Jul 22, 2024
dc1f048
Merge remote-tracking branch 'upstream/main' into BrowserFingerprinting
maraf Jul 22, 2024
c8a645c
Git ignore *.d.ts.sha256
maraf Jul 22, 2024
d076290
Fix
maraf Jul 22, 2024
bef50ee
Update source-build-reference-packages to latest
lewing Jul 22, 2024
05a3854
Revert "Update source-build-reference-packages to latest"
lewing Jul 23, 2024
f673b26
Fix the references
lewing Jul 23, 2024
ac0a52d
Update Versions.props
lewing Jul 23, 2024
5d8917a
Update Versions.props
lewing Jul 23, 2024
3e0efe6
Merge branch 'main' into BrowserFingerprinting
maraf Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<StaticWebAssetsGetPublishAssetsTargets>ComputeFilesToPublish;GetCurrentProjectPublishStaticWebAssetItems</StaticWebAssetsGetPublishAssetsTargets>
<StaticWebAssetsAdditionalPublishProperties>$(StaticWebAssetsAdditionalPublishProperties);BuildProjectReferences=false;ResolveAssemblyReferencesFindRelatedSatellites=true</StaticWebAssetsAdditionalPublishProperties>
<StaticWebAssetsAdditionalPublishPropertiesToRemove>$(StaticWebAssetsAdditionalPublishPropertiesToRemove);NoBuild;RuntimeIdentifier</StaticWebAssetsAdditionalPublishPropertiesToRemove>
<StaticWebAssetStandaloneHosting Condition="'$(StaticWebAssetStandaloneHosting)' == '' and '$(StaticWebAssetProjectMode)' == 'Root'">true</StaticWebAssetStandaloneHosting>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Runtime feature defaults to trim unnecessary code -->
<InvariantTimezone Condition="'$(BlazorEnableTimeZoneSupport)' == 'false'">true</InvariantTimezone>
<BlazorCacheBootResources Condition="'$(BlazorCacheBootResources)' == ''">true</BlazorCacheBootResources>
<WasmFingerprintDotnetJs Condition="'$(WasmFingerprintDotnetJs)' == ''">false</WasmFingerprintDotnetJs>

<!-- Turn off parts of the build that do not apply to WASM projects -->
<GenerateDependencyFile>false</GenerateDependencyFile>
Expand Down Expand Up @@ -194,6 +193,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache)</_BlazorWebAssemblyStartupMemoryCache>
<_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter)</_BlazorWebAssemblyJiterpreter>
<_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions)</_BlazorWebAssemblyRuntimeOptions>
<_WasmFingerprintAssets>$(WasmFingerprintAssets)</_WasmFingerprintAssets>
<_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">true</_WasmFingerprintAssets>

<!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
<PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
Expand Down Expand Up @@ -238,10 +239,8 @@ Copyright (c) .NET Foundation. All rights reserved.
InvariantGlobalization="$(_WasmInvariantGlobalization)"
HybridGlobalization="$(_IsHybridGlobalization)"
LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
DotNetJsVersion="$(_WasmRuntimePackVersion)"
CopySymbols="$(_WasmCopyOutputSymbolsToOutputDirectory)"
OutputPath="$(OutputPath)"
FingerprintDotNetJs="$(WasmFingerprintDotnetJs)"
EnableThreads="$(_WasmEnableThreads)"
EmitSourceMap="$(_WasmEmitSourceMapBuild)"
>
Expand All @@ -259,6 +258,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
</ConvertDllsToWebCil>

<ItemGroup>
<_WasmFingerprintPatterns Include="WasmFiles" Pattern="*.wasm" Expression="#[.{fingerprint}]!" />
maraf marked this conversation as resolved.
Show resolved Hide resolved
maraf marked this conversation as resolved.
Show resolved Hide resolved
<_WasmFingerprintPatterns Include="DatFiles" Pattern="*.dat" Expression="#[.{fingerprint}]!" />
<_WasmFingerprintPatterns Include="Pdb" Pattern="*.pdb" Expression="#[.{fingerprint}]!" />
</ItemGroup>

<DefineStaticWebAssets
CandidateAssets="@(_WebCilAssetsCandidates)"
SourceId="$(PackageId)"
Expand All @@ -268,6 +273,8 @@ Copyright (c) .NET Foundation. All rights reserved.
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="Never"
ContentRoot="$(OutputPath)wwwroot"
FingerprintCandidates="$(_WasmFingerprintAssets)"
FingerprintPatterns="@(FingerprintPatterns);@(_WasmFingerprintPatterns)"
BasePath="$(StaticWebAssetBasePath)"
>
<Output TaskParameter="Assets" ItemName="WasmStaticWebAsset" />
Expand Down Expand Up @@ -321,10 +328,6 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="'%(StaticWebAsset.AssetTraitName)' == 'JSModule' and '%(StaticWebAsset.AssetTraitValue)' == 'JSLibraryModule' and '%(AssetKind)' != 'Publish'" />
</ItemGroup>

<GetFileHash Files="@(WasmStaticWebAsset->'%(OriginalItemSpec)')" Algorithm="SHA256" HashEncoding="base64">
<Output TaskParameter="Items" ItemName="_WasmOutputWithHash" />
</GetFileHash>

<ComputeStaticWebAssetsTargetPaths
Assets="@(_WasmJsModuleCandidatesForBuild)"
PathPrefix=""
Expand All @@ -333,13 +336,26 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="AssetsWithTargetPath" ItemName="_WasmJsModuleCandidatesForBuildWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>
maraf marked this conversation as resolved.
Show resolved Hide resolved

<GetFileHash Files="@(_WasmJsModuleCandidatesForBuildWithTargetPath)" Algorithm="SHA256" HashEncoding="base64">
<Output TaskParameter="Items" ItemName="_WasmOutputWithHash" />
</GetFileHash>
<DefineStaticWebAssetEndpoints
CandidateAssets="@(WasmStaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="WasmStaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>

<ResolveFingerprintedStaticWebAssetEndpointsForAssets
CandidateEndpoints="@(WasmStaticWebAssetEndpoint)"
CandidateAssets="@(WasmStaticWebAsset)"
maraf marked this conversation as resolved.
Show resolved Hide resolved
IsStandalone="$(StaticWebAssetStandaloneHosting)"
>
<Output TaskParameter="ResolvedEndpoints" ItemName="_WasmResolvedEndpoints" />
</ResolveFingerprintedStaticWebAssetEndpointsForAssets>

<GenerateWasmBootJson
AssemblyPath="@(IntermediateAssembly)"
Resources="@(_WasmOutputWithHash)"
Resources="@(WasmStaticWebAsset);@(_WasmJsModuleCandidatesForBuildWithTargetPath)"
Endpoints="@(_WasmResolvedEndpoints)"
DebugBuild="true"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="false"
Expand Down Expand Up @@ -400,14 +416,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="Endpoints" ItemName="_BuildWasmBootJsonStaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>

<DefineStaticWebAssetEndpoints
CandidateAssets="@(WasmStaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="WasmStaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>

</Target>

<Target Name="ProvideDefaultUserRuntimeConfig" BeforeTargets="_GenerateRuntimeConfigurationFilesInputCache" Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'">
Expand Down Expand Up @@ -465,13 +473,13 @@ Copyright (c) .NET Foundation. All rights reserved.
LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)"
CopySymbols="$(CopyOutputSymbolsToPublishDirectory)"
ExistingAssets="@(_WasmPublishPrefilteredAssets)"
DotNetJsVersion="$(_WasmRuntimePackVersion)"
FingerprintDotNetJs="$(WasmFingerprintDotnetJs)"
EnableThreads="$(_WasmEnableThreads)"
EmitSourceMap="$(_WasmEmitSourceMapPublish)"
IsWebCilEnabled="$(_WasmEnableWebcil)"
IsFingerprintingEnabled="$(_WasmFingerprintAssets)"
>
<Output TaskParameter="NewCandidates" ItemName="_NewWasmPublishStaticWebAssets" />
<Output TaskParameter="PromotedAssets" ItemName="_PromotedWasmPublishStaticWebAssets" />
<Output TaskParameter="FilesToRemove" ItemName="_PublishResolvedFilesToRemove" />
</ComputeWasmPublishAssets>

Expand All @@ -494,7 +502,7 @@ Copyright (c) .NET Foundation. All rights reserved.
RemoveMetadata="Integrity;Fingerprint" />
</ItemGroup>

<DefineStaticWebAssets CandidateAssets="@(_NewWebCilPublishStaticWebAssetsCandidatesNoMetadata)">
<DefineStaticWebAssets CandidateAssets="@(_NewWebCilPublishStaticWebAssetsCandidates);@(_PromotedWasmPublishStaticWebAssets)">
<Output TaskParameter="Assets" ItemName="_NewWebCilPublishStaticWebAssets" />
</DefineStaticWebAssets>

Expand Down Expand Up @@ -627,13 +635,18 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="AssetsWithTargetPath" ItemName="_WasmCandidatesForPublishWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>

<GetFileHash Files="@(_WasmPublishAsset);@(_WasmCandidatesForPublishWithTargetPath)" Algorithm="SHA256" HashEncoding="base64">
<Output TaskParameter="Items" ItemName="_WasmPublishBootResourceWithHash" />
</GetFileHash>
<ResolveFingerprintedStaticWebAssetEndpointsForAssets
CandidateEndpoints="@(StaticWebAssetEndpoint)"
CandidateAssets="@(_WasmPublishAsset);@(_WasmCandidatesForPublishWithTargetPath)"
IsStandalone="$(StaticWebAssetStandaloneHosting)"
>
<Output TaskParameter="ResolvedEndpoints" ItemName="_WasmResolvedEndpointsForPublish" />
</ResolveFingerprintedStaticWebAssetEndpointsForAssets>

<GenerateWasmBootJson
AssemblyPath="@(IntermediateAssembly)"
Resources="@(_WasmPublishBootResourceWithHash)"
Resources="@(_WasmPublishAsset);@(_WasmCandidatesForPublishWithTargetPath)"
Endpoints="@(_WasmResolvedEndpointsForPublish)"
DebugBuild="false"
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="$(PublishTrimmed)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,29 @@ private static bool IsFromMonoPackage(ITaskItem candidate)

public static string GetCandidateRelativePath(ITaskItem candidate)
{
const string optionalFingerprint = "#[.{fingerprint}]?";
const string requiredFingerprint = "#[.{fingerprint}]!";

string fileName = candidate.GetMetadata("FileName");
string extension = candidate.GetMetadata("Extension");
string subPath = string.Empty;

var destinationSubPath = candidate.GetMetadata("DestinationSubPath");
javiercn marked this conversation as resolved.
Show resolved Hide resolved
if (!string.IsNullOrEmpty(destinationSubPath))
return $"_framework/{destinationSubPath}";
{
fileName = Path.GetFileNameWithoutExtension(destinationSubPath);
extension = Path.GetExtension(destinationSubPath);
subPath = destinationSubPath.Substring(fileName.Length + extension.Length);
}

var relativePath = candidate.GetMetadata("FileName") + candidate.GetMetadata("Extension");
return $"_framework/{relativePath}";
string relativePath = (fileName, extension) switch {
("dotnet", ".js") => string.Concat(fileName, optionalFingerprint, extension),
("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension),
("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension),
("dotnet.worker", ".js") => string.Concat(fileName, requiredFingerprint, extension),
_ => string.Concat(fileName, extension)
};
return $"_framework/{subPath}{relativePath}";
}

public static ITaskItem GetCustomIcuAsset(ITaskItem candidate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public class ComputeWasmBuildAssets : Task
[Required]
public ITaskItem[] ProjectSatelliteAssemblies { get; set; }

[Required]
public string DotNetJsVersion { get; set; }
maraf marked this conversation as resolved.
Show resolved Hide resolved

[Required]
public string OutputPath { get; set; }

Expand All @@ -52,8 +49,6 @@ public class ComputeWasmBuildAssets : Task
[Required]
public bool CopySymbols { get; set; }

public bool FingerprintDotNetJs { get; set; }

public bool EnableThreads { get; set; }

public bool EmitSourceMap { get; set; }
Expand Down Expand Up @@ -117,44 +112,8 @@ public override bool Execute()
continue;
}

string candidateFileName = candidate.GetMetadata("FileName");
if (candidateFileName.StartsWith("dotnet") && candidate.GetMetadata("Extension") == ".js")
{
string newDotnetJSFileName = null;
string newDotNetJSFullPath = null;
if (candidateFileName != "dotnet" || FingerprintDotNetJs)
{
var itemHash = FileHasher.GetFileHash(candidate.ItemSpec);
newDotnetJSFileName = $"{candidateFileName}.{DotNetJsVersion}.{itemHash}.js";

var originalFileFullPath = Path.GetFullPath(candidate.ItemSpec);
var originalFileDirectory = Path.GetDirectoryName(originalFileFullPath);

newDotNetJSFullPath = Path.Combine(originalFileDirectory, newDotnetJSFileName);
}
else
{
newDotNetJSFullPath = candidate.ItemSpec;
newDotnetJSFileName = Path.GetFileName(newDotNetJSFullPath);
}

var newDotNetJs = new TaskItem(newDotNetJSFullPath, candidate.CloneCustomMetadata());
newDotNetJs.SetMetadata("OriginalItemSpec", candidate.ItemSpec);

var newRelativePath = $"_framework/{newDotnetJSFileName}";
newDotNetJs.SetMetadata("RelativePath", newRelativePath);

newDotNetJs.SetMetadata("AssetTraitName", "WasmResource");
newDotNetJs.SetMetadata("AssetTraitValue", "native");

assetCandidates.Add(newDotNetJs);
continue;
}
else
{
string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate);
candidate.SetMetadata("RelativePath", relativePath);
}
string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate);
candidate.SetMetadata("RelativePath", relativePath);

// Workaround for https://github.com/dotnet/aspnetcore/issues/37574.
// For items added as "Reference" in project references, the OriginalItemSpec is incorrect.
Expand Down Expand Up @@ -264,6 +223,7 @@ private static void ApplyUniqueMetadataProperties(ITaskItem candidate)
break;
case ".wasm":
case ".blat":
case ".js" when filename.StartsWith("dotnet"):
case ".dat" when filename.StartsWith("icudt"):
case ".json" when filename.StartsWith("segmentation-rules"):
candidate.SetMetadata("AssetTraitName", "WasmResource");
Expand Down
Loading
Loading