Skip to content

Commit e503a03

Browse files
authored
Merge pull request #960 from unoplatform/dev/jela/linked-files-net10
fix: Adjust support for linked assets
2 parents f8675cc + 0ff0556 commit e503a03

File tree

8 files changed

+172
-102
lines changed

8 files changed

+172
-102
lines changed

build/ci/dotnet-install.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ steps:
1313
- pwsh: |
1414
$DotNetRoot = "C:\hostedtoolcache\windows\dotnet"
1515
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1"
16-
& ./build/installcli.ps1 -c 10.0 -q daily -InstallDir $DotNetRoot
16+
& ./build/installcli.ps1 -v 10.0.100-preview.2.25164.34 -InstallDir $DotNetRoot
1717
1818
condition: and(succeeded(), eq( variables['Agent.OS'], 'Windows_NT' ))
1919
displayName: 'Setup .NET (Windows)'
2020
2121
- pwsh: |
2222
wget https://dot.net/v1/dotnet-install.sh
2323
chmod +x dotnet-install.sh
24-
./dotnet-install.sh -c 10.0 -q daily
24+
./dotnet-install.sh -v 10.0.100-preview.2.25164.34
2525
echo "[task.setvariable variable=PATH;]${env:PATH}:$env:HOME/.dotnet"
2626
echo "[task.setvariable variable=DOTNET_ROOT;]$env:HOME/.dotnet"
2727

src/Uno.Wasm.Bootstrap/GenerateUnoAssetsManifestTask.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ namespace Uno.Wasm.Bootstrap;
3434

3535
public class GenerateUnoAssetsManifest_v0 : Microsoft.Build.Utilities.Task
3636
{
37+
private const string DefaultFingerprintExpression = "#[.{fingerprint}]?";
38+
3739
private string _intermediateAssetsPath = "";
40+
private string[]? _tokensByPattern;
3841

3942
[Required]
4043
public ITaskItem[] StaticWebAsset { get; set; } = [];
4144

4245
[Required]
4346
public string IntermediateOutputPath { get; set; } = "";
4447

48+
public ITaskItem[] FingerprintPatterns { get; set; } = [];
49+
4550
[Required]
4651
public string OutputPackagePath { get; set; } = "";
4752

@@ -57,7 +62,7 @@ public override bool Execute()
5762
// Grab the list of all the staticwebassets provided to be available in uno-assets.txt
5863
foreach(var asset in StaticWebAsset)
5964
{
60-
var assetPath = Path.GetDirectoryName(asset.GetMetadata("RelativePath")) + "/" + Path.GetFileName(asset.GetMetadata("FullPath"));
65+
var assetPath = ReplaceFingerprintPattern(asset.GetMetadata("RelativePath"));
6166
var sanitizedAssetPath = assetPath.Replace("\\", "/").TrimStart('/');
6267

6368
if (sanitizedAssetPath.StartsWith(OutputPackagePath + "/"))
@@ -77,6 +82,27 @@ public override bool Execute()
7782
return true;
7883
}
7984

85+
/// <summary>
86+
/// Replaces the fingerprint expressions in the original path, after it's been
87+
/// added by the DefineStaticWebAssets msbuild task.
88+
/// </summary>
89+
private string ReplaceFingerprintPattern(string relativePath)
90+
{
91+
// Based on https://github.com/dotnet/sdk/blob/d945ac60cc0073b6f0c3a55a4668e7251e7188c3/src/StaticWebAssetsSdk/Tasks/FingerprintPatternMatcher.cs#L13-L14
92+
93+
_tokensByPattern ??= FingerprintPatterns
94+
.Select(p => p.GetMetadata("Expression") is string expr and not "" ? expr : DefaultFingerprintExpression)
95+
.Distinct()
96+
.ToArray();
97+
98+
foreach (var expression in _tokensByPattern)
99+
{
100+
relativePath = relativePath.Replace(expression, "");
101+
}
102+
103+
return relativePath;
104+
}
105+
80106
private void AddStaticAsset(string targetPath, string filePath)
81107
{
82108
var contentRoot = targetPath.StartsWith(_intermediateAssetsPath)

src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
DependsOnTargets="$(UnoGenerateAssetsManifestDependsOn)">
271271
<GenerateUnoAssetsManifest_v0
272272
StaticWebAsset="@(StaticWebAsset)"
273+
FingerprintPatterns="@(StaticWebAssetFingerprintPattern)"
273274
OutputPackagePath="$(WasmShellOutputPackagePath)"
274275
IntermediateOutputPath="$(IntermediateOutputPath)">
275276
<Output TaskParameter="UnoAssetsFile" ItemName="_UnoAssetsManifest" />

src/Uno.Wasm.StaticLinking.Aot.UITests/app.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Uno.Wasm.StaticLinking.Aot.UITests/app.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ const path = require("path");
1818

1919
console.log(`Init puppeteer`);
2020

21-
let counter = 3;
21+
let counter = 10;
2222

23-
while (value === null && counter-- > 0) {
23+
while (counter-- > 0) {
2424
await delay(2000);
2525
try {
26-
value = await page.$eval('#results', a => a.textContent);
27-
console.log(`got value= ${value}`);
26+
value = await page.$eval('#results', a => a.innerText);
27+
console.log(`got value= [${value}]`);
28+
29+
if (value && value.length > 0) {
30+
break;
31+
}
2832
}
2933
catch (e) {
3034
console.log(`Waiting for results... (${e})`);
@@ -43,7 +47,7 @@ const path = require("path");
4347
}
4448

4549
let expected = process.platform === 'darwin' ? "Interpreter;" : "InterpreterAndAOT;";
46-
expected += "42;42.30;42.7;e42;True;true;True;1.2;1.4;3.1;0;42;requireJs:true;jsInterop:Invoked;gl:true;functionsExportsAvailable:true;sat:True;";
50+
expected += "42;42.30;42.7;e42;True;true;True;1.2;1.4;3.1;0;42;requireJs:true;jsInterop:Invoked;gl:true;ex:true;sat:True;la:True;";
4751

4852
if (value !== expected) {
4953
console.log(`Invalid results got ${value}, expected ${expected}`);

src/Uno.Wasm.StaticLinking.Shared/Common.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<ItemGroup>
2020
<PackageReference Include="System.Web.Services.Description" Version="4.10.0" />
2121
</ItemGroup>
22+
23+
<ItemGroup>
24+
<Content Include="$(MSBuildThisFileDirectory)../nuget.config" Link="Linked/nuget.linked.config" />
25+
</ItemGroup>
26+
2227
<ItemGroup>
2328
<WasmShellEmccExportedRuntimeMethod Include="GL" />
2429
<WasmShellEmccExportedRuntimeMethod Include="FS" />

src/Uno.Wasm.StaticLinking.Shared/Program.cs

Lines changed: 115 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,107 +21,129 @@
2121
using System;
2222
using System.Globalization;
2323
using System.IO;
24+
using System.Net.Http;
2425
using System.Numerics;
2526
using System.Runtime.InteropServices;
2627
using System.Runtime.Intrinsics;
28+
using System.Text;
2729
using System.Text.RegularExpressions;
2830
using System.Threading;
31+
using System.Threading.Tasks;
2932
using WebAssembly;
3033

3134
namespace Uno.Wasm.Sample
3235
{
3336
public static class Program
3437
{
35-
static void Main()
38+
static async Task Main()
3639
{
37-
// Validate mono tracing with __Native special pinvoke library name
38-
InternalImportTest.mono_trace_enable(1);
39-
40-
var runtimeMode = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE");
41-
Console.WriteLine($"Mono Runtime Mode: " + runtimeMode);
42-
43-
Console.WriteLine($"test_add:{SideModule1.test_add(21, 21)}");
44-
Console.WriteLine($"test_float:{SideModule1.test_add_float1(21, 21)}");
45-
Console.WriteLine($"test_add_double:{SideModule1.test_add_double(21, 21)}");
46-
47-
Console.WriteLine($"Before now");
48-
var now = DateTime.Now;
49-
Console.WriteLine($"now:{now} +1:{now.AddDays(1)} -1:{now.AddDays(-1)}");
50-
51-
var validateEmAddFunctionResult = int.Parse(Imports.ValidateEmAddFunction()) != 0;
52-
53-
var idbFSValidation = Imports.ValidateIDBFS();
54-
Console.WriteLine($"idbFSValidation: {idbFSValidation}");
55-
56-
var requireAvailable = Imports.RequireAvailable();
57-
Console.WriteLine($"requireAvailable: {requireAvailable}");
58-
59-
var glAvailable = Imports.GLAvailable();
60-
Console.WriteLine($"glAvailable: {glAvailable}");
61-
62-
var functionsExportsAvailable = Imports.FunctionsExportsAvailable();
63-
Console.WriteLine($"functionsExportsAvailable: {functionsExportsAvailable}");
64-
65-
var jsInteropResult = Imports.TestCallback();
66-
67-
var jsTimeZone = Imports.GetJSTimeZone();
68-
var clrTimeZone = TimeZoneInfo.Local.DisplayName;
69-
var timezoneValidation =
70-
#if NET5_0_OR_GREATER
71-
true; // Timezone support is not yet enabled for NET 5
72-
#else
73-
jsTimeZone == clrTimeZone;
74-
#endif
75-
76-
Console.WriteLine($"Timezone: {jsTimeZone};{clrTimeZone}");
77-
78-
Console.WriteLine($"SIMD: {Vector.IsHardwareAccelerated}");
79-
80-
#if NET7_0_OR_GREATER
81-
Console.WriteLine($"Vector64: {Vector64.IsHardwareAccelerated}");
82-
Console.WriteLine($"Vector128: {Vector128.IsHardwareAccelerated}");
83-
#endif
84-
85-
File.WriteAllText("/tmp/test.txt", "test.txt");
86-
var chmodRes = AdditionalImportTest.chmod("/tmp/test.txt", AdditionalImportTest.UGO_RWX);
87-
88-
var additionalNativeAdd = AdditionalImportTest.additional_native_add(21, 21);
89-
var additionalNativeAdd2 = AdditionalImportTest.additional_native_add2(21, 21);
90-
91-
var resManager = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly);
92-
var s1 = resManager.GetString("WebDescriptionMissing", new CultureInfo("en-US"));
93-
var s2 = resManager.GetString("WebDescriptionMissing", new CultureInfo("fr-CA"));
94-
Console.WriteLine($"Res(en-US): {s1}");
95-
Console.WriteLine($"Res(fr-CA): {s2}");
96-
97-
var satelliteValidation =
98-
s1 == "Cannot find definition for {0}. Service Description with namespace {1} is missing."
99-
&& s2 == "Impossible de localiser une définition pour {0}. Description du service manquante avec l'espace de noms {1}."
100-
;
101-
102-
var res = $"{runtimeMode};" +
103-
$"{SideModule1.test_add(21, 21)};" +
104-
$"{SideModule1.test_add_float1(21.1f, 21.2f):.00};" +
105-
$"{SideModule1.test_add_double(21.3, 21.4)};" +
106-
$"e{SideModule1.test_exception()};" +
107-
$"{validateEmAddFunctionResult};" +
108-
$"{idbFSValidation};" +
109-
$"{timezoneValidation};" +
110-
$"{SideModule2.side2_getCustomVersion()};" +
111-
$"{SideModule3.side3_getCustomVersion()};" +
112-
$"{SideModule4.side4_getCustomVersion()};" +
113-
$"{chmodRes};" +
114-
$"{additionalNativeAdd};" +
115-
$"requireJs:{requireAvailable};" +
116-
$"jsInterop:{jsInteropResult};" +
117-
$"gl:{glAvailable};"+
118-
$"functionsExportsAvailable:{functionsExportsAvailable};"+
119-
$"sat:{satelliteValidation};"
120-
;
121-
122-
var r = Imports.AppendResult(res);
123-
124-
SideModule1.test_png();
40+
try
41+
{
42+
// Validate mono tracing with __Native special pinvoke library name
43+
InternalImportTest.mono_trace_enable(1);
44+
45+
var runtimeMode = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_MONO_RUNTIME_MODE");
46+
Console.WriteLine($"Mono Runtime Mode: " + runtimeMode);
47+
48+
var appBase = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_APP_BASE");
49+
var webAppBase = Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_WEBAPP_BASE_PATH");
50+
51+
Console.WriteLine($"test_add:{SideModule1.test_add(21, 21)}");
52+
Console.WriteLine($"test_float:{SideModule1.test_add_float1(21, 21)}");
53+
Console.WriteLine($"test_add_double:{SideModule1.test_add_double(21, 21)}");
54+
55+
Console.WriteLine($"Before now");
56+
var now = DateTime.Now;
57+
Console.WriteLine($"now:{now} +1:{now.AddDays(1)} -1:{now.AddDays(-1)}");
58+
59+
var validateEmAddFunctionResult = int.Parse(Imports.ValidateEmAddFunction()) != 0;
60+
61+
var idbFSValidation = Imports.ValidateIDBFS();
62+
Console.WriteLine($"idbFSValidation: {idbFSValidation}");
63+
64+
var requireAvailable = Imports.RequireAvailable();
65+
Console.WriteLine($"requireAvailable: {requireAvailable}");
66+
67+
var glAvailable = Imports.GLAvailable();
68+
Console.WriteLine($"glAvailable: {glAvailable}");
69+
70+
var functionsExportsAvailable = Imports.FunctionsExportsAvailable();
71+
Console.WriteLine($"functionsExportsAvailable: {functionsExportsAvailable}");
72+
73+
var jsInteropResult = Imports.TestCallback();
74+
75+
var jsTimeZone = Imports.GetJSTimeZone();
76+
var clrTimeZone = TimeZoneInfo.Local.DisplayName;
77+
var timezoneValidation =
78+
#if NET5_0_OR_GREATER
79+
true; // Timezone support is not yet enabled for NET 5
80+
#else
81+
jsTimeZone == clrTimeZone;
82+
#endif
83+
84+
Console.WriteLine($"Timezone: {jsTimeZone};{clrTimeZone}");
85+
86+
Console.WriteLine($"SIMD: {Vector.IsHardwareAccelerated}");
87+
88+
#if NET7_0_OR_GREATER
89+
Console.WriteLine($"Vector64: {Vector64.IsHardwareAccelerated}");
90+
Console.WriteLine($"Vector128: {Vector128.IsHardwareAccelerated}");
91+
#endif
92+
93+
File.WriteAllText("/tmp/test.txt", "test.txt");
94+
var chmodRes = AdditionalImportTest.chmod("/tmp/test.txt", AdditionalImportTest.UGO_RWX);
95+
96+
var additionalNativeAdd = AdditionalImportTest.additional_native_add(21, 21);
97+
var additionalNativeAdd2 = AdditionalImportTest.additional_native_add2(21, 21);
98+
99+
var resManager = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly);
100+
var s1 = resManager.GetString("WebDescriptionMissing", new CultureInfo("en-US"));
101+
var s2 = resManager.GetString("WebDescriptionMissing", new CultureInfo("fr-CA"));
102+
Console.WriteLine($"Res(en-US): {s1}");
103+
Console.WriteLine($"Res(fr-CA): {s2}");
104+
105+
var satelliteValidation =
106+
s1 == "Cannot find definition for {0}. Service Description with namespace {1} is missing."
107+
&& s2 == "Impossible de localiser une définition pour {0}. Description du service manquante avec l'espace de noms {1}."
108+
;
109+
110+
var assetsUrl = $"{Imports.GetAppAddress()}{webAppBase}{appBase}/uno-assets.txt";
111+
Console.WriteLine($"Reading assets from {assetsUrl}");
112+
var assets = Encoding.UTF8.GetString(await new HttpClient().GetByteArrayAsync(assetsUrl));
113+
114+
var linkedAsset = assets.Contains("Linked/nuget.linked.config");
115+
116+
var res = $"{runtimeMode};" +
117+
$"{SideModule1.test_add(21, 21)};" +
118+
$"{SideModule1.test_add_float1(21.1f, 21.2f):.00};" +
119+
$"{SideModule1.test_add_double(21.3, 21.4)};" +
120+
$"e{SideModule1.test_exception()};" +
121+
$"{validateEmAddFunctionResult};" +
122+
$"{idbFSValidation};" +
123+
$"{timezoneValidation};" +
124+
$"{SideModule2.side2_getCustomVersion()};" +
125+
$"{SideModule3.side3_getCustomVersion()};" +
126+
$"{SideModule4.side4_getCustomVersion()};" +
127+
$"{chmodRes};" +
128+
$"{additionalNativeAdd};" +
129+
$"requireJs:{requireAvailable};" +
130+
$"jsInterop:{jsInteropResult};" +
131+
$"gl:{glAvailable};"+
132+
$"ex:{functionsExportsAvailable};"+
133+
$"sat:{satelliteValidation};" +
134+
$"la:{linkedAsset};"
135+
;
136+
137+
Console.WriteLine($"Test Results={res}");
138+
139+
var r = Imports.AppendResult(res);
140+
141+
SideModule1.test_png();
142+
}
143+
catch (Exception e)
144+
{
145+
Console.WriteLine($"Test run failed with {e}");
146+
}
125147
}
126148
}
127149

@@ -209,6 +231,10 @@ public static partial string ValidateIDBFS()
209231

210232
public static partial string ValidateIDBFS();
211233

234+
[System.Runtime.InteropServices.JavaScript.JSImport("globalThis.getLocation")]
235+
236+
public static partial string GetAppAddress();
237+
212238
#if !USE_JSIMPORT
213239
public static partial string RequireAvailable()
214240
=> Runtime.InvokeJS($"requireAvailable()");

0 commit comments

Comments
 (0)