From 3ef53c9ac1a65315d6aca1286edec1eb6deaea82 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sun, 23 Jun 2024 20:10:42 -0400 Subject: [PATCH 1/3] fix: Use assembly full path search first --- src/Uno.Wasm.Bootstrap/ShellTask.cs | 11 +++++++-- .../CapturingAssemblyResolver.cs | 24 ++++++++++++++++++- src/Uno.Wasm.Packager/packager.cs | 4 +++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index b7807b2a3..be1433d6f 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -776,7 +776,13 @@ private void RunPackager() DirectoryCreateDirectory(workAotPath); - var referencePathsParameter = string.Join(" ", _referencedAssemblies.Select(Path.GetDirectoryName).Distinct().Select(r => $"--search-path=\"{AlignPath(r)}\"")); + var referencePathsParameter = string.Join( + " " + , _referencedAssemblies.Select(Path.GetDirectoryName).Distinct().Select(r => $"--search-path=\"{AlignPath(r)}\"")); + + var referenceAssembliesParameter = string.Join( + " " + , _referencedAssemblies.Distinct().Select(r => $"--asm-ref=\"{AlignPath(r)}\"")); var metadataUpdaterPath = Path.Combine(BuildTaskBasePath, "..", "tools", "support", "Uno.Wasm.MetadataUpdater.dll"); @@ -824,7 +830,7 @@ private void RunPackager() var enableICUParam = EnableNetCoreICU ? "--icu" : ""; var monovmparams = $"--framework=net5 --runtimepack-dir=\"{AlignPath(MonoWasmSDKPath)}\" {enableICUParam} {pthreadPoolSizeParam} --illinker-path=\"{_linkerBinPath}\""; - var pass1ResponseContent = $"{runtimeConfigurationParam} {appDirParm} {monovmparams} --zlib {debugOption} {referencePathsParameter} \"{AlignPath(TryConvertLongPath(Path.GetFullPath(Assembly)))}\""; + var pass1ResponseContent = $"{runtimeConfigurationParam} {appDirParm} {monovmparams} --zlib {debugOption} {referenceAssembliesParameter} {referencePathsParameter} \"{AlignPath(TryConvertLongPath(Path.GetFullPath(Assembly)))}\""; var packagerPass1ResponseFile = Path.Combine(workAotPath, "packager-pass1.rsp"); File.WriteAllText(packagerPass1ResponseFile, pass1ResponseContent); @@ -935,6 +941,7 @@ private void RunPackager() packagerParams.Add(EmccLinkOptimization ? "--emcc-link-optimization" : ""); packagerParams.Add(MonoILLinker ? "--linker --link-mode=all" : ""); packagerParams.Add(referencePathsParameter); + packagerParams.Add(referenceAssembliesParameter); packagerParams.Add(GenerateAOTProfile ? "--profile=aot" : ""); packagerParams.Add(EnableLogProfiler ? "--profile=log" : ""); packagerParams.Add(!string.IsNullOrEmpty(WasmTunerBinPath) ? $"\"--wasm-tuner-path={AlignPath(Path.GetFullPath(WasmTunerBinPath))}\"" : ""); diff --git a/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs b/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs index 658ab85eb..3865e488c 100644 --- a/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs +++ b/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs @@ -10,6 +10,12 @@ class CapturingAssemblyResolver : DefaultAssemblyResolver { private List> _files; + private List _assembly_references; + + public CapturingAssemblyResolver(List assembly_references) + { + _assembly_references = assembly_references; + } protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name, IEnumerable directories, ReaderParameters parameters) { @@ -19,6 +25,23 @@ protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name // paying the cost of File.Exists _files = new List>(); + + // Fill all the known references first, so they get resolved + // using compilation paths. + var explicitAssembliesPaths = new Dictionary(); + foreach(var asmReferencePath in _assembly_references) + { + if (Path.GetFileNameWithoutExtension(asmReferencePath) is { } asmName) + { + if (!explicitAssembliesPaths.ContainsKey(asmName)) + { + explicitAssembliesPaths.Add(asmName, asmReferencePath); + } + } + } + + _files.Add(explicitAssembliesPaths); + string[] extensions = new[] { ".winmd", ".dll", ".exe", ".dll" }; foreach (var directory in directories.Where(Directory.Exists)) @@ -39,7 +62,6 @@ protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name } } - _files.Add(map); } } diff --git a/src/Uno.Wasm.Packager/packager.cs b/src/Uno.Wasm.Packager/packager.cs index abe53fcbc..79abd9018 100644 --- a/src/Uno.Wasm.Packager/packager.cs +++ b/src/Uno.Wasm.Packager/packager.cs @@ -61,6 +61,7 @@ class Driver { static List file_list = new List (); static HashSet assemblies_with_dbg_info = new HashSet (); static List root_search_paths = new List(); + static List assembly_references = new List(); static CapturingAssemblyResolver resolver; const string BINDINGS_ASM_NAME_MONO = "WebAssembly.Bindings"; @@ -278,7 +279,7 @@ static void Import (string ra, AssemblyKind kind) { if (resolver == null) { - resolver = new CapturingAssemblyResolver(); + resolver = new CapturingAssemblyResolver(assembly_references); root_search_paths.ForEach(resolver.AddSearchDirectory); foreach (var prefix in bcl_prefixes) resolver.AddSearchDirectory(prefix); @@ -554,6 +555,7 @@ int Run (string[] args) { { "template=", s => runtimeTemplate = s }, { "asset=", s => assets.Add(s) }, { "search-path=", s => root_search_paths.Add(s) }, + { "asm-ref=", s => assembly_references.Add(s) }, { "profile=", s => profilers.Add (s) }, { "copy=", s => copyTypeParm = s }, { "aot-assemblies=", s => aot_assemblies = s }, From f93d9f999c02adb3c9c1945c957f0a4fa37a5a7b Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Sun, 23 Jun 2024 20:30:34 -0400 Subject: [PATCH 2/3] chore: Adjust search paths --- src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs b/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs index 3865e488c..5d45f9776 100644 --- a/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs +++ b/src/Uno.Wasm.Packager/CapturingAssemblyResolver.cs @@ -29,7 +29,7 @@ protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name // Fill all the known references first, so they get resolved // using compilation paths. var explicitAssembliesPaths = new Dictionary(); - foreach(var asmReferencePath in _assembly_references) + foreach (var asmReferencePath in _assembly_references) { if (Path.GetFileNameWithoutExtension(asmReferencePath) is { } asmName) { @@ -42,6 +42,7 @@ protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name _files.Add(explicitAssembliesPaths); + // Use all other search paths string[] extensions = new[] { ".winmd", ".dll", ".exe", ".dll" }; foreach (var directory in directories.Where(Directory.Exists)) @@ -62,6 +63,7 @@ protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name } } + _files.Add(map); } } From 334e219e3a0f0009d74fa7952e5506f80e4e0bf8 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Mon, 24 Jun 2024 22:24:44 -0400 Subject: [PATCH 3/3] chore: Adjust linker parameters --- src/Uno.Wasm.Bootstrap/ShellTask.cs | 5 +++++ src/Uno.Wasm.Packager/packager.cs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index be1433d6f..ea1490211 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -1015,6 +1015,11 @@ private void RunPackager() var assemblyPath = Path.Combine(linkerInput, Path.GetFileName(Assembly)); + // Use explicit assemby references first + var referenceAssemblyPaths = _referencedAssemblies.Distinct().Select(p => $"-reference \"{p}\" "); + linkerParams.AddRange(referenceAssemblyPaths); + + // Then search for other known paths var linkerSearchPaths = _referencedAssemblies.Select(Path.GetDirectoryName).Distinct().Select(p => $"-d \"{p}\" "); linkerParams.AddRange(linkerSearchPaths); linkerParams.Add($"-d \"{_bclPath}\""); diff --git a/src/Uno.Wasm.Packager/packager.cs b/src/Uno.Wasm.Packager/packager.cs index 79abd9018..0c364d8ed 100644 --- a/src/Uno.Wasm.Packager/packager.cs +++ b/src/Uno.Wasm.Packager/packager.cs @@ -1586,6 +1586,7 @@ int Run (string[] args) { ninja.WriteLine ("rule linker"); var linkerBin = "dotnet \'$linker_dir/illink.dll\'"; + var assemblyRefPaths = assembly_references.Distinct().Select(p => $"-reference \"{p}\" "); var linkerSearchPaths = root_search_paths.Concat(bcl_prefixes).Distinct().Select(p => $"-d \"{p}\" "); var tunerBinary = string.IsNullOrEmpty(wasm_tuner_path) @@ -1599,6 +1600,7 @@ int Run (string[] args) { linker_args.Add($"-out ./linker-out --deterministic --disable-opt unreachablebodies"); linker_args.Add($"--strip-link-attributes"); linker_args.Add(extra_linkerflags); + linker_args.AddRange(assemblyRefPaths); linker_args.AddRange(linkerSearchPaths); ninja.WriteLine ($" command = {tools_shell_prefix} {linkerBin} \'@{linkerResponse}\' {exitCommand}; {tunerCommand} --gen-empty-assemblies \'@$builddir/tuner.rsp\'");