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

[nativeaot] fix project builds on Windows #9710

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

jonathanpeppers
Copy link
Member

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:

@jonathanpeppers jonathanpeppers marked this pull request as draft January 27, 2025 17:25
@jonathanpeppers
Copy link
Member Author

This fails on CI, but works locally...

'where' is not recognized as an internal or external command,

The <Exec Command="where /Q ..." call is in NativeAOT's MSBuild targets

@jonathanpeppers
Copy link
Member Author

Odd, I have C:\Windows\System32\where.exe locally, that works.

On CI, C:\Windows\System32 is in %PATH%:

Setting $PATH to: C:\Android\android-sdk\ndk\27.2.12479018\toolchains\llvm\prebuilt\windows-x86_64\bin\;D:\a\_work\1\s\bin\Release\dotnet;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\17.0.13-11\x64\bin;C:\hostedtoolcache\windows";C:\vss-agent\4.251.0\externals\git\cmd;C:\vss-agent\4.251.0\externals\git\mingw64\bin;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS\;C:\tools\zstd;C:\Program Files\Mercurial\;C:\hostedtoolcache\windows\stack\3.3.1\x64;C:\cabal\bin;C:\\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver\;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.432-6\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Microsoft SQL Server\160\DTS\Binn\;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.9\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI\;c:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2\;C:\Program Files\Amazon\SessionManagerPlugin\bin\;C:\Program Files\Amazon\AWSSAMCLI\bin\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\LLVM\bin;C:\hostedtoolcache\windows\Python\3.11.9\x64;C:\hostedtoolcache\windows\Python\3.11.9\x64\Scripts;C:\Program Files\nodejs\;C:\Users\cloudtest\.dotnet\tools;C:\Users\cloudtest\.cargo\bin;C:\Users\cloudtest\AppData\Local\Microsoft\WindowsApps

Then I see a non-escaped, non-closed quote?!?

;C:\hostedtoolcache\windows";

@dellis1972
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/windows/nativeaot branch from ab7f020 to ad59c69 Compare January 27, 2025 23:47
Comment on lines 26 to 27
- script: echo "##vso[task.prependpath]$(Agent.ToolsDirectory)"
displayName: add $(Agent.ToolsDirectory) to path
Copy link
Member Author

Choose a reason for hiding this comment

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

This solves the problem with %PATH%:

image

Going to rebase, we have this change in main now.

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
@jonathanpeppers jonathanpeppers force-pushed the dev/peppers/windows/nativeaot branch from ad59c69 to aa96dfe Compare January 28, 2025 01:02
@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 28, 2025 01:02
@jonathanpeppers jonathanpeppers merged commit ed0d8a0 into main Jan 28, 2025
58 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/windows/nativeaot branch January 28, 2025 14:53
grendello added a commit that referenced this pull request Jan 28, 2025
* main:
  [Mono.Android] Bind Android API-Baklava Beta 1 (#9707)
  [nativeaot] fix project builds on Windows (#9710)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants