Skip to content

Commit

Permalink
feat: Use SDK provided linker for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 22, 2022
1 parent a1ead0b commit bd4318b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Uno.Wasm.Bootstrap/ShellTask.cs
Expand Up @@ -767,12 +767,13 @@ private void RunPackager()
var emsdkPath = useFullPackager ? ValidateEmscripten() : "";

ValidateDotnet();
LinkerSetup();

var runtimeConfigurationParam = $"--runtime-config={RuntimeConfiguration.ToLowerInvariant()}" + (EnableThreads ? "-threads" : "") + " " + (EnableSimd ? "-simd" : "");
var pthreadPoolSizeParam = $"--pthread-pool-size={PThreadsPoolSize}";

var enableICUParam = EnableNetCoreICU ? "--icu" : "";
var monovmparams = $"--framework=net5 --runtimepack-dir=\"{AlignPath(MonoWasmSDKPath)}\" {enableICUParam} {pthreadPoolSizeParam}";
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 packagerPass1ResponseFile = Path.Combine(workAotPath, "packager-pass1.rsp");
Expand Down Expand Up @@ -868,6 +869,7 @@ private void RunPackager()
packagerParams.Add(debugOption);
packagerParams.Add(monovmparams);
packagerParams.Add("--zlib");
packagerParams.Add($"--illinker-path=\"{_linkerBinPath}\"");
packagerParams.Add("--enable-fs ");
packagerParams.Add($"--extra-emccflags=\"{extraEmccFlagsPararm} -l idbfs.js\" ");
packagerParams.Add($"--extra-linkerflags=\"{extraLinkerFlags}\"");
Expand Down Expand Up @@ -924,8 +926,6 @@ private void RunPackager()
MonoILLinker
)
{
LinkerSetup();

var linkerInput = Path.Combine(IntermediateOutputPath, "linker-in");
var linkerResponse = Path.Combine(linkerInput, "linker.rsp");
var linkerParams = new List<string>();
Expand Down
26 changes: 12 additions & 14 deletions src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets
Expand Up @@ -26,26 +26,16 @@
<WasmShellEnableThreads Condition="'$(WasmShellEnableThreads)'==''">false</WasmShellEnableThreads>
<WasmShellEnableSimd Condition="'$(WasmShellEnableSimd)'==''">false</WasmShellEnableSimd>

<!--
Set this variable to use custom debugger binaries instead of the files found
in the active mono-wasm folder.
-->
<!--<MonoRuntimeCustomDebuggerPath>$(MSBuildThisFileDirectory)CustomDebuggerProxy</MonoRuntimeCustomDebuggerPath>-->
<!--
Uncomment to enable custom linker path
<MonoRuntimeCustomLinkerPath>$(MSBuildThisFileDirectory)</MonoRuntimeCustomLinkerPath>
-->

<!--
Force all applicable references to be present in the ReferenceCopyLocalPaths property.
Otherwise, the ReferencePath property only contains reference assemblies if those are available.
-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<!--
When using IISExpress with a standalone app, there's no point restarting IISExpress
after build. It slows things unnecessarily and breaks in-flight HTTP requests.
-->
When using IISExpress with a standalone app, there's no point restarting IISExpress
after build. It slows things unnecessarily and breaks in-flight HTTP requests.
-->
<NoRestartServerOnBuild>true</NoRestartServerOnBuild>

<!-- Disable unwanted parts of the default publish process -->
Expand Down Expand Up @@ -180,6 +170,14 @@
<_WasmShellToolSuffix Condition="'$(_WasmShellIsNetCore)'!='true'">net462</_WasmShellToolSuffix>
<_WasmShellToolSuffix Condition="'$(_WasmShellIsNetCore)'=='true'">net5.0</_WasmShellToolSuffix>

<WasmShellLinkerPath
Condition="
'$(WasmShellLinkerPath)'==''
and '$(TargetFrameworkIdentifier)'=='.NETCoreApp'
and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))
and '$(ILLinkTasksAssembly)'!=''"
>$([System.IO.Path]::GetDirectoryName($(ILLinkTasksAssembly)))\..\net$(BundledNETCoreAppTargetFrameworkVersion)</WasmShellLinkerPath>

</PropertyGroup>

<UnoInstallSDKTask_v0
Expand Down Expand Up @@ -220,7 +218,7 @@
ContentExtensionsToExclude="$(WasmShellContentExtensionsToExclude)"
CurrentProjectPath="$(MSBuildProjectDirectory)"
CustomDebuggerPath="$(MonoRuntimeCustomDebuggerPath)"
CustomLinkerPath="$(MonoRuntimeCustomLinkerPath)"
CustomLinkerPath="$(WasmShellLinkerPath)"
DistCompressionLayoutMode="$(WasmShellCompressionLayoutMode)"
DistPath="$(WasmShellDistPath)"
EmccExportedRuntimeMethods="@(WasmShellEmccExportedRuntimeMethod)"
Expand Down
5 changes: 4 additions & 1 deletion src/Uno.Wasm.Packager/packager.cs
Expand Up @@ -463,6 +463,7 @@ class WasmOptions {
string wasm_runtime_path = null;
var runtime_config = "release";
int pthread_pool_size = 4;
string illinker_path = "";
string extra_emccflags = "";
string extra_linkerflags = "";
string linker_optimization_level = "";
Expand Down Expand Up @@ -519,6 +520,7 @@ class WasmOptions {
{ "emcc-exported-runtime-method=", s => emcc_exported_runtime_methods.Add (s) },
{ "framework=", s => framework = s },
{ "extra-emccflags=", s => extra_emccflags = s },
{ "illinker-path=", s => illinker_path = s },
{ "extra-linkerflags=", s => extra_linkerflags = s },
{ "linker-optimization-level=", s => linker_optimization_level = s },
{ "help", s => print_usage = true },
Expand Down Expand Up @@ -1181,6 +1183,7 @@ class WasmOptions {
ninja.WriteLine ($"bcl_facades_dir = {bcl_facades_prefix}");
ninja.WriteLine ($"framework_dir = {framework_prefix}");
ninja.WriteLine ($"tools_dir = {bcl_tools_prefix}");
ninja.WriteLine ($"linker_dir = {illinker_path}");

if (!is_windows)
{
Expand Down Expand Up @@ -1331,7 +1334,7 @@ class WasmOptions {
ninja.WriteLine($" description = [EMCC-LINK] $in -> $out");

ninja.WriteLine ("rule linker");
var linkerBin = "dotnet $tools_dir/illink.dll";
var linkerBin = "dotnet \'$linker_dir/illink.dll\'";

var linkerSearchPaths = root_search_paths.Concat(bcl_prefixes).Distinct().Select(p => $"-d \"{p}\" ");

Expand Down

0 comments on commit bd4318b

Please sign in to comment.