Skip to content

Commit

Permalink
Merge branch 'main' into dev/rolf/dev/rolf/no-trimmer-warning-suppres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
rolfbjarne authored Oct 4, 2024
2 parents cceb557 + b7a317d commit 7c68741
Show file tree
Hide file tree
Showing 107 changed files with 1,347 additions and 1,921 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-single-platform-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
set -ex
git config user.email "[email protected]"
git config user.name "GitHub Actions Single Platform Branch Updater"
for platform in dotnet-iOS dotnet-tvOS dotnet-MacCatalyst dotnet-macOS dotnet; do
for platform in dotnet-iOS dotnet-tvOS dotnet-MacCatalyst dotnet-macOS; do
git checkout -b release-test/only-$platform origin/release-test/only-$platform
git merge origin/main
git push
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ tests/bcl-test/SystemCoreXunit*.csproj
tests/bcl-test/SystemXunit.csproj
global.json
.idea
device-tests-provisioning.csx
build-provisioning.csx
provision-xcode.csx
provision-shared.csx
mono_crash.*.json
*.binlog
.vscode
Expand Down
11 changes: 4 additions & 7 deletions Make.config
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ include $(TOP)/Make.versions
# The value is taken from the name + version of the Ref pack.
# Example: given the Ref pack "Microsoft.iOS.Ref.net8.0_17.5" with the version "17.5.8030", the value
# to write here would be the part after "Microsoft.iOS.Ref." + "/" + version: "net8.0_17.5/17.5.8030"
STABLE_NUGET_VERSION_iOS=net8.0_17.5/17.5.8030
STABLE_NUGET_VERSION_tvOS=net8.0_17.5/17.5.8030
STABLE_NUGET_VERSION_MacCatalyst=net8.0_17.5/17.5.8030
STABLE_NUGET_VERSION_macOS=net8.0_14.5/14.5.8030
STABLE_NUGET_VERSION_iOS=net8.0_18.0/18.0.8303
STABLE_NUGET_VERSION_tvOS=net8.0_18.0/18.0.8303
STABLE_NUGET_VERSION_MacCatalyst=net8.0_18.0/18.0.8303
STABLE_NUGET_VERSION_macOS=net8.0_15.0/15.0.8303

PACKAGE_HEAD_REV=$(shell git rev-parse HEAD)

Expand Down Expand Up @@ -748,9 +748,6 @@ EMSCRIPTEN_MANIFEST_VERSION_BAND=$(DOTNET_MANIFEST_VERSION_BAND_WITH_PRERELEASE_
# It should typically be $(DOTNET_MANIFEST_VERSION_BAND_WITH_PRERELEASE_COMPONENT), unless we decide to hardcode it to something else
MACIOS_MANIFEST_VERSION_BAND=$(DOTNET_MANIFEST_VERSION_BAND_WITH_PRERELEASE_COMPONENT)

# Set this to 1 if the Microsoft.NETCore.App.Ref dependency in eng/Version.Details.xml does *not* specify a CoherentParentDependency on VS.Tools.Net.Core.SDK.Resolver.
TRACKING_DOTNET_RUNTIME_SEPARATELY=

# The location of csc changes depending on whether we're using a preview or a stable/service release :/
DOTNET_CSC_PATH_PREVIEW=$(DOTNET_DIR)/sdk/$(DOTNET_VERSION)/Roslyn/bincore/csc.dll
DOTNET_CSC_PATH_STABLE=$(DOTNET_DIR)/sdk/$(DOTNET_VERSION_BAND)/Roslyn/bincore/csc.dll
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ else
@echo
endif
endif
$(Q) $(MAKE) -C dotnet shutdown-build-server

.PHONY: package release
package release:
Expand Down
7 changes: 6 additions & 1 deletion dotnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,9 @@ all-hook::
$(Q) $(MAKE) shutdown-build-server

shutdown-build-server:
$(Q) $(DOTNET) build-server shutdown
$(Q) echo "Shutting down build servers:"
$(Q) $(DOTNET) build-server shutdown | sed 's/^/ /' || true
$(Q) echo "Listing .NET processes still alive:"
$(Q) pgrep -lf "^$(DOTNET)" | sed 's/^/ /' || true
$(Q) echo "Killing the above mentioned processes."
$(Q) pkill -9 -f "^$(DOTNET)" | sed 's/^/ /' || true
5 changes: 5 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,11 @@
<!-- libSystem.Security.Cryptography.Native.Apple.a requires the Security framework -->
<_NativeExecutableFrameworks Include="Security" />

<!-- Most apps do not use BrowserEngineKit, and linking with it when an app is not supposed to will prevent it from getting approved in the App Store.
However, we'll automatically detect that we need to link with BrowserEngineKit if an app isn't trimmed, so let's just remove BrowserEngineKit
here, with an escape hatch if an app really needs it (which would be rather rare). Ref: https://github.com/xamarin/xamarin-macios/issues/21324 -->
<_NativeExecutableFrameworks Remove="BrowserEngineKit" Condition="'$(LinkWithBrowserEngineKit)' != 'true'" />

<!-- Mono requires zlib, iconv, icucore, and the "Compression framework" -->
<_MainLinkerFlags Include="-lz" />
<_MainLinkerFlags Include="-liconv" />
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
<Uri>https://github.com/dotnet/templating</Uri>
<Sha />
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.iOS.Shared" Version="9.0.0-prerelease.24379.1">
<Dependency Name="Microsoft.DotNet.XHarness.iOS.Shared" Version="10.0.0-prerelease.24476.1">
<Uri>https://github.com/dotnet/xharness</Uri>
<Sha>edae8a9491f747ba2a36023075aa3ac57be4d32e</Sha>
<Sha>7d5c32dbda0c6c8b9dc20cde4e1261b191896138</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<MicrosoftNETRuntimeMonoTargetsSdkPackageVersion>9.0.0-rc.2.24462.10</MicrosoftNETRuntimeMonoTargetsSdkPackageVersion>
<MicrosoftTemplateEngineTasksVersion>7.0.100-alpha.1.21601.1</MicrosoftTemplateEngineTasksVersion>
<MicrosoftDotNetCecilPackageVersion>0.11.5-alpha.24467.1</MicrosoftDotNetCecilPackageVersion>
<MicrosoftDotNetXHarnessiOSSharedPackageVersion>10.0.0-prerelease.24467.4</MicrosoftDotNetXHarnessiOSSharedPackageVersion>
<MicrosoftDotNetXHarnessiOSSharedPackageVersion>10.0.0-prerelease.24476.1</MicrosoftDotNetXHarnessiOSSharedPackageVersion>
<!-- Manually updated versions -->
<Emscriptennet7WorkloadVersion>$(MicrosoftNETWorkloadEmscriptenCurrentManifest80100Version)</Emscriptennet7WorkloadVersion>
<EmscriptenWorkloadVersion>$(MicrosoftNETWorkloadEmscriptenCurrentManifest80100Version)</EmscriptenWorkloadVersion>
Expand Down
2 changes: 1 addition & 1 deletion mk/xamarin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif

# Available versions can be seen here:
# https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-eng/NuGet/Microsoft.Tools.Mlaunch/versions
MLAUNCH_NUGET_VERSION=1.0.256
MLAUNCH_NUGET_VERSION=1.0.261

define CheckVersionTemplate
check-$(1)::
Expand Down
153 changes: 75 additions & 78 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Collections.Generic;

Expand All @@ -15,7 +17,6 @@

namespace Xamarin.MacDev.Tasks {
public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTask {
MetadataLoadContext? universe;
List<ITaskItem> unpackedResources = new List<ITaskItem> ();

#region Inputs
Expand All @@ -26,9 +27,6 @@ public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTas
[Required]
public string IntermediateOutputPath { get; set; } = string.Empty;

[Required]
public ITaskItem [] ReferenceAssemblies { get; set; } = Array.Empty<ITaskItem> ();

[Required]
public ITaskItem [] ReferencedLibraries { get; set; } = Array.Empty<ITaskItem> ();

Expand All @@ -52,15 +50,6 @@ public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTas
#endregion

public override bool Execute ()
{
try {
return ExecuteImpl ();
} finally {
universe?.Dispose ();
}
}

bool ExecuteImpl ()
{
if (ShouldExecuteRemotely ()) {
var result = new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
Expand All @@ -87,7 +76,7 @@ bool ExecuteImpl ()
Log.LogMessage (MessageImportance.Low, MSBStrings.M0168, asm.ItemSpec);
} else {
var perAssemblyOutputPath = Path.Combine (IntermediateOutputPath, "unpack", asm.GetMetadata ("Filename"));
var extracted = ExtractContentAssembly (asm.ItemSpec, perAssemblyOutputPath).ToArray ();
var extracted = ExtractContentAssembly (asm.ItemSpec, perAssemblyOutputPath);

results.AddRange (extracted);

Expand All @@ -113,58 +102,88 @@ bool IsFrameworkAssembly (ITaskItem asm)
return false;
}

IEnumerable<ITaskItem> ExtractContentAssembly (string assembly, string intermediatePath)
List<ITaskItem> ExtractContentAssembly (string assembly, string intermediatePath)
{
var rv = new List<ITaskItem> ();

if (!File.Exists (assembly)) {
Log.LogMessage (MessageImportance.Low, $"Not inspecting assembly because it doesn't exist: {assembly}");
yield break;
return rv;
}

var asmWriteTime = File.GetLastWriteTimeUtc (assembly);
var manifestResources = GetAssemblyManifestResources (assembly).ToArray ();
if (!manifestResources.Any ())
yield break;

Log.LogMessage (MessageImportance.Low, $"Inspecting assembly with {manifestResources.Length} resources: {assembly}");
foreach (var embedded in manifestResources) {
string rpath;

if (embedded.Name.StartsWith ("__" + Prefix + "_content_", StringComparison.Ordinal)) {
var mangled = embedded.Name.Substring (("__" + Prefix + "_content_").Length);
rpath = UnmangleResource (mangled);
} else if (embedded.Name.StartsWith ("__" + Prefix + "_page_", StringComparison.Ordinal)) {
var mangled = embedded.Name.Substring (("__" + Prefix + "_page_").Length);
rpath = UnmangleResource (mangled);
} else {
continue;
}

var path = Path.Combine (intermediatePath, rpath);
var file = new FileInfo (path);

var item = new TaskItem (path);
item.SetMetadata ("LogicalName", rpath);
item.SetMetadata ("Optimize", "false");

if (file.Exists && file.LastWriteTimeUtc >= asmWriteTime) {
Log.LogMessage (" Up to date: {0}", rpath);
} else {
Log.LogMessage (" Unpacking: {0}", rpath);

Directory.CreateDirectory (Path.GetDirectoryName (path));
try {
var asmWriteTime = File.GetLastWriteTimeUtc (assembly);
using var peStream = File.OpenRead (assembly);
using var peReader = new PEReader (peStream);
var metadataReader = PEReaderExtensions.GetMetadataReader (peReader);
Log.LogMessage (MessageImportance.Low, $"Inspecting resources in assembly {assembly}");
foreach (var manifestResourceHandle in metadataReader.ManifestResources) {
var manifestResource = metadataReader.GetManifestResource (manifestResourceHandle);
if (!manifestResource.Implementation.IsNil)
continue; // embedded resources have Implementation.IsNil = true, and those are the ones we care about

var name = metadataReader.GetString (manifestResource.Name);
if (string.IsNullOrEmpty (name))
continue;

string rpath;

if (name.StartsWith ("__" + Prefix + "_content_", StringComparison.Ordinal)) {
var mangled = name.Substring (("__" + Prefix + "_content_").Length);
rpath = UnmangleResource (mangled);
} else if (name.StartsWith ("__" + Prefix + "_page_", StringComparison.Ordinal)) {
var mangled = name.Substring (("__" + Prefix + "_page_").Length);
rpath = UnmangleResource (mangled);
} else {
continue;
}

using (var stream = File.Open (path, FileMode.Create)) {
using (var resource = embedded.Open ())
resource.CopyTo (stream);
var path = Path.Combine (intermediatePath, rpath);
var file = new FileInfo (path);

var item = new TaskItem (path);
item.SetMetadata ("LogicalName", rpath);
item.SetMetadata ("Optimize", "false");

if (file.Exists && file.LastWriteTimeUtc >= asmWriteTime) {
Log.LogMessage (" Up to date: {0}", rpath);
} else {
Log.LogMessage (" Unpacking: {0}", rpath);

Directory.CreateDirectory (Path.GetDirectoryName (path));

var resourceDirectory = peReader.GetSectionData (peReader.PEHeaders.CorHeader!.ResourcesDirectory.RelativeVirtualAddress);
var reader = resourceDirectory.GetReader ((int) manifestResource.Offset, resourceDirectory.Length - (int) manifestResource.Offset);
var length = reader.ReadUInt32 ();
if (length > reader.RemainingBytes)
throw new BadImageFormatException ();
#if NET
using var fs = new FileStream (path, FileMode.Create, FileAccess.Write, FileShare.Read);
unsafe {
var span = new ReadOnlySpan<byte> (reader.CurrentPointer, (int) length);
fs.Write (span);
}
#else
var buffer = new byte [4096];
using var fs = new FileStream (path, FileMode.Create, FileAccess.Write, FileShare.Read, buffer.Length);
var left = (int) length;
while (left > 0) {
var read = Math.Min (left, buffer.Length);
reader.ReadBytes (read, buffer, 0);
fs.Write (buffer, 0, read);
left -= read;
}
#endif
unpackedResources.Add (item);
}

unpackedResources.Add (item);
rv.Add (item);
}

yield return item;
} catch (Exception e) {
Log.LogMessage (MessageImportance.Low, $"Unable to load the resources from the assembly '{assembly}': {e}");
return new List<ITaskItem> ();
}

yield break;
return rv;
}

static string UnmangleResource (string mangled)
Expand Down Expand Up @@ -237,27 +256,5 @@ public bool ShouldCopyToBuildServer (ITaskItem item)

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => ItemsFiles;

IEnumerable<ManifestResource> GetAssemblyManifestResources (string fileName)
{
if (universe is null)
universe = new MetadataLoadContext (new PathAssemblyResolver (ReferenceAssemblies.Select (v => v.ItemSpec)));

Assembly assembly;
try {
assembly = universe.LoadFromAssemblyPath (fileName);
} catch (Exception e) {
Log.LogMessage (MessageImportance.Low, $"Unable to load the assembly '{fileName}: {e}");
yield break;
}

foreach (var resourceName in assembly.GetManifestResourceNames ()) {
if (string.IsNullOrEmpty (resourceName))
continue;
var info = assembly.GetManifestResourceInfo (resourceName);
if (!info.ResourceLocation.HasFlag (ResourceLocation.Embedded))
continue;
yield return new ManifestResource (resourceName, () => assembly.GetManifestResourceStream (resourceName));
}
}
}
}
6 changes: 3 additions & 3 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,9 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<_StampDirectory>$(DeviceSpecificIntermediateOutputPath)resourcestamps\</_StampDirectory>
</PropertyGroup>
<ItemGroup>
<_UnpackLibraryResourceItems Include="@(ReferencePath);@(ReferenceDependencyPaths)">
<_UnpackLibraryResourceItems Include="@(ReferencePath)" Condition="'%(ReferencePath.FrameworkReferenceName)' != 'Microsoft.NETCore.App' And '%(ReferencePath.FrameworkReferenceName)' != 'Microsoft.$(_PlatformName)'" />
<_UnpackLibraryResourceItems Include="@(ReferenceDependencyPaths)" Condition="'%(ReferenceDependencyPaths.FrameworkReferenceName)' != 'Microsoft.NETCore.App' And '%(ReferenceDependencyPaths.FrameworkReferenceName)' != 'Microsoft.$(_PlatformName)'" />
<_UnpackLibraryResourceItems>
<StampFile>$(_StampDirectory)%(FileName).stamp</StampFile>
<ItemsFile>$(_StampDirectory)%(FileName).items</ItemsFile>
</_UnpackLibraryResourceItems>
Expand Down Expand Up @@ -1982,14 +1984,12 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<MakeDir Directories="$(_StampDirectory)" />

<!-- This task may be executed locally on Windows (for Hot Restart) -->
<!-- Note that ReferenceAssemblies must always be passed all referenced assemblies, even for incremental builds when we're not necessarily unpacking from all assemblies -->
<UnpackLibraryResources
Condition="'$(IsMacEnabled)' == 'true' Or '$(IsHotRestartBuild)' == 'true'"
SessionId="$(BuildSessionId)"
Prefix="$(_EmbeddedResourcePrefix)"
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
TargetFrameworkDirectory="$(TargetFrameworkDirectory)"
ReferenceAssemblies="@(ReferencePath);@(ReferenceDependencyPaths)"
ReferencedLibraries="@(_UnpackLibraryResourceItems)"
>
<Output TaskParameter="BundleResourcesWithLogicalNames" ItemName="_BundleResourceWithLogicalName" />
Expand Down
1 change: 1 addition & 0 deletions src/Foundation/DictionaryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ static public NativeHandle GetHandle (this DictionaryContainer? self)

// helper to avoid the (common pattern)
// var p = x is null ? null : x.Dictionary;
[return: NotNullIfNotNull (nameof (self))]
static public NSDictionary? GetDictionary (this DictionaryContainer? self)
{
return self is null ? null : self.Dictionary;
Expand Down
Loading

0 comments on commit 7c68741

Please sign in to comment.