Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
30c3091
Brand release/6.0-maui branch appropriately (#61792)
directhex Nov 24, 2021
af20fce
[mono][interp] Remove hack for nint/nfloat (#62053)
BrzVlad Nov 30, 2021
5e7fb16
Shrink version name due to nuget maximum (#62190)
directhex Dec 1, 2021
6c8d2b0
[release/6.0-maui] Exclude the managed code around libproc on iOS/tvO…
MaximLipnin Dec 2, 2021
3992fc3
Update timeout for sourcebuild (#61436) (#62300)
directhex Dec 2, 2021
2ab2de4
[MonoAOTCompiler] more properties & custom WorkingDirectory (#62849)
github-actions[bot] Dec 16, 2021
6523aa4
Merge branch 'release/6.0-maui' into merge/release/6.0-to-release/6.0…
akoeplinger Dec 20, 2021
d63fcb9
Disable package generation
akoeplinger Dec 20, 2021
37e3ee4
Merge pull request #62850 from dotnet-maestro-bot/merge/release/6.0-t…
jkotas Dec 22, 2021
7636d44
transform sgen_get_descriptor to parallel safe version in job_major_m…
github-actions[bot] Jan 4, 2022
b96f560
Bump SdkBandVersion prop to 6.0.200 (#62787)
steveisok Jan 4, 2022
a66e67b
Bump SdkVersionForWorkloadTesting to use a 200 band SDK (#63450)
steveisok Jan 7, 2022
a9d5ccd
[release/6.0-maui] Add back HAVE_SYS_ZLIB support (#63359)
lambdageek Jan 10, 2022
f36afb1
[release/6.0-maui] Backport MacCatalyst process start support (#62520)
simonrozsival Jan 11, 2022
936a1c1
[automated] Merge branch 'release/6.0' => 'release/6.0-maui' (#63112)
dotnet-maestro-bot Jan 14, 2022
e08fc29
Merge branch 'release/6.0-maui' into merge/release/6.0-to-release/6.0…
akoeplinger Jan 17, 2022
1ea69f9
Merge pull request #63807 from dotnet-maestro-bot/merge/release/6.0-t…
akoeplinger Jan 17, 2022
a54012e
[release/6.0-maui] Serialize SendPacketsAsync tests (#63896)
github-actions[bot] Jan 18, 2022
ffa6594
[release/6.0-maui] [Android] Prevent potential out of bounds write on…
github-actions[bot] Jan 18, 2022
994a341
[release/6.0-maui] [debugger] Fix reading a byte without checking the…
thaystg Jan 18, 2022
063054b
[release/6.0-maui] [mono][debugger] Fix step on ios when using interp…
github-actions[bot] Jan 18, 2022
fd2cdbb
[iOS/tvOS] Remove P/Invokes to libproc from System.Private.CoreLib (#…
akoeplinger Jan 18, 2022
49d6db3
[release/6.0-maui] [Android] Fix accessing network interfaces informa…
simonrozsival Jan 18, 2022
4f567e5
Take MacCatalyst into account in EnvironmentTests.WorkingSet_Valid te…
github-actions[bot] Jan 19, 2022
6371525
[release/6.0-maui] Android remove backward timezones (#64228)
github-actions[bot] Jan 24, 2022
059caa2
Merge pull request #64056 from dotnet-maestro-bot/merge/release/6.0-t…
akoeplinger Jan 25, 2022
9e82981
[release/6.0-maui][mono] Recognize new names for Xamarin.iOS etc asse…
akoeplinger Jan 26, 2022
2405c8e
Revert branch specific changes
safern Jan 26, 2022
e7920eb
Merge branch 'release/6.0' into merge-maui-branch-to-6.0
akoeplinger Feb 3, 2022
7ba7eae
Merge remote-tracking branch 'upstream/release/6.0' into merge-maui-b…
akoeplinger Feb 7, 2022
0f45149
Add the ability to generate Mono toolchain manifests per sdk band. 1…
Feb 8, 2022
bdc58e1
Merge remote-tracking branch 'upstream/release/6.0' into merge-maui-b…
Feb 8, 2022
da2f120
Remove unnecessary SdkBandVersion prop
Feb 8, 2022
0dead8c
Revert removing SdkBandVersion change. Wasm tests still need it
Feb 8, 2022
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
Prev Previous commit
Next Next commit
[MonoAOTCompiler] more properties & custom WorkingDirectory (#62849)
Fixes: #56163

PR #58523 fixed something on Windows, but it didn't actually address
our issues on Android.

A directory name like `foo Ümläüts` fails:

* `mkdir 'foo Ümläüts' ; cd 'foo Ümläüts'`
* `dotnet new android`
* `dotnet build -c Release -p:RunAOTCompilation=true` (adding
  `-p:EnableLLVM=true` complicates further)

The error:

    Precompiling failed for C:\src\foo Ümläüts\obj\Release\android-arm64\linked\System.Private.CoreLib.dll: Error: Loaded assembly 'C:\src\foo ├£ml├ñ├╝ts\obj\Release\android-arm64\linked\System.Private.CoreLib.dll' doesn't match original file name 'C:\foo ▄mlΣⁿts\obj\Release\android-arm64\linked\System.Private.CoreLib.dll'. Set MONO_PATH to the assembly's location.

Reviewing the existing AOT implementation in Xamarin.Android, I found
out *why* Xamarin.Android works:

    [AOT] response file obj\Release\120\aot\arm64-v8a\App36.dll\response.txt: --llvm "--aot=temp-path=obj\Release\120\aot\arm64-v8a\App36.dll,llvm-path=C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\Android,outfile=obj\Release\120\aot\arm64-v8a\libaot-App36.dll.so,msym-dir=obj\Release\120\aot\arm64-v8a,asmwriter,mtriple=aarch64-linux-android,tool-prefix=C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\aarch64-linux-android-,ld-name=ld.EXE,ld-flags=\"-LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\aarch64-linux-android\4.9.x\";\"-LC:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm64\usr\lib\";\"C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib\gcc\aarch64-linux-android\4.9.x\libgcc.a\";\"C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm64\usr\lib\libc.so\";\"C:\Program Files (x86)\Android\android-sdk\ndk-bundle\platforms\android-21\arch-arm64\usr\lib\libm.so\"" C:\Users\jopepper\source\repos\App36\App36\obj\Release\120\android\assets\shrunk\App36.dll

1. Xamarin.Android passes *relative* paths. The `foo Ümläüts`
   directory name doesn't even come into play for some arguments.

2. With LLVM, `ld-flags` contains a `;`.

The existing code splits on `;` and joins on `,`:

https://github.com/dotnet/runtime/blob/25c207351c4f57cf2daa98caaf327a8b8d83edb8/src/tasks/AotCompilerTask/MonoAOTCompiler.cs#L505-L509

So we lose any `;` delimiters for the `ld-flags` value, they get
replaced by `,`.

I think the solution here is:

1. Add several missing properties to `<MonoAOTCompiler/>` so we don't
   have to rely on the `%(AotArguments)` item metadata. No splitting
   on `;` would be required, `ld-flags` can be passed in and used as-is.

2. Add a new `WorkingDirectory` property. When this is set, assume
   paths passed in might be relative -- and don't transform paths by
   calling `Path.GetFullPath()`.

Lastly, I fixed a place where the UTF8 encoding wasn't passed when
MSBuild logging the response file.

These changes I tried to make in a way where this shouldn't break
other .NET workloads like wasm. If existing MSBuild targets call this
task (not using the new properties), the behavior should remain
unchanged.

I tested these changes by commiting a modified `MonoAOTCompiler.dll`:

dotnet/android#6562

I'm able to enable several AOT tests related to #56163.

Co-authored-by: Jonathan Peppers <[email protected]>
  • Loading branch information
github-actions[bot] and jonathanpeppers authored Dec 16, 2021
commit 2ab2de48f0ab18e52a60fbff8635016df3cb5a93
68 changes: 63 additions & 5 deletions src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,39 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
/// </summary>
public string? CacheFilePath { get; set; }

/// <summary>
/// Passes additional, custom arguments to --aot
/// </summary>
public string? AotArguments { get; set; }

/// <summary>
/// Passes temp-path to the AOT compiler
/// </summary>
public string? TempPath { get; set; }

/// <summary>
/// Passes ld-name to the AOT compiler, for use with UseLLVM=true
/// </summary>
public string? LdName { get; set; }

/// <summary>
/// Passes ld-flags to the AOT compiler, for use with UseLLVM=true
/// </summary>
public string? LdFlags { get; set; }

/// <summary>
/// Specify WorkingDirectory for the AOT compiler
/// </summary>
public string? WorkingDirectory { get; set; }

[Required]
public string IntermediateOutputPath { get; set; } = string.Empty;

[Output]
public string[]? FileWrites { get; private set; }

private static readonly Encoding s_utf8Encoding = new UTF8Encoding(false);

private List<string> _fileWrites = new();

private IList<ITaskItem>? _assembliesToCompile;
Expand Down Expand Up @@ -225,7 +252,9 @@ private bool ProcessAndValidateArguments()
return false;
}

if (!Path.IsPathRooted(OutputDir))
// A relative path might be used along with WorkingDirectory,
// only call Path.GetFullPath() if WorkingDirectory is blank.
if (string.IsNullOrEmpty(WorkingDirectory) && !Path.IsPathRooted(OutputDir))
OutputDir = Path.GetFullPath(OutputDir);

if (!Directory.Exists(OutputDir))
Expand Down Expand Up @@ -682,6 +711,26 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
}
}

if (!string.IsNullOrEmpty(AotArguments))
{
aotArgs.Add(AotArguments);
}

if (!string.IsNullOrEmpty(TempPath))
{
aotArgs.Add($"temp-path={TempPath}");
}

if (!string.IsNullOrEmpty(LdName))
{
aotArgs.Add($"ld-name={LdName}");
}

if (!string.IsNullOrEmpty(LdFlags))
{
aotArgs.Add($"ld-flags={LdFlags}");
}

// we need to quote the entire --aot arguments here to make sure it is parsed
// on Windows as one argument. Otherwise it will be split up into multiple
// values, which wont work.
Expand All @@ -694,7 +743,16 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st
}
else
{
processArgs.Add('"' + assemblyFilename + '"');
if (string.IsNullOrEmpty(WorkingDirectory))
{
processArgs.Add('"' + assemblyFilename + '"');
}
else
{
// If WorkingDirectory is supplied, the caller could be passing in a relative path
// Use the original ItemSpec that was passed in.
processArgs.Add('"' + assemblyItem.ItemSpec + '"');
}
}

monoPaths = $"{assemblyDir}{Path.PathSeparator}{monoPaths}";
Expand All @@ -706,14 +764,14 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st

var responseFileContent = string.Join(" ", processArgs);
var responseFilePath = Path.GetTempFileName();
using (var sw = new StreamWriter(responseFilePath, append: false, encoding: new UTF8Encoding(false)))
using (var sw = new StreamWriter(responseFilePath, append: false, encoding: s_utf8Encoding))
{
sw.WriteLine(responseFileContent);
}

return new PrecompileArguments(ResponseFilePath: responseFilePath,
EnvironmentVariables: envVariables,
WorkingDir: assemblyDir,
WorkingDir: string.IsNullOrEmpty(WorkingDirectory) ? assemblyDir : WorkingDirectory,
AOTAssembly: aotAssembly,
ProxyFiles: proxyFiles);
}
Expand Down Expand Up @@ -741,7 +799,7 @@ private bool PrecompileLibrary(PrecompileArguments args)
StringBuilder envStr = new StringBuilder(string.Empty);
foreach (KeyValuePair<string, string> kvp in args.EnvironmentVariables)
envStr.Append($"{kvp.Key}={kvp.Value} ");
Log.LogMessage(importance, $"{msgPrefix}Exec (with response file contents expanded) in {args.WorkingDir}: {envStr}{CompilerBinaryPath} {File.ReadAllText(args.ResponseFilePath)}");
Log.LogMessage(importance, $"{msgPrefix}Exec (with response file contents expanded) in {args.WorkingDir}: {envStr}{CompilerBinaryPath} {File.ReadAllText(args.ResponseFilePath, s_utf8Encoding)}");
}

Log.LogMessage(importance, output);
Expand Down