-
Notifications
You must be signed in to change notification settings - Fork 564
[One .NET] rework .NET 6 AOT support #6562
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Fixes: #6520 Context: dotnet/runtime#56163 Context: dotnet/runtime#62725 This fixes AOT builds for project names like `foo Ümläüts`, and LLVM-related options are no longer space delimited. Previously, `<MonoAOTCompiler/>` managed its own `WorkingDirectory` to the location that `.dll` input files were located. The problem with this, is that *other* paths like `temp-path`, etc. would then need to be full paths. Full paths containing characters like `Ümläüts` would break! Additionally, `%(AotArguments)` metadata is split on `;` and joined on `,`. And since `ld-flags` contains a `;`, we would lose it. So we delimited by the space character, which also breaks if directories contain a space! To solve these issues: * Added strongly-typed properties to the `<MonoAOTCompiler/>` MSBuild task. We no longer have to put as many things in `%(AotArguments)` on each assembly. Only assembly-specific settings go there now, like the path to AOT profiles. Right now the "main assembly" has no profile at all, and the rest get built-in profiles. * Added a `WorkingDirectory` property, which we pass in `$(MSBuildProjectDirectory)` for the current project directory. After these changes, I could remove many temporary comments around dotnet/runtime#56163, as the tests work properly now.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,13 +51,24 @@ public abstract class GetAotArguments : AndroidAsyncTask | |
|
|
||
| public ITaskItem [] Profiles { get; set; } = Array.Empty<ITaskItem> (); | ||
|
|
||
| public bool UsingAndroidNETSdk { get; set; } | ||
|
|
||
| public string AotAdditionalArguments { get; set; } = ""; | ||
|
|
||
| [Required, Output] | ||
| public ITaskItem [] ResolvedAssemblies { get; set; } = Array.Empty<ITaskItem> (); | ||
|
|
||
| [Output] | ||
| public string? Triple { get; set; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming suggestion:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither The We could use a different name, but is that worse? We'd still be using |
||
|
|
||
| [Output] | ||
| public string? ToolPrefix { get; set; } | ||
|
|
||
| [Output] | ||
| public string? MsymPath { get; set; } | ||
|
|
||
| [Output] | ||
| public string? LdName { get; set; } | ||
|
|
||
| [Output] | ||
| public string? LdFlags { get; set; } | ||
|
|
||
| protected AotMode AotMode; | ||
| protected SequencePointsMode SequencePointsMode; | ||
| protected string SdkBinDirectory = ""; | ||
|
|
@@ -208,22 +219,12 @@ int GetNdkApiLevel (NdkTools ndk, AndroidTargetArch arch) | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a list of parameters to pass to the --aot switch | ||
| /// Fills [Output] parameters to pass to the --aot switch | ||
| /// </summary> | ||
| protected List<string> GetAotOptions (NdkTools ndk, AndroidTargetArch arch, int level, string outdir, string mtriple, string toolPrefix) | ||
| protected void GetAotOptions (NdkTools ndk, AndroidTargetArch arch, int level, string outdir, string toolPrefix) | ||
| { | ||
| List<string> aotOptions = new List<string> (); | ||
|
|
||
| if (!string.IsNullOrEmpty (AotAdditionalArguments)) | ||
| aotOptions.Add (AotAdditionalArguments); | ||
| if (SequencePointsMode == SequencePointsMode.Offline) | ||
| aotOptions.Add ($"msym-dir={outdir}"); | ||
| if (AotMode != AotMode.Normal) | ||
| aotOptions.Add (AotMode.ToString ().ToLowerInvariant ()); | ||
|
|
||
| aotOptions.Add ("asmwriter"); | ||
| aotOptions.Add ($"mtriple={mtriple}"); | ||
| aotOptions.Add ($"tool-prefix={toolPrefix}"); | ||
| MsymPath = outdir; | ||
|
|
||
| string ldName; | ||
| if (EnableLLVM) { | ||
|
|
@@ -238,16 +239,12 @@ protected List<string> GetAotOptions (NdkTools ndk, AndroidTargetArch arch, int | |
| ldName = "ld"; | ||
| } | ||
| string ldFlags = GetLdFlags (ndk, arch, level, toolPrefix); | ||
|
|
||
| // MUST be before `ld-flags`, otherwise Mono fails to parse it on Windows | ||
| if (!string.IsNullOrEmpty (ldName)) { | ||
| aotOptions.Add ($"ld-name={ldName}"); | ||
| LdName = ldName; | ||
| } | ||
| if (!string.IsNullOrEmpty (ldFlags)) { | ||
| aotOptions.Add ($"ld-flags={ldFlags}"); | ||
| LdFlags = ldFlags; | ||
| } | ||
|
|
||
| return aotOptions; | ||
| } | ||
|
|
||
| string GetLdFlags(NdkTools ndk, AndroidTargetArch arch, int level, string toolPrefix) | ||
|
|
@@ -292,13 +289,7 @@ string GetLdFlags(NdkTools ndk, AndroidTargetArch arch, int level, string toolPr | |
| libs.Add (Path.Combine (androidLibPath, "libc.so")); | ||
| libs.Add (Path.Combine (androidLibPath, "libm.so")); | ||
|
|
||
| if (UsingAndroidNETSdk) { | ||
| // NOTE: in .NET 6+ use space for the delimiter and escape spaces in paths | ||
| var escaped = libs.Select (l => l.Replace (" ", "\\ ")); | ||
| ldFlags = string.Join (" ", escaped); | ||
| } else { | ||
| ldFlags = $"\\\"{string.Join ("\\\";\\\"", libs)}\\\""; | ||
| } | ||
| ldFlags = $"\\\"{string.Join ("\\\";\\\"", libs)}\\\""; | ||
| } | ||
| return ldFlags; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System; | ||
|
|
||
| namespace Xamarin.ProjectTools | ||
| { | ||
| public static class AbiUtils | ||
| { | ||
| public static string AbiToRuntimeIdentifier (string androidAbi) | ||
| { | ||
| if (androidAbi == "armeabi-v7a") { | ||
| return "android-arm"; | ||
| } else if (androidAbi == "arm64-v8a") { | ||
| return "android-arm64"; | ||
| } else if (androidAbi == "x86") { | ||
| return "android-x86"; | ||
| } else if (androidAbi == "x86_64") { | ||
| return "android-x64"; | ||
| } | ||
| throw new InvalidOperationException ($"Unknown abi: {androidAbi}"); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.