Skip to content

Commit

Permalink
Merge pull request #19312 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.6/pr-19304

fix(hr): Dev-server HR support for mobile targets (backport #19304)
  • Loading branch information
jeromelaban authored Jan 24, 2025
2 parents b5f1671 + 043584d commit 0971565
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 75 deletions.
1 change: 1 addition & 0 deletions build/Uno.UI.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
<XmlPoke XmlInputPath=".\nuget\Uno.WinUI.nuspec" Query="/x:package/x:files/x:file[@target='buildTransitive\net8.0-windows\uno.winui.targets']/@target" Value="buildTransitive\net8.0-windows\$(PackageNamePrefix).targets" Namespaces="$(NugetNamespace)" Condition="'$(UNO_UWP_BUILD)'=='true'"/>

<!-- remote control -->
<Move SourceFiles="..\src\Uno.UI.RemoteControl\buildTransitive\Uno.WinUI.DevServer.props" DestinationFiles="..\src\Uno.UI.RemoteControl\buildTransitive\$(PackageNamePrefix).DevServer.props" Condition="'$(UNO_UWP_BUILD)'=='true'"/>
<Move SourceFiles="..\src\Uno.UI.RemoteControl\buildTransitive\Uno.WinUI.DevServer.targets" DestinationFiles="..\src\Uno.UI.RemoteControl\buildTransitive\$(PackageNamePrefix).DevServer.targets" Condition="'$(UNO_UWP_BUILD)'=='true'"/>

<!-- Lottie move file -->
Expand Down
21 changes: 11 additions & 10 deletions build/nuget/Uno.WinUI.DevServer.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -30,7 +30,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -39,7 +39,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -48,7 +48,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -57,7 +57,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -66,7 +66,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -75,7 +75,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -84,7 +84,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>

Expand All @@ -93,7 +93,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Uno.Wasm.WebSockets" version="1.1.0" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>
Expand All @@ -103,7 +103,7 @@
<dependency id="Uno.WinUI" version="1.29.0-dev.93" />
<dependency id="Uno.WinUI.DevServer.Messaging" version="1.29.0-dev.93" />

<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
<dependency id="Uno.Wasm.WebSockets" version="1.1.0" />
<dependency id="Microsoft.IO.RecyclableMemoryStream" version="2.3.2" />
</group>
Expand Down Expand Up @@ -159,6 +159,7 @@
<file src="..\..\src\Uno.UI.RemoteControl.Server.Processors\bin\Release\net8.0\*.pdb" target="tools\rc\processors\net8.0" />
<file src="..\..\src\Uno.UI.RemoteControl.Server.Processors\bin\Release\net9.0\*.dll" target="tools\rc\processors\net9.0" />
<file src="..\..\src\Uno.UI.RemoteControl.Server.Processors\bin\Release\net9.0\*.pdb" target="tools\rc\processors\net9.0" />
<file src="..\..\src\Uno.UI.RemoteControl.Server.Processors\bin\Release\net9.0\BuildHost-netcore\**" target="tools\rc\processors\net9.0\BuildHost-netcore" />

<!-- Build targets -->
<file src="..\..\src\Uno.UI.RemoteControl\buildTransitive\*" target="buildTransitive" />
Expand Down
4 changes: 2 additions & 2 deletions build/nuget/Uno.WinUI.Lottie.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency id="SkiaSharp.NativeAssets.android" version="2.88.7" />

<dependency id="Uno.WinUI" version="to-be-set-by-ci" />
<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
</group>
<group targetFramework="net8.0-ios17.0">
<dependency id="SkiaSharp.Skottie" version="2.88.7" />
Expand Down Expand Up @@ -70,7 +70,7 @@
<dependency id="SkiaSharp.NativeAssets.android" version="2.88.7" />

<dependency id="Uno.WinUI" version="to-be-set-by-ci" />
<dependency id="Newtonsoft.Json" version="13.0.2" />
<dependency id="Newtonsoft.Json" version="13.0.3" />
</group>
<group targetFramework="net9.0-ios18.0">
<dependency id="SkiaSharp.Skottie" version="2.88.7" />
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="1.0.3" />
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.3" />
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.3" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Update="CommunityToolkit.Mvvm" Version="$(CommunityToolkitMvvmVersion)" />
<PackageReference Update="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Update="Microsoft.Web.WebView2" Version="1.0.2592.51" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<CompilerVisibleProperty Include="UnoRemoteControlHost" />
<CompilerVisibleProperty Include="UnoRemoteControlProcessorsPath" />
<CompilerVisibleProperty Include="UnoRemoteControlConfigCookie" />
<CompilerVisibleProperty Include="UnoEnCLogPath" />
<CompilerVisibleProperty Include="UnoHotReloadDiagnosticsLogPath" />
<CompilerVisibleProperty Include="UnoDisableBindableTypeProvidersGeneration" />
<CompilerVisibleProperty Include="ShouldWriteErrorOnInvalidXaml" />
<CompilerVisibleProperty Include="IsUiAutomationMappingEnabled" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class RemoteControlGenerator : ISourceGenerator
"VSIDEResolvedNonMSBuildProjectOutputs",
"DevEnvDir",
"MSBuildVersion",
"UnoHotReloadDiagnosticsLogPath",
};

public void Initialize(GeneratorInitializationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Uno.Extensions;
using Uno.UI.RemoteControl.Helpers;
using System.Collections.Generic;
using System.Runtime.Loader;
using Microsoft.Extensions.Logging;

namespace Uno.UI.RemoteControl.Host.HotReload.MetadataUpdates
Expand All @@ -24,31 +25,41 @@ internal static class CompilationWorkspaceProvider
Dictionary<string, string> properties,
CancellationToken ct)
{
if (properties.TryGetValue("UnoEnCLogPath", out var EnCLogPath))
if (properties.TryGetValue("UnoHotReloadDiagnosticsLogPath", out var logPath))
{
// Sets Roslyn's environment variable for troubleshooting HR, see:
// https://github.com/dotnet/roslyn/blob/fc6e0c25277ff440ca7ded842ac60278ee6c9695/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs#L72
Environment.SetEnvironmentVariable("Microsoft_CodeAnalysis_EditAndContinue_LogDir", EnCLogPath);
}
Environment.SetEnvironmentVariable("Microsoft_CodeAnalysis_EditAndContinue_LogDir", logPath);

var globalProperties = new Dictionary<string, string> {
// Mark this compilation as hot-reload capable, so generators can act accordingly
{ "IsHotReloadHost", "True" },
};
// Unconditionally enable binlog generation in msbuild. See https://github.com/dotnet/project-system/blob/4210ce79cfd35154dbd858f056bfb9101f290e69/docs/design-time-builds.md?L61
Environment.SetEnvironmentVariable("MSBUILDDEBUGENGINE", "1");
Environment.SetEnvironmentVariable("MSBUILDDEBUGPATH", logPath);
}

foreach (var property in properties)
static bool IsValidProperty(string property)
{
// Don't set the runtime identifier since it propagates to libraries as well
// which do not build using the RuntimeIdentifier being set. For instance, a head
// building for `iossimulator` will fail if the RuntimeIdentifier is set globally its
// dependent projects, causing the HR engine to search for pdb/dlls in
// the bin/Debug/net8.0/iossimulator/*.dll path instead of its original path.
if (!property.Key.Equals("RuntimeIdentifier", StringComparison.OrdinalIgnoreCase))
if (property.Equals("RuntimeIdentifier", StringComparison.OrdinalIgnoreCase))
{
globalProperties.Add(property.Key, property.Value);
// Don't set the runtime identifier since it propagates to libraries as well
// which do not build using the RuntimeIdentifier being set. For instance, a head
// building for `iossimulator` will fail if the RuntimeIdentifier is set globally its
// dependent projects, causing the HR engine to search for pdb/dlls in
// the bin/Debug/net8.0/iossimulator/*.dll path instead of its original path.

return false;
}

if (property.StartsWith("MSBuild", StringComparison.OrdinalIgnoreCase))
{
// Noticeably, don't set the "MSBuildVersion" (Forbidden, will fail workspace).
return false;
}

return true;
}

var globalProperties = properties.Where(property => IsValidProperty(property.Key)).ToDictionary();

MSBuildWorkspace workspace = null!;
for (var i = 3; i > 0; i--)
{
Expand Down Expand Up @@ -158,17 +169,17 @@ private static string BuildMSBuildPath(string? workDir)

private static void RegisterAssemblyLoader()
{
// Force assembly loader to consider siblings, when running in a separate appdomain.
ResolveEventHandler localResolve = (s, e) =>
// Force assembly loader to consider siblings, when running in a separate appdomain / ALC.
Assembly? Load(string name)
{
if (e.Name == "Mono.Runtime")
if (name == "Mono.Runtime")
{
// Roslyn 2.0 and later checks for the presence of the Mono runtime
// through this check.
return null;
}

var assembly = new AssemblyName(e.Name);
var assembly = new AssemblyName(name);
var basePath = Path.GetDirectoryName(new Uri(typeof(CompilationWorkspaceProvider).Assembly.Location).LocalPath) ?? "";

Console.WriteLine($"Searching for [{assembly}] from [{basePath}]");
Expand All @@ -180,35 +191,6 @@ private static void RegisterAssemblyLoader()
return null;
}

// Lookup for the highest version matching assembly in the current app domain.
// There may be an existing one that already matches, even though the
// fusion loader did not find an exact match.
var loadedAsm = (
from asm in AppDomain.CurrentDomain.GetAssemblies()
where asm.GetName().Name == assembly.Name
orderby asm.GetName().Version descending
select asm
).ToArray();

if (loadedAsm.Length > 1)
{
var duplicates = loadedAsm
.Skip(1)
.Where(a => a.GetName().Version == loadedAsm[0].GetName().Version)
.ToArray();

if (duplicates.Length != 0)
{
Console.WriteLine($"Selecting first occurrence of assembly [{e.Name}] which can be found at [{duplicates.Select(d => d.Location).JoinBy("; ")}]");
}

return loadedAsm[0];
}
else if (loadedAsm.Length == 1)
{
return loadedAsm[0];
}

Assembly? LoadAssembly(string filePath)
{
if (File.Exists(filePath))
Expand Down Expand Up @@ -244,8 +226,9 @@ select asm
.FirstOrDefault();
};

AppDomain.CurrentDomain.AssemblyResolve += localResolve;
AppDomain.CurrentDomain.TypeResolve += localResolve;
AppDomain.CurrentDomain.AssemblyResolve += (snd, e) => Load(e.Name);
AppDomain.CurrentDomain.TypeResolve += (snd, e) => Load(e.Name);
AssemblyLoadContext.Default.Resolving += (snd, e) => Load(e.FullName);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,28 @@ private void InitializeInner(ConfigureServer configureServer) => _initializeTask
{
await Notify(HotReloadEvent.Initializing);

var properties = configureServer
.MSBuildProperties
.ToDictionary();

// Flag the current build as created for hot reload, which allows for running targets or settings
// props/items in the context of the hot reload workspace.
properties["UnoIsHotReloadHost"] = "True";

// Set the RuntimeIdentifier as a temporary property so that we do not force the
// property as a read-only global property that would be transitively applied to
// projects that are not supporting the head's RuntimeIdentifier. (e.g. an android app
// which references a netstd2.0 library project)
if (properties.Remove("RuntimeIdentifier", out var runtimeIdentifier))
{
properties["UnoHotReloadRuntimeIdentifier"] = runtimeIdentifier;
}

var result = await CompilationWorkspaceProvider.CreateWorkspaceAsync(
configureServer.ProjectPath,
_reporter,
configureServer.MetadataUpdateCapabilities,
configureServer.MSBuildProperties.Where(kvp => !kvp.Key.StartsWith("MSBuild", StringComparison.OrdinalIgnoreCase)).ToDictionary(),
properties,
CancellationToken.None);

ObserveSolutionPaths(result.Item1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
<PackageReference Include="Uno.Core.Extensions.Logging.Singleton" />
<PackageReference Include="Uno.Core.Extensions" />
<PackageReference Include="Uno.Core.Extensions.Disposables" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />

<!-- Avoid transitive dependency from Microsoft.Build on 7.0.3 which has a vulnerability -->
<PackageReference Include="System.Text.Json" Version="8.0.5" />
Expand All @@ -36,6 +34,8 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
Expand All @@ -48,15 +48,17 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net9.0'">
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.8.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0" />
<!-- TODO: Use version 9 when compiling against .NET 9? -->
<PackageReference Include="Microsoft.Build" Version="17.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build" Version="17.7.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.7.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.7.2" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.7.2" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
</ItemGroup>

<ItemGroup>
<Content Include="buildTransitive\*.DevServer.props">
<PackagePath>build</PackagePath>
<Pack>true</Pack>
</Content>
<Content Include="buildTransitive\*.DevServer.targets">
<PackagePath>build</PackagePath>
<Pack>true</Pack>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Condition="'$(UnoIsHotReloadHost)'=='true'">
<RuntimeIdentifier Condition="'$(UnoHotReloadRuntimeIdentifier)' != ''">$(UnoHotReloadRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

</Project>
Loading

0 comments on commit 0971565

Please sign in to comment.