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

[release/6.0.1xx-preview7] [dotnet] Add support for the interpreter + AOT when needed. Fixes #11421 and #11724. #12237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 21 additions & 5 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
AOTCompiler=$(_AOTCompiler)
AOTOutputDirectory=$(_AOTOutputDirectory)
CacheDirectory=$(_LinkerCacheDirectory)
@(_BundlerDlsym -> 'Dlsym=%(Identity)')
Debug=$(_BundlerDebug)
DeploymentTarget=$(_MinimumOSVersion)
@(_BundlerEnvironmentVariables -> 'EnvironmentVariable=%(Identity)=%(Value)')
Expand All @@ -370,6 +371,8 @@
InvariantGlobalization=$(InvariantGlobalization)
ItemsDirectory=$(_LinkerItemsDirectory)
IsSimulatorBuild=$(_SdkIsSimulator)
LibMonoLinkMode=$(_LibMonoLinkMode)
LibXamarinLinkMode=$(_LibXamarinLinkMode)
LinkMode=$(_LinkMode)
MarshalManagedExceptionMode=$(_MarshalManagedExceptionMode)
MarshalObjectiveCExceptionMode=$(_MarshalObjectiveCExceptionMode)
Expand Down Expand Up @@ -557,9 +560,9 @@
<ReadItemsFromFile SessionId="$(BuildSessionId)" File="$(_LinkerItemsDirectory)/_BindingLibraryLinkWith.items" Condition="Exists('$(_LinkerItemsDirectory)/_BindingLibraryLinkWith.items')">
<Output TaskParameter="Items" ItemName="_BindingLibraryLinkWith" />
</ReadItemsFromFile>
<!-- Load _BindingLibraryLinkerFlags -->
<ReadItemsFromFile SessionId="$(BuildSessionId)" File="$(_LinkerItemsDirectory)/_BindingLibraryLinkerFlags.items" Condition="Exists('$(_LinkerItemsDirectory)/_BindingLibraryLinkerFlags.items')">
<Output TaskParameter="Items" ItemName="_BindingLibraryLinkerFlags" />
<!-- Load _AssemblyLinkerFlags -->
<ReadItemsFromFile SessionId="$(BuildSessionId)" File="$(_LinkerItemsDirectory)/_AssemblyLinkerFlags.items" Condition="Exists('$(_LinkerItemsDirectory)/_AssemblyLinkerFlags.items')">
<Output TaskParameter="Items" ItemName="_AssemblyLinkerFlags" />
</ReadItemsFromFile>
<!-- Load _BindingLibraryFrameworks -->
<ReadItemsFromFile SessionId="$(BuildSessionId)" File="$(_LinkerItemsDirectory)/_BindingLibraryFrameworks.items" Condition="Exists('$(_LinkerItemsDirectory)/_BindingLibraryFrameworks.items')">
Expand Down Expand Up @@ -630,6 +633,17 @@
</PropertyGroup>

<Target Name="_ComputeVariables" DependsOnTargets="$(_ComputeVariablesDependsOn)">
<PropertyGroup Condition="'$(_RunAotCompiler)' == ''">
<!-- Don't run the AOT compiler by default -->
<_RunAotCompiler>false</_RunAotCompiler>
<!-- We need it for device builds for mobile platforms -->
<_RunAotCompiler Condition="'$(_SdkIsSimulator)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">true</_RunAotCompiler>
<!-- We need it if the interpreter is enabled, no matter where -->
<_RunAotCompiler Condition="'$(MtouchInterpreter)' != ''">true</_RunAotCompiler>
<!-- We need it for Mac Catalyst on arm64 -->
<_RunAotCompiler Condition="'$(RuntimeIdentifier)' == 'maccatalyst-arm64'">true</_RunAotCompiler>
</PropertyGroup>

<PropertyGroup>
<_IntermediateNativeLibraryDir>$(IntermediateOutputPath)nativelibraries/</_IntermediateNativeLibraryDir>
<_NativeExecutableName>$(_AppBundleName)</_NativeExecutableName>
Expand All @@ -642,11 +656,13 @@
<_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/</_AOTInputDirectory>
<_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/</_AOTOutputDirectory>

<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And '$(_RunAotCompiler)' == 'true'">static</_LibMonoLinkMode> <!-- https://github.com/dotnet/runtime/issues/55000 -->
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And ('$(ComputedPlatform)' != 'iPhone' Or '$(_PlatformName)' == 'macOS')">dylib</_LibMonoLinkMode>
<_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == ''">static</_LibMonoLinkMode>
<_LibMonoExtension Condition="'$(_LibMonoLinkMode)' == 'dylib'">dylib</_LibMonoExtension>
<_LibMonoExtension Condition="'$(_LibMonoLinkMode)' == 'static'">a</_LibMonoExtension>

<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == '' And '$(_RunAotCompiler)' == 'true'">static</_LibXamarinLinkMode> <!-- https://github.com/dotnet/runtime/issues/55000 -->
<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == '' And '$(ComputedPlatform)' != 'iPhone' And '$(_PlatformName)' != 'macOS'">dylib</_LibXamarinLinkMode>
<_LibXamarinLinkMode Condition="'$(_LibXamarinLinkMode)' == ''">static</_LibXamarinLinkMode>
<_LibXamarinExtension Condition="'$(_LibXamarinLinkMode)' == 'dylib'">dylib</_LibXamarinExtension>
Expand Down Expand Up @@ -702,7 +718,7 @@
</Target>

<Target Name="_AOTCompile"
Condition="'$(_SdkIsSimulator)' != 'true' And '$(_PlatformName)' != 'macOS'"
Condition="'$(_RunAotCompiler)' == 'true'"
DependsOnTargets="_ComputeVariables"
Inputs="@(_AssembliesToAOT)"
Outputs="@(_AssembliesToAOT -> '%(ObjectFile)');@(_AssembliesToAOT -> '%(LLVMFile)');">
Expand Down Expand Up @@ -836,7 +852,7 @@
EntitlementsInExecutable="$(_CompiledEntitlements)"
FrameworkRPath="$(_EmbeddedFrameworksRPath)"
Frameworks="@(_NativeExecutableFrameworks);@(_BindingLibraryFrameworks)"
LinkerFlags="@(_BindingLibraryLinkerFlags);@(_ReferencesLinkerFlags);@(_MainLinkerFlags)"
LinkerFlags="@(_AssemblyLinkerFlags);@(_ReferencesLinkerFlags);@(_MainLinkerFlags)"
LinkWithLibraries="@(_XamarinMainLibraries);@(_BindingLibraryLinkWith);@(_MainLinkWith)"
MinimumOSVersion="$(_MinimumOSVersion)"
NativeReferences="@(_FileNativeReference);@(_FrameworkNativeReference)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Xamarin.MacDev.Tasks {
public abstract class ParseBundlerArgumentsTaskBase : XamarinTask {
public string ExtraArgs { get; set; }

[Output]
public ITaskItem [] DlSym { get; set; }

[Output]
public ITaskItem[] EnvironmentVariables { get; set; }

Expand Down Expand Up @@ -49,6 +52,7 @@ public override bool Execute ()
var args = CommandLineArgumentBuilder.Parse (ExtraArgs);
List<string> xml = null;
var envVariables = new List<ITaskItem> ();
var dlsyms = new List<ITaskItem> ();

for (int i = 0; i < args.Length; i++) {
var arg = args [i];
Expand Down Expand Up @@ -84,6 +88,9 @@ public override bool Execute ()
// do not set the MtouchNoSymbolStrip property to 'true' in that case.
NoSymbolStrip = string.IsNullOrEmpty (value) ? "true" : "false";
break;
case "dlsym":
dlsyms.Add (new TaskItem (string.IsNullOrEmpty (value) ? "true" : value));
break;
case "dsym":
NoDSymUtil = ParseBool (value) ? "false" : "true";
break;
Expand Down Expand Up @@ -143,6 +150,11 @@ public override bool Execute ()
EnvironmentVariables = envVariables.ToArray ();
}

if (dlsyms.Count > 0) {
if (DlSym != null)
dlsyms.AddRange (DlSym);
DlSym = dlsyms.ToArray ();
}
}

return !Log.HasLoggedErrors;
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
NoDSymUtil="$(_NoDSymUtil)"
>
<Output TaskParameter="CustomBundleName" PropertyName="_CustomBundleName" />
<Output TaskParameter="DlSym" ItemName="_BundlerDlsym" />
<Output TaskParameter="EnvironmentVariables" ItemName="_BundlerEnvironmentVariables" />
<Output TaskParameter="MarshalManagedExceptionMode" PropertyName="_MarshalManagedExceptionMode" />
<Output TaskParameter="MarshalObjectiveCExceptionMode" PropertyName="_MarshalObjectiveCExceptionMode" />
Expand Down
10 changes: 3 additions & 7 deletions runtime/monotouch-main.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,9 @@ - (void) memoryWarning: (NSNotification *) sender
xamarin_initialize ();
DEBUG_LAUNCH_TIME_PRINT ("\tmonotouch init time");

#if defined (__arm__) || defined(__aarch64__)
xamarin_register_assemblies ();
assembly = xamarin_open_and_register (xamarin_executable_name, &exception_gchandle);
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
#else
if (xamarin_register_assemblies != NULL)
xamarin_register_assemblies ();

if (xamarin_executable_name) {
assembly = xamarin_open_and_register (xamarin_executable_name, &exception_gchandle);
if (exception_gchandle != NULL)
Expand All @@ -455,7 +452,6 @@ - (void) memoryWarning: (NSNotification *) sender
if (exception_gchandle != NULL)
xamarin_process_managed_exception_gchandle (exception_gchandle);
}
#endif

DEBUG_LAUNCH_TIME_PRINT ("\tAssembly register time");

Expand Down
5 changes: 2 additions & 3 deletions runtime/monovm-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@
void
xamarin_bridge_initialize ()
{
#if defined (__arm__) || defined(__aarch64__)
xamarin_register_modules ();
#endif
if (xamarin_register_modules != NULL)
xamarin_register_modules ();
DEBUG_LAUNCH_TIME_PRINT ("\tAOT register time");

#ifdef DEBUG
Expand Down
18 changes: 18 additions & 0 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
enum XamarinLaunchMode xamarin_launch_mode = XamarinLaunchModeApp;
bool xamarin_supports_dynamic_registration = true;
const char *xamarin_runtime_configuration_name = NULL;
const char *xamarin_mono_native_lib_name = "__Internal";

/* Callbacks */

Expand Down Expand Up @@ -2441,8 +2442,25 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;

void* symbol = NULL;

#if TARGET_OS_MACCATALYST
static void *monoNativeLibrary = NULL;
#endif

if (!strcmp (libraryName, "__Internal")) {
symbol = dlsym (RTLD_DEFAULT, entrypointName);
#if TARGET_OS_MACCATALYST
} else if (!strcmp (libraryName, "libSystem.Native") ||
!strcmp (libraryName, "libSystem.Security.Cryptography.Native.Apple") ||
!strcmp (libraryName, "libSystem.Net.Security.Native")) {
if (monoNativeLibrary == NULL) {
if (xamarin_mono_native_lib_name == NULL || !strcmp (xamarin_mono_native_lib_name, "__Internal")) {
monoNativeLibrary = RTLD_DEFAULT;
} else {
monoNativeLibrary = dlopen (xamarin_mono_native_lib_name, RTLD_LAZY);
}
}
symbol = dlsym (monoNativeLibrary, entrypointName);
#endif // TARGET_OS_MACCATALYST
#if !defined (CORECLR_RUNTIME) // we're intercepting objc_msgSend calls using the managed System.Runtime.InteropServices.ObjectiveC.Bridge.SetMessageSendCallback instead.
#if defined (__i386__) || defined (__x86_64__) || defined (__arm64__)
} else if (!strcmp (libraryName, "/usr/lib/libobjc.dylib")) {
Expand Down
1 change: 1 addition & 0 deletions runtime/xamarin/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern enum MarshalManagedExceptionMode xamarin_marshal_managed_exception_mode;
extern enum XamarinLaunchMode xamarin_launch_mode;
extern bool xamarin_supports_dynamic_registration;
extern const char *xamarin_runtime_configuration_name;
extern const char *xamarin_mono_native_lib_name;

typedef void (*xamarin_setup_callback) ();
typedef int (*xamarin_extension_main_callback) (int argc, char** argv);
Expand Down
2 changes: 0 additions & 2 deletions runtime/xamarin/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ void xamarin_mono_object_release_at_process_exit (MonoObject *mobj);
*/
MonoAssembly * xamarin_open_assembly (const char *name);

#if defined(__arm__) || defined(__aarch64__)
void mono_aot_register_module (void *aot_info);
#endif

typedef void (*xamarin_register_module_callback) ();
typedef void (*xamarin_register_assemblies_callback) ();
Expand Down
4 changes: 2 additions & 2 deletions tests/dotnet/MyInterpretedApp/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Foundation;
using UIKit;

namespace MySingleView
namespace MyInterpretedApp
{
public partial class AppDelegate : UIApplicationDelegate
{
Expand All @@ -15,7 +15,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options)

var dvc = new UIViewController ();
var button = new UIButton (window.Bounds);
button.SetTitle ("net6!", UIControlState.Normal);
button.SetTitle ($"Execution mode: {Application.GetExecutionMode ()}", UIControlState.Normal);
dvc.Add (button);

window.RootViewController = dvc;
Expand Down
6 changes: 0 additions & 6 deletions tests/dotnet/MyInterpretedApp/Entitlements.plist

This file was deleted.

20 changes: 0 additions & 20 deletions tests/dotnet/MyInterpretedApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,5 @@
<!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>1</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>10.0</string>
<key>CFBundleDisplayName</key>
<string>ApplicationName</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.mysingleview</string>
<key>XSAppIconAssets</key>
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
<key>XSLaunchImageAssets</key>
<string>Resources/Images.xcassets/LaunchImage.launchimage</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions tests/dotnet/MyInterpretedApp/MacCatalyst/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,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<RuntimeIdentifier>maccatalyst-arm64</RuntimeIdentifier>
</PropertyGroup>
<Import Project="../shared.csproj" />
</Project>
13 changes: 12 additions & 1 deletion tests/dotnet/MyInterpretedApp/Main.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
using System;
using System.Runtime.CompilerServices;

using Foundation;
using UIKit;

namespace MySingleView
namespace MyInterpretedApp
{
public class Application
{
static void Main (string[] args)
{
Console.WriteLine ($"Execution mode: {GetExecutionMode ()}");
UIApplication.Main (args, null, typeof (AppDelegate));
}

public static string GetExecutionMode()
{
if (!RuntimeFeature.IsDynamicCodeSupported)
return "AOT";
if (RuntimeFeature.IsDynamicCodeCompiled)
return "JIT";
return "Interpreter";
}
}
}
12 changes: 8 additions & 4 deletions tests/dotnet/MyInterpretedApp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ TOP=../../..

include $(TOP)/Make.config

build:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY)
%-ios:
$(MAKE) -C iOS $@

%-tvos:
$(MAKE) -C tvOS $@

%-maccatalyst %-maccat:
$(MAKE) -C MacCatalyst $@

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run
4 changes: 4 additions & 0 deletions tests/dotnet/MyInterpretedApp/iOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include ../shared.mk

dev:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) /p:RuntimeIdentifier=ios-arm64
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
<OutputType>Exe</OutputType>
<MtouchInterpreter>all</MtouchInterpreter>
</PropertyGroup>
<Import Project="../shared.csproj" />
</Project>
19 changes: 19 additions & 0 deletions tests/dotnet/MyInterpretedApp/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<UseInterpreter>true</UseInterpreter>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>

<ApplicationTitle>MyInterpretedApp</ApplicationTitle>
<ApplicationId>com.xamarin.myinterpretedapp</ApplicationId>
<ApplicationVersion>1.0</ApplicationVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="../*.cs" />
<None Include="../Info.plist">
<Link>Info.plist</Link>
</None>
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions tests/dotnet/MyInterpretedApp/shared.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TOP=../../../..
include $(TOP)/Make.config

reload:
rm -Rf $(TOP)/tests/dotnet/packages
$(MAKE) -C $(TOP) -j8 all
$(MAKE) -C $(TOP) -j8 install
git clean -xfdq

reload-and-build: reload
$(MAKE) build

reload-and-run: reload
$(MAKE) run

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

run:
$(DOTNET6) build /bl *.csproj $(MSBUILD_VERBOSITY) -t:Run

diag:
$(DOTNET6) build /v:diag msbuild.binlog
1 change: 1 addition & 0 deletions tests/dotnet/MyInterpretedApp/tvOS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../shared.mk
7 changes: 7 additions & 0 deletions tests/dotnet/MyInterpretedApp/tvOS/MyInterpretedApp.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>
Loading