Skip to content

Commit

Permalink
[dotnet] Add support for Mac Catalyst apps optimized interface for ma…
Browse files Browse the repository at this point in the history
…cOS. Fixes #14621. (#14663)

This also required bumping Xamarin.MacDev.

New commits in xamarin/Xamarin.MacDev:

* xamarin/Xamarin.MacDev@0717ac3 Add a new device type for Mac Catalyst.
* xamarin/Xamarin.MacDev@ed2a604 Remove net451 target framework from
Xamarin.MacDev.csproj

Diff: https://github.com/xamarin/Xamarin.MacDev/compare/9e6e29f2a4e89b140cb37575168faccc70c45d5f..0717ac3c249595b48860904ce77000a6115affbe

Fixes #14621.
  • Loading branch information
rolfbjarne committed Apr 7, 2022
1 parent 92ee92e commit 1b37c48
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 5 deletions.
18 changes: 18 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1407,4 +1407,12 @@
<data name="W7097" xml:space="preserve">
<value>Code signing has been requested multiple times for '{0}', with different metadata. The metadata '{1}' has been values for each item (once it's '{2}', another time it's '{3}').</value>
</data>

<data name="E7098" xml:space="preserve">
<value>The UIDeviceFamily value '6' is not valid for this platform. It's only valid for Mac Catalyst.</value>
</data>

<data name="E7099" xml:space="preserve">
<value>The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {0} (equivalent to macOS {1}).</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ void Validation (PDictionary plist)
return;

var supportedDevices = plist.GetUIDeviceFamily ();
var macCatalystOptimizedForMac = (supportedDevices & IPhoneDeviceType.MacCatalystOptimizedForMac) == IPhoneDeviceType.MacCatalystOptimizedForMac;
if (macCatalystOptimizedForMac) {
if (Platform != ApplePlatform.MacCatalyst) {
LogAppManifestError (MSBStrings.E7098 /* The UIDeviceFamily value '6' is not valid for this platform. It's only valid for Mac Catalyst. */);
return; // no need to look for more errors, they will probably not make much sense.
}

GetMinimumOSVersion (plist, out var minimumOSVersion);
if (minimumOSVersion < new Version (11, 0)) {
string miniOSVersion = "?";
if (MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion, false), minimumOSVersion, out var iOSVersion, out var _))
miniOSVersion = iOSVersion.ToString ();
LogAppManifestError (MSBStrings.E7099 /* The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {0} (equivalent to macOS {1}). */, miniOSVersion, minimumOSVersion);
}
}

switch (Platform) {
case ApplePlatform.iOS:
var supportsIPhone = (supportedDevices & IPhoneDeviceType.IPhone) != 0
Expand Down
8 changes: 4 additions & 4 deletions tests/common/shared-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<NativeLibName>ios-fat</NativeLibName>
<!-- We need this because we'd otherwise default to the latest OS version we support, and we'll want to execute on earlier versions -->
<SupportedOSPlatformVersion>10.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(SupportedOSPlatformVersion)' == ''">10.0</SupportedOSPlatformVersion>
<CompilerResponseFile>$(MSBuildThisFileDirectory)\..\..\src\build\dotnet\ios-defines-dotnet.rsp</CompilerResponseFile>
</PropertyGroup>
<ItemGroup Condition="'$(_PlatformName)' == 'iOS'">
Expand All @@ -18,7 +18,7 @@
<PropertyGroup Condition="$(TargetFramework.EndsWith('-tvos'))">
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
<NativeLibName>tvos-fat</NativeLibName>
<SupportedOSPlatformVersion>10.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(SupportedOSPlatformVersion)' == ''">10.0</SupportedOSPlatformVersion>
<CompilerResponseFile>$(MSBuildThisFileDirectory)\..\..\src\build\dotnet\tvos-defines-dotnet.rsp</CompilerResponseFile>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.EndsWith('-tvos'))">
Expand All @@ -28,15 +28,15 @@
<PropertyGroup Condition="$(TargetFramework.EndsWith('-macos'))">
<DefineConstants>$(DefineConstants);MONOMAC</DefineConstants>
<NativeLibName>macos-fat</NativeLibName>
<SupportedOSPlatformVersion>10.14</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(SupportedOSPlatformVersion)' == ''">10.14</SupportedOSPlatformVersion>
<CompilerResponseFile>$(MSBuildThisFileDirectory)\..\..\src\build\dotnet\macos-defines-dotnet.rsp</CompilerResponseFile>
</PropertyGroup>

<!-- Logic for Mac Catalyst -->
<PropertyGroup Condition="$(TargetFramework.EndsWith('-maccatalyst'))">
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<NativeLibName>maccatalyst-fat</NativeLibName>
<SupportedOSPlatformVersion>13.3</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(SupportedOSPlatformVersion)' == ''">13.3</SupportedOSPlatformVersion>
<CompilerResponseFile>$(MSBuildThisFileDirectory)\..\..\src\build\dotnet\maccatalyst-defines-dotnet.rsp</CompilerResponseFile>
</PropertyGroup>

Expand Down
19 changes: 19 additions & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Runtime.InteropServices;

using Foundation;

namespace MySimpleApp
{
public class Program
{
static int Main (string[] args)
{
GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly

Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD"));

return args.Length;
}
}
}
10 changes: 10 additions & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>6</integer>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework>
<SupportedOSPlatformVersion>14.0</SupportedOSPlatformVersion>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
2 changes: 2 additions & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TOP=../../..
include $(TOP)/tests/common/shared-dotnet-test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
1 change: 1 addition & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
1 change: 1 addition & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/macOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
16 changes: 16 additions & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>

<ApplicationTitle>CatalystAppOptimizedForMacOS</ApplicationTitle>
<ApplicationId>com.xamarin.catalystappoptimizedformacos</ApplicationId>
</PropertyGroup>

<Import Project="../../common/shared-dotnet.csproj" />

<ItemGroup>
<Compile Include="../*.cs" />
<None Include="../Info.plist" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TOP=../../../..
include $(TOP)/tests/common/shared-dotnet.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
1 change: 1 addition & 0 deletions tests/dotnet/CatalystAppOptimizedForMacOS/tvOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
38 changes: 38 additions & 0 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,5 +889,43 @@ public void CentralPackageVersionsApp (ApplePlatform platform)
var properties = GetDefaultProperties ();
DotNet.AssertBuild (project_path, properties);
}

[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", false)]
[TestCase (ApplePlatform.iOS, "iossimulator-x64", true)]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64", true)]
[TestCase (ApplePlatform.MacOSX, "osx-x64;osx-arm64", true)]
public void CatalystAppOptimizedForMacOS (ApplePlatform platform, string runtimeIdentifier, bool failureExpected)
{
var project = "CatalystAppOptimizedForMacOS";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
if (failureExpected) {
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
Assert.AreEqual (1, errors.Length, "Error count");
Assert.AreEqual ($"The UIDeviceFamily value '6' is not valid for this platform. It's only valid for Mac Catalyst.", errors [0].Message, "Error message");
} else {
DotNet.AssertBuild (project_path, properties);
}
}

[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", "13.3")]
public void CatalystAppOptimizedForMacOS_InvalidMinOS (ApplePlatform platform, string runtimeIdentifier, string minOS)
{
var project = "CatalystAppOptimizedForMacOS";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
properties ["SupportedOSPlatformVersion"] = minOS;
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
Assert.AreEqual (1, errors.Length, "Error count");
Assert.AreEqual ($"The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {minOS} (equivalent to macOS 10.15.2).", errors [0].Message, "Error message");
}
}
}

2 comments on commit 1b37c48

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.