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

[XM] Prototype of AOT support in Xamarin.Mac #1340

Merged
merged 22 commits into from
Jan 11, 2017
Merged

[XM] Prototype of AOT support in Xamarin.Mac #1340

merged 22 commits into from
Jan 11, 2017

Conversation

chamons
Copy link
Contributor

@chamons chamons commented Dec 12, 2016

No description provided.

@chamons chamons added requires-approval-before-merge The pull request requires special approval before it can be merged requires-qa-before-merge The pull request requires QA to approve it before it can be merged run-mac-binding-project-tests Run the mac binding project tests run-mmp-tests Run the mmp tests labels Dec 12, 2016
@chamons chamons self-assigned this Dec 12, 2016
@chamons
Copy link
Contributor Author

chamons commented Dec 12, 2016

Let's get this out here for testing.

Copy link
Contributor

@spouliot spouliot left a comment

Choose a reason for hiding this comment

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

beside the name, the rest is fine :)

@chamons
Copy link
Contributor Author

chamons commented Dec 12, 2016

@spouliot I'll %s/experimental-xm-aot/xm-aot/gc after QA approves it and we're going to master. I just want a scary sounding name for testing.

@monojenkins
Copy link
Collaborator

Build success

@@ -358,6 +359,7 @@ static void Main2 (string [] args)
{ "xamarin-framework-directory=", "The framework directory", v => { xm_framework_dir = v; }, true },
{ "xamarin-full-framework", "Used with --target-framework=4.5 to select XM 4.5 Target Framework", v => { IsUnifiedFullXamMacFramework = true; } },
{ "xamarin-system-framework", "Used with --target-framework=4.5 to select XM 4.5 Target Framework", v => { IsUnifiedFullSystemFramework = true; } },
{ "experimental-xm-aot", "Enable experimental AOT Xamarin.Mac support. Careful, the pieces might be sharp.", v => { experimental_xm_aot = true; }, true }, // Experimental - If it breaks for now you get to keep the pieces
Copy link
Member

Choose a reason for hiding this comment

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

I would name this experimental-aot (imho the xm part is redundant).

@@ -771,12 +773,35 @@ static void Pack (IList<string> unprocessed)
if (App.LinkMode != LinkMode.All && App.RuntimeOptions != null)
App.RuntimeOptions.Write (App.AppDirectory);

if (experimental_xm_aot.HasValue && experimental_xm_aot.Value && IsUnified) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe show an error if aot is requested for Classic instead of silently ignoring it.

if (!string.IsNullOrEmpty (certificate_name)) {
CodeSign ();
Watch ("Code Sign", 1);
}
}

static void AOTBundle ()
{
string monoExe = Is64Bit ? "/usr/local/bin/mono64" : "/usr/local/bin/mono";
Copy link
Member

Choose a reason for hiding this comment

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

I think /Library/Frameworks/Mono.framework/Commands is the supported location of the mono binaries.

Also I'd use mono32 and mono64, since I think the mono binary one day will switch to be 64-bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... not sure mono32 can AOT 64bits code.

I think that XM needs to ship it's own AOT compilers since the system mono might not match with the BCL version XM ships.

IOW the above code should be fine when using the system mono (as long as both 32 and 64 bits are shipping) but it might fail for the bundle 4.5 support coming out of XM.

For a first preview it might be good enough to specify which mono version(s) is/are compatible.

string quotedFileList = string.Join (" ", dirInfo.EnumerateFiles ().Where (aotableFile).Select (x => Quote(x.ToString ())));
foreach (var file in dirInfo.EnumerateFiles ().Where (aotableFile))
{
if (RunCommand (monoExe, String.Format ("--aot=hybrid {0}", Quote (file.ToString ())), new string [] {"MONO_PATH", mmp_dir }) > 0)
Copy link
Member

Choose a reason for hiding this comment

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

This can be parallelized to speed it up significantly.

mtouch currently uses Parallel.ForEach to AOT in parallel [1] (the default is to set MaxDegreeOfParallelism to the number of processors, but this can be overridden by passing -jX /--jobs X (like for make) to motuch).

@monojenkins
Copy link
Collaborator

Build failure

@monojenkins
Copy link
Collaborator

Build failure

case "all":
aot = AotType.All;
break;
case "platform":
Copy link
Member

Choose a reason for hiding this comment

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

Another possibility here is sdk: every assembly in the XM SDK (that we ship).

Copy link
Member

Choose a reason for hiding this comment

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

Another syntax idea (but yours is fine if you like it better):

--aot:+System.dll,-MyCustom.dll

which would set AotType.Explicit, enable AOT for System.dll and disable it for MyCustom.dll

This is how mtouch' --dlsym: option works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rolfbjarne Lining up with how mtouch does things is good enough for me. :) I'll rework

case AotType.Explicit:
return aot_explicit_reference.Contains (x.Name);
default:
throw new InvalidOperationException ($"AOTBundle with aot: {aot}?");
Copy link
Member

Choose a reason for hiding this comment

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

This should have a better error number, maybe something like this: https://github.com/rolfbjarne/xamarin-macios/blob/framework-sdk/tools/mtouch/error.cs#L108

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


Parallel.ForEach (dirInfo.EnumerateFiles ().Where (aotableFile), new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, file => {
if (RunCommand (monoExe, String.Format ("--aot=hybrid {0}", Quote (file.ToString ())), new string [] {"MONO_PATH", mmp_dir }) > 0)
ErrorHelper.Warning (1337, string.Format ("AOT failed on {0}", file));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this an error? Users can now ignore specific assemblies if they're causing trouble, while still AOT-ing the rest, so making it an error won't prevent people from enabling AOT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it was a warning from back before ignore was an option. 👍

@monojenkins
Copy link
Collaborator

Build failure

@monojenkins
Copy link
Collaborator

Build success

// MM5103 Failed to compile. Error code - {0}. Please file a bug report at http://bugzilla.xamarin.com
// MM5104 ** reserved mtouch **
// MM5105 Failed to AOT compile. Error code - {0}. Please file a bug report at http://bugzilla.xamarin.com
Copy link
Contributor

Choose a reason for hiding this comment

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

MT3xxx segment is reserved for AOT compiler errors

@monojenkins
Copy link
Collaborator

Build failure

aotFiles.Add (file);
break;
case AotType.SDK:
if (fileName == "Xamarin.Mac.dll" || fileName == "System.dll" || fileName == "mscorlib.dll")
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason for limiting "SDK" to these three assemblies? We already have a Profile.IsSdkAssembly method you can use: https://github.com/xamarin/xamarin-macios/blob/master/tools/mmp/driver.cs#L687

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good reason. Let me use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So @rolfbjarne there is apparently a good reason:

https://github.com/xamarin/xamarin-macios/blob/master/tools/mmp/linker/MonoMac.Tuner/MonoMacProfile.cs#L106

The list of SDK assemblies turns out to be the entire BCL pretty much + the Xamarin.Mac bits.

The idea behind the SDK option was to be a middle ground of the stuff pulled in always while being fast.

I'm open to changing this list, or renaming it if you can think of a better name. Swapping to Profile.IsSdkAssembly would make it almost the same as All.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not overload (and confuse) the meaning of SDK in the tooling. Rename it to something else, e.g. core ?

FWIW sdk might be an valid (we lack data to see if it's a good one) option, it's definitively a good one for the linker (and we should avoid confusion between them).

Copy link
Member

Choose a reason for hiding this comment

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

I like core as well, for the same reasons Sebastien mentions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

if (!IsAOT)
throw ErrorHelper.CreateError (0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", aotType);

const string MonoExePath = "/Library/Frameworks/Xamarin.Mac.framework/Commands/bmac-mobile-mono";
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't take XAMMAC_FRAMEWORK_PATH into account, you already have a method to get it: https://github.com/xamarin/xamarin-macios/blob/master/tools/mmp/driver.cs#L963

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

- Stop hard coded bmac-mobile-mono path
- Rename sdk to core
- Add real sdk option to AOT
@monojenkins
Copy link
Collaborator

Build failure

@chamons
Copy link
Contributor Author

chamons commented Jan 4, 2017

Build error is my fault. Fixing.

@monojenkins
Copy link
Collaborator

Build success

@chamons
Copy link
Contributor Author

chamons commented Jan 6, 2017

@spouliot / @rolfbjarne Any more changes for this PR?

@chamons
Copy link
Contributor Author

chamons commented Jan 6, 2017

The only outstanding thing on my end is to add the 32-bit mono to what we ship and remove the "only allow AOT in 64-bit" check.

@chamons
Copy link
Contributor Author

chamons commented Jan 9, 2017

Ok. 32-bit changes are in.

QA got back to us and said it will be awhile until they can test things manually.

I'd like to get this in master now. We can rip out the option late in C10 if things unlikely don't work out.

@rolfbjarne / @spouliot - Ready to go? Can I get an approve changes if 👍

@monojenkins
Copy link
Collaborator

Build failure

@spouliot
Copy link
Contributor

@chamons 👍 please update the release notes in the wiki

if (!IsAOT)
throw ErrorHelper.CreateError (0099, "Internal error \"AOTBundle with aot: {0}\" Please file a bug report with a test case (http://bugzilla.xamarin.com).", aotType);

string monoExePath = Path.Combine (XamarinMacPrefix, "bin/bmac-mobile-mono" + (Is64Bit ? "" : "-32"));
Copy link
Member

Choose a reason for hiding this comment

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

Does this work for all the three profiles (mobile, xm 4.5 and system)? I believe we'll have to use the system mono when using the system profile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah. You are right. I incorrectly assumed that as long as we got the assemblies in place by the rest of the system, AOT could not care about which mono (system or built in) was used.

Let me rework.

Copy link
Contributor

@spouliot spouliot left a comment

Choose a reason for hiding this comment

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

👍

@monojenkins
Copy link
Collaborator

Build failure

@monojenkins
Copy link
Collaborator

Build failure

@chamons
Copy link
Contributor Author

chamons commented Jan 10, 2017

build

@monojenkins
Copy link
Collaborator

Build failure

@chamons
Copy link
Contributor Author

chamons commented Jan 11, 2017

build

@monojenkins
Copy link
Collaborator

Build failure

@chamons
Copy link
Contributor Author

chamons commented Jan 11, 2017

Test failure is a known issue in the mac bindings tests and is unrelated I believe.

@chamons chamons removed the requires-qa-before-merge The pull request requires QA to approve it before it can be merged label Jan 11, 2017
@chamons chamons merged commit ffe142d into master Jan 11, 2017
@chamons chamons deleted the xm_aot branch January 11, 2017 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires-approval-before-merge The pull request requires special approval before it can be merged run-mac-binding-project-tests Run the mac binding project tests run-mmp-tests Run the mmp tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants