-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nativeaot] fix project builds on Windows (#9710)
In 2fa7954, we got Android projects *building* for NativeAOT. However, this didn't work at all on Windows. Reviewing how NativeAOT's MSBuild targets are setup, they expect various tooling to be available in `%PATH%`. To fix this: * Create a new `<SetNdkPathForIlc/>` MSBuild task. * That simply sets the Android NDK "bin" directory to `%PATH%`. NativeAOT apps now successfully build (and run) on Windows. I also updated an integration test to verify this. Unfortunately, we still have to set `$(DisableUnsupportedError)` or we will get the message: D:\.nuget\packages\microsoft.dotnet.ilcompiler\10.0.0-alpha.1.25067.10\build\Microsoft.NETCore.Native.Publish.targets(61,5): error : Cross-OS native compilation is not supported. Please use the appropriate OS-specific target. A future change might be needed here, or it might be fine to for the Android workload to set this property: * https://github.com/dotnet/runtime/blob/ea4a404ef8890f265780f798e7668d4710259e03/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets#L61-L62
- Loading branch information
1 parent
f4e405e
commit ed0d8a0
Showing
3 changed files
with
36 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.IO; | ||
using Microsoft.Android.Build.Tasks; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace Xamarin.Android.Tasks; | ||
|
||
/// <summary> | ||
/// NativeAOT's compiler (ILC) expects to find tooling in $PATH | ||
/// </summary> | ||
public class SetNdkPathForIlc : AndroidTask | ||
{ | ||
public override string TaskPrefix => "SILC"; | ||
|
||
[Required] | ||
public string NdkBinDirectory { get; set; } = ""; | ||
|
||
public override bool RunTask () | ||
{ | ||
var ndkbin = Path.GetFullPath (NdkBinDirectory); | ||
var path = $"{ndkbin}{Path.PathSeparator}{Environment.GetEnvironmentVariable ("PATH")}"; | ||
Log.LogDebugMessage ($"Setting $PATH to: {path}"); | ||
Environment.SetEnvironmentVariable ("PATH", path); | ||
return !Log.HasLoggedErrors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters