Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Add support for universal apps. #11983

Merged
merged 44 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
87de6ea
[runtime] Add support for finding assemblies in an RID-specific subdi…
rolfbjarne May 25, 2021
6fe54cb
[dotnet] Only trim when building a specific RuntimeIdentifier.
rolfbjarne May 21, 2021
9a9562c
[tests] Add unified simple test app for all platforms we support.
rolfbjarne Jun 15, 2021
0021c2b
[MachO] Make StaticLibrary.IsStaticLibrary work with files shorter th…
rolfbjarne May 21, 2021
7aec86f
ools] Create a PathUtils class and move some shareable code there.
rolfbjarne May 21, 2021
0af6ec5
[MachO] Add a MachO.IsMachOFile method
rolfbjarne May 21, 2021
ba83560
[tools] Move parts of the binary file comparison to a helper file to …
rolfbjarne May 21, 2021
f864ff3
[tools] Move another IsUptodate overload to the FileCopier file to in…
rolfbjarne Jun 16, 2021
5955cd1
[tests] Add a complex test library project with resources and app con…
rolfbjarne May 21, 2021
724d0fe
[dotnet] Set a default RuntimeIdentifier and validate that we get a v…
rolfbjarne Jun 14, 2021
e1f31c6
[tests] Quote parameters containing semicolons when passed to 'dotnet…
rolfbjarne May 21, 2021
003cf30
[dotnet] Don't execute ComputeResolvedFileToPublishList if we're in t…
rolfbjarne May 21, 2021
5c50a2f
[msbuild] Implement a MergeAppBundles task to merge two (or more) app…
rolfbjarne May 21, 2021
4f8e9a8
[tests] Add new tests for merging app bundles
rolfbjarne May 21, 2021
91311a0
[dotnet] Implement support for multiple RuntimeIdentifiers.
rolfbjarne May 21, 2021
81b139e
[dotnet] Ignore RuntimeIdentifier if RuntimeIdentifiers is set.
rolfbjarne Jun 16, 2021
62865cb
Merge remote-tracking branch 'origin/main' into HEAD
rolfbjarne Jun 21, 2021
a32d605
[msbuild] Fix symlink check to check for file presence first.
rolfbjarne Jun 18, 2021
4526a5e
[msbuild] Copy directories correctly.
rolfbjarne Jun 18, 2021
bc9e007
[tests] Updated list of not-yet-localized error messages.
rolfbjarne Jun 18, 2021
718d954
[tests] Improve error reporting when SetUp fails in MergeAppBundleTas…
rolfbjarne Jun 21, 2021
f1cc00c
[tests] Update tests according to the actual error messages.
rolfbjarne Jun 21, 2021
7179cac
[dotnet] Set the default RuntimeIdentifier earlier.
rolfbjarne Jun 21, 2021
2f1667e
[tests] Remove MSBuildSDKsPath from the environment before invoking m…
rolfbjarne Jun 22, 2021
70d0f86
Merge remote-tracking branch 'origin/main' into HEAD
rolfbjarne Jun 23, 2021
889cf99
[dotnet] Compile entitlements before signing the merged app bundle.
rolfbjarne Jun 22, 2021
5ecb7ae
[msbuild] List all files causing errors.
rolfbjarne Jun 23, 2021
2a203b5
[msbuild] Compute input files slightly differently for CreateMergedAp…
rolfbjarne Jun 23, 2021
f6e9f55
[runtime] Add a xamarin_locate_app_resource function.
rolfbjarne Jun 23, 2021
608dfb3
[dotnet] Make the globalization data file an architecture-specific file.
rolfbjarne Jun 23, 2021
a78be0a
[dotnet] Ignore Info.plist files from the input app bundles when merg…
rolfbjarne Jun 23, 2021
e68831b
[dotnet] Compile the app manifest in the outer build for multi-rid apps.
rolfbjarne Jun 23, 2021
7f505c3
[dotnet] Rework how we compute the TargetArchitectures property.
rolfbjarne Jun 23, 2021
9f82694
[msbuild] Use the same prefix in ErrorHelper as we do in other MSBuil…
rolfbjarne Jun 24, 2021
df369da
[MachO] Simplify code a bit according to review.
rolfbjarne Jun 24, 2021
c5dad31
[dotnet] Don't create debug settings / configurations for inner builds.
rolfbjarne Jun 24, 2021
1fa1cf3
[dotnet] Use the correct relative paths for Info.plist for all platfo…
rolfbjarne Jun 24, 2021
82fc13e
[tests] Fix assertions regarding errors after recent changes.
rolfbjarne Jun 24, 2021
9a406d2
[tests] Fix makefile for ComplexAssembly to do nothing on a rebuild.
rolfbjarne Jun 24, 2021
2f65937
[tests] Remove BOM in new file.
rolfbjarne Jun 24, 2021
3497373
[dotnet] Compute 'ComputedPlatform' correctly for outer multi-rid bui…
rolfbjarne Jun 24, 2021
31b48eb
[tests] Copy more supporting files for building monotouch-test with .…
rolfbjarne Jun 24, 2021
6d6db24
[dotnet] Use relative paths in a few places.
rolfbjarne Jun 24, 2021
8aff15a
[tests] Don't run parallel make in tests/common/TestProjects/ComplexA…
rolfbjarne Jun 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
<!-- PublishTrimmed must be calculated as part of a target because IsMacEnabled on Windows will be set after connecting to the Mac -->
<Target Name="_ComputePublishTrimmed">
<PropertyGroup>
<PublishTrimmed Condition="'$(PublishTrimmed)' == '' And ($(_ProjectType.EndsWith('ExecutableProject')) Or $(_ProjectType.EndsWith('AppExtensionProject'))) And '$(IsMacEnabled)' == 'true'">true</PublishTrimmed>
<PublishTrimmed Condition="'$(PublishTrimmed)' == '' And '$(RuntimeIdentifier)' != '' And ($(_ProjectType.EndsWith('ExecutableProject')) Or $(_ProjectType.EndsWith('AppExtensionProject'))) And '$(IsMacEnabled)' == 'true'">true</PublishTrimmed>
</PropertyGroup>
</Target>

Expand Down
45 changes: 44 additions & 1 deletion runtime/product.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*
*/

#include <TargetConditionals.h>

#ifdef MONOTOUCH
#if TARGET_OS_WATCH
#define PRODUCT "Xamarin.WatchOS"
Expand Down Expand Up @@ -43,4 +45,45 @@
#define ARCH_SUBDIR
#else
#error Either MONOTOUCH or MONOMAC must be defined.
#endif
#endif

// Set RuntimeIdentifier defines
#if TARGET_OS_MACCATALYST
#define RUNTIMEIDENTIFIER_PLATFORM "maccatalyst"
#elif TARGET_OS_IOS
#if TARGET_OS_SIMULATOR
#define RUNTIMEIDENTIFIER_PLATFORM "iossimulator"
#else
#define RUNTIMEIDENTIFIER_PLATFORM "ios"
#endif
#elif TARGET_OS_TV
#if TARGET_OS_SIMULATOR
#define RUNTIMEIDENTIFIER_PLATFORM "tvossimulator"
#else
#define RUNTIMEIDENTIFIER_PLATFORM "tvos"
#endif
#elif TARGET_OS_WATCH
#if TARGET_OS_SIMULATOR
#define RUNTIMEIDENTIFIER_PLATFORM "watchossimulator"
#else
#define RUNTIMEIDENTIFIER_PLATFORM "watchos"
#endif
#elif TARGET_OS_OSX
#define RUNTIMEIDENTIFIER_PLATFORM "osx"
#else
#error Unknown platform
#endif

#if defined (__aarch64__)
#define RUNTIMEIDENTIFIER_ARCHITECTURE "arm64"
#elif defined (__x86_64__)
#define RUNTIMEIDENTIFIER_ARCHITECTURE "x64"
#elif defined (__i386__)
#define RUNTIMEIDENTIFIER_ARCHITECTURE "x86"
#elif defined (__arm__)
#define RUNTIMEIDENTIFIER_ARCHITECTURE "arm"
#else
#error Unknown architecture
#endif

#define RUNTIMEIDENTIFIER RUNTIMEIDENTIFIER_PLATFORM "-" RUNTIMEIDENTIFIER_ARCHITECTURE
12 changes: 11 additions & 1 deletion runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
*
* The platform assembly (Xamarin.[iOS|TVOS|WatchOS].dll) and any assemblies
* the platform assembly references (mscorlib.dll, System.dll) may be in a
* pointer-size subdirectory (ARCH_SUBDIR).
* pointer-size subdirectory (ARCH_SUBDIR), or an RID-specific subdirectory.
*
* AOT data files will have an arch-specific infix.
*/
Expand Down Expand Up @@ -2536,6 +2536,16 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
}
#endif // !MONOMAC

#if DOTNET
// RID-specific subdirectory
if (snprintf (path, pathlen, "%s/.xamarin/%s/%s", root, RUNTIMEIDENTIFIER, resource) < 0) {
LOG (PRODUCT ": Failed to construct path for resource: %s (5): %s", resource, strerror (errno));
return false;
} else if (xamarin_file_exists (path)) {
return true;
}
#endif

// just the file, no extensions, etc.
if (snprintf (path, pathlen, "%s/%s", root, resource) < 0) {
LOG (PRODUCT ": Failed to construct path for resource: %s (6): %s", resource, strerror (errno));
Expand Down
19 changes: 19 additions & 0 deletions tests/dotnet/MySimpleApp/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 0;
}
}
}
6 changes: 6 additions & 0 deletions tests/dotnet/MySimpleApp/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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>
</dict>
</plist>
9 changes: 9 additions & 0 deletions tests/dotnet/MySimpleApp/MacCatalyst/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOP=../../../..

include $(TOP)/Make.config

build:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY)

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run
7 changes: 7 additions & 0 deletions tests/dotnet/MySimpleApp/MacCatalyst/MySimpleApp.csproj
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>net6.0-maccatalyst</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
20 changes: 20 additions & 0 deletions tests/dotnet/MySimpleApp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TOP=../../..

include $(TOP)/Make.config

prepare:
cd .. && $(MAKE) global.json NuGet.config
rm -Rf */bin */obj

all-ios: prepare
$(DOTNET6) build iOS/*.csproj /bl

all-mac: prepare
$(DOTNET6) build macOS/*.csproj /bl

run-mac:
./macOS/bin/Debug/net6.0-macos/osx-x64/$(notdir $(CURDIR)).app/Contents/MacOS/$(notdir $(CURDIR))

diag:
cd .. && $(MAKE) global.json NuGet.config
$(DOTNET6) build /v:diag *binlog
8 changes: 8 additions & 0 deletions tests/dotnet/MySimpleApp/iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>
<!-- We need this because some tests will build this project for 32-bit targets -->
<key>MinimumOSVersion</key>
<string>10.0</string></dict>
</plist>
9 changes: 9 additions & 0 deletions tests/dotnet/MySimpleApp/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOP=../../../..

include $(TOP)/Make.config

build:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY)

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run
7 changes: 7 additions & 0 deletions tests/dotnet/MySimpleApp/iOS/MySimpleApp.csproj
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>net6.0-ios</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
6 changes: 6 additions & 0 deletions tests/dotnet/MySimpleApp/macOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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>
</dict>
</plist>
9 changes: 9 additions & 0 deletions tests/dotnet/MySimpleApp/macOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOP=../../../..

include $(TOP)/Make.config

build:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY)

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run
7 changes: 7 additions & 0 deletions tests/dotnet/MySimpleApp/macOS/MySimpleApp.csproj
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>net6.0-macos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
15 changes: 15 additions & 0 deletions tests/dotnet/MySimpleApp/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>

<ApplicationTitle>MySimpleApp</ApplicationTitle>
<ApplicationId>com.xamarin.mysimpleapp</ApplicationId>
<ApplicationVersion>3.14</ApplicationVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="../*.cs" />
<None Include="Info.plist" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions tests/dotnet/MySimpleApp/tvOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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>
</dict>
</plist>
9 changes: 9 additions & 0 deletions tests/dotnet/MySimpleApp/tvOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOP=../../../..

include $(TOP)/Make.config

build:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY)

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run
7 changes: 7 additions & 0 deletions tests/dotnet/MySimpleApp/tvOS/MySimpleApp.csproj
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>net6.0-tvos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>
2 changes: 1 addition & 1 deletion tools/common/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public bool CopyAssembly (string source, string target, bool copy_debug_symbols
if (!Application.IsUptodate (source, target) && (strip_assembly || !Cache.CompareAssemblies (source, target))) {
copied = true;
if (strip_assembly) {
Driver.FileDelete (target);
PathUtils.FileDelete (target);
Directory.CreateDirectory (Path.GetDirectoryName (target));
MonoTouch.Tuner.Stripper.Process (source, target);
} else {
Expand Down
58 changes: 0 additions & 58 deletions tools/common/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,63 +1246,5 @@ public static Frameworks GetFrameworks (Application app)
throw ErrorHelper.CreateError (71, Errors.MX0071, app.Platform, app.ProductName);
return rv;
}

[DllImport (Constants.libSystemLibrary)]
static extern int symlink (string path1, string path2);

public static bool Symlink (string path1, string path2)
{
return symlink (path1, path2) == 0;
}

[DllImport (Constants.libSystemLibrary)]
static extern int unlink (string pathname);

public static void FileDelete (string file)
{
// File.Delete can't always delete symlinks (in particular if the symlink points to a file that doesn't exist).
unlink (file);
// ignore any errors.
}

struct timespec {
public IntPtr tv_sec;
public IntPtr tv_nsec;
}

struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
public uint st_dev;
public ushort st_mode;
public ushort st_nlink;
public ulong st_ino;
public uint st_uid;
public uint st_gid;
public uint st_rdev;
public timespec st_atimespec;
public timespec st_mtimespec;
public timespec st_ctimespec;
public timespec st_birthtimespec;
public ulong st_size;
public ulong st_blocks;
public uint st_blksize;
public uint st_flags;
public uint st_gen;
public uint st_lspare;
public ulong st_qspare_1;
public ulong st_qspare_2;
}

[DllImport (Constants.libSystemLibrary, EntryPoint = "lstat$INODE64", SetLastError = true)]
static extern int lstat (string path, out stat buf);

public static bool IsSymlink (string file)
{
stat buf;
var rv = lstat (file, out buf);
if (rv != 0)
throw new Exception (string.Format ("Could not lstat '{0}': {1}", file, Marshal.GetLastWin32Error ()));
const int S_IFLNK = 40960;
return (buf.st_mode & S_IFLNK) == S_IFLNK;
}
}
}
28 changes: 27 additions & 1 deletion tools/common/MachO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,27 @@ public static bool IsDynamicFramework (string filename)

return true;
}

public static bool IsMachOFile (string filename)
{
using (var fs = new FileStream (filename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
if (fs.Length < 4)
return false;
using (var reader = new BinaryReader (fs)) {
var magic = reader.ReadUInt32 ();
reader.BaseStream.Position = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why reset the position ?
as the reader is not used before being disposed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied from somewhere else - I'll remove this line.

switch (magic) {
case MH_MAGIC:
case MH_MAGIC_64:
case FAT_MAGIC: // little-endian fat binary
case FAT_CIGAM: // big-endian fat binary
return true;
default:
return false;
}
}
}
}
}

public class StaticLibrary
Expand Down Expand Up @@ -573,7 +594,12 @@ public static bool IsStaticLibrary (BinaryReader reader, bool throw_if_error = f
var pos = reader.BaseStream.Position;

var bytes = reader.ReadBytes (8);
var rv = bytes [0] == '!' && bytes [1] == '<' && bytes [2] == 'a' && bytes [3] == 'r' && bytes [4] == 'c' && bytes [5] == 'h' && bytes [6] == '>' && bytes [7] == 0xa;
bool rv;
if (bytes.Length < 8) {
rv = false;
} else {
rv = bytes [0] == '!' && bytes [1] == '<' && bytes [2] == 'a' && bytes [3] == 'r' && bytes [4] == 'c' && bytes [5] == 'h' && bytes [6] == '>' && bytes [7] == 0xa;
}
reader.BaseStream.Position = pos;

if (throw_if_error && !rv)
Expand Down
Loading