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

How to build a project using locally built ILCompiler? #68257

Closed
adamsitnik opened this issue Apr 20, 2022 · 2 comments · Fixed by #68308
Closed

How to build a project using locally built ILCompiler? #68257

adamsitnik opened this issue Apr 20, 2022 · 2 comments · Fixed by #68308
Labels
area-NativeAOT-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@adamsitnik
Copy link
Member

With CoreRT, it was possible to build an app using ILCompiler that was built locally: https://github.com/dotnet/corert/blob/7f902d4d8b1c3280e60f5e06c71951a60da173fb/Documentation/how-to-build-and-run-ilcompiler-in-console-shell-prompt.md#compiling-source-to-native-code-using-the-ilcompiler-you-built

BenchmarkDotNet supported that, but I've not used it for a long time. Today I wanted to give it a try to test #68249 and I've failed.

Sample project file:

<Project>
  <Import Project="$(MSBuildSDKsPath)\Microsoft.NET.Sdk\Sdk\Sdk.props" />
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PlatformTarget>x64</PlatformTarget>
    <IlcOptimizationPreference>Speed</IlcOptimizationPreference>
    <TrimMode>link</TrimMode><TrimmerDefaultAction>link</TrimmerDefaultAction>
    <IlcGenerateCompleteTypeMetadata>True</IlcGenerateCompleteTypeMetadata>
    <IlcGenerateStackTraceData>True</IlcGenerateStackTraceData>
    <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
  </PropertyGroup>
  <Import Project="$(MSBuildSDKsPath)\Microsoft.NET.Sdk\Sdk\Sdk.targets" />
  <Import Project="$(IlcPath)\build\Microsoft.NETCore.Native.targets" />
  <ItemGroup>
    <IlcArg Include="--instructionset:base,sse,sse2,sse3,sse4.1,sse4.2,avx,avx2,aes,bmi,bmi2,fma,lzcnt,pclmul,popcnt" />
  </ItemGroup>
</Project>

The first error I got was: Native compilation can run on x64 and arm64 hosts only. I was able to work around it by passing /p:IlcHostArch=x64.

The next error I got was: The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative.

This property is computed in following way:

<PrivateSdkAssemblies Include="$(IlcSdkPath)*.dll" Exclude="@(_ExcludedPrivateSdkAssemblies)"/>

<IlcSdkPath Condition="'$(IlcSdkPath)' == ''">$(RuntimePackagePath)\sdk\</IlcSdkPath>

I can see that there is no "sdk" folder in \artifacts\bin\coreclr\windows.x64.Release\ (after running .\build.cmd -c Release -subset Clr), but there is an "aotsdk" folder. Also, the test project seems to just get the right path from MSBuild:

<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>

I've workarounded this problem by just passing the right flag but got stuck few errors later. I gave up assuming that I am trying to open doors that somebody else have already opened.

@MichalStrehovsky @jkotas is there an easy (even hacky) way to get it working?

@adamsitnik adamsitnik added question Answer questions and provide assistance, not an issue with source code or documentation. area-NativeAOT-coreclr labels Apr 20, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 20, 2022
@hez2010
Copy link
Contributor

hez2010 commented Apr 20, 2022

I would recommend to generate a rsp file manually and pass it directly to ilc.

@jkotas
Copy link
Member

jkotas commented Apr 20, 2022

The easiest way to use the locally built compiler is do a full build including packaging, add nuget.config path that points to ...\artifacts\packages\Release\Shipping and use regular project structure.

We have IlcXXXPath variables that allow you to override path for each component. This is what the tests are doing:

<DisableUnsupportedError>true</DisableUnsupportedError>
<IlcToolsPath>$(CoreCLRILCompilerDir)</IlcToolsPath>
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
<IlcFrameworkPath>$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)</IlcFrameworkPath>
<IlcFrameworkNativePath>$(MicrosoftNetCoreAppRuntimePackNativeDir)</IlcFrameworkNativePath>

My typical dev workflow is to build the regular package and point nuget.config to it, and then override IlcXXXPaths for the part that I am iterating on. The added benefit is that it allows me to mix and match release and debug builds of the compiler and libraries (e.g. use Debug compiler and Release libraries).

jkotas added a commit to jkotas/runtime that referenced this issue Apr 21, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 21, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Apr 21, 2022
directhex pushed a commit to directhex/runtime that referenced this issue Apr 21, 2022
@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label May 3, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants