Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Conversation

@A-And
Copy link
Contributor

@A-And A-And commented Nov 22, 2017

Below is a working implementation - CoreRT can be consumed by adding a

 <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="X" /> 

where X is the version of the ILCompiler package produced by build-packages.cmd or once its published with

dotnet add package Microsoft.DotNet.ILCompiler

Ideally, I'd like to add the assemblies produced by the project references in Microsoft.DotNet.ILCompiler.pkgproj to have their TargetPath property overriden when creating this package specifically, but the paths seem to be dynamically generated somewhere in the compiler. Can anyone more familiar with the NuGet package publishing pipeline take a look?
Additionally, the implementation below doesn't include symbols for the framework, sdk and tools assemblies to the final package.

<!-- PackageTargetRuntime needs to be reset because if let unset, it's going to be set to globally configured value
which will cause the package assets to be placed into runtime/[RID]/lib/[TFM]/ path, instead of lib/[TFM] -->

<ProjectReference Include="$(PackageSourceDirectory)ILCompiler\src\ILCompiler.csproj" >
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these ProjectReferences at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not specifically.
Ideally, I'd like to use the assemblies generated by these directly instead of including the entire 'tools' folder. I wanted to leave them here mostly so discussion is easier.

Copy link
Member

@jkotas jkotas Nov 22, 2017

Choose a reason for hiding this comment

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

The package needs to contain the compiler as published app so that it can run (ie what you would get if you have done dotnet publish ILCompiler.csproj).

The "buildtools" msbuild targets that we are using currently do not support regular publishing easily, so we produce the bits in semi-complicated way. The result is about the same as what you would get by running dotnet publish ILCompiler.csproj ILCompiler.csproj -r <...>.

For the package reference to work well here, it would need to somehow do the publishing. And if the publishing works, it should be sufficient to have just the reference to ILCompiler.csproj since the publishing does transitive closure.

"Microsoft.DotNet.ILCompiler" : {
"StableVersions": [],
"BaselineVersion": "1.0.0",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: there is an extra space on this line.

@A-And A-And force-pushed the ILCompilerPackageSupport branch from a95eb72 to df23f56 Compare November 27, 2017 18:02
<!-- PackageTargetRuntime needs to be reset because if let unset, it's going to be set to globally configured value
which will cause the package assets to be placed into runtime/[RID]/lib/[TFM]/ path, instead of lib/[TFM] -->

<Dependency Include="Microsoft.DotNet.ObjectWriter">
Copy link
Member

Choose a reason for hiding this comment

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

I do not think ObjectWriter, NetCore.Jit and S.C.Immutable packages needs to be listed here at all.

Copy link
Member

Choose a reason for hiding this comment

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

(And if they need to be here for some reason - they should use versions from https://github.com/dotnet/corert/blob/master/dependencies.props)

@A-And A-And force-pushed the ILCompilerPackageSupport branch from 2c9282e to e9959f6 Compare November 27, 2017 23:06
@A-And A-And changed the title [WIP] ILCompiler nuget package support ILCompiler nuget package support Nov 27, 2017
@A-And A-And changed the title ILCompiler nuget package support [WIP] ILCompiler nuget package support Nov 27, 2017
@A-And A-And force-pushed the ILCompilerPackageSupport branch 3 times, most recently from 6248d9e to 9cee186 Compare November 30, 2017 21:57

Once completed, you can find the native executable in the root folder of your project under ``/bin/x64/<Configuration>/netcoreapp2.0/publish/``

## Try it out!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrong tone?

<TargetOS Condition="'$(TargetOS)' == '' and '$(OS)' == 'Unix' and Exists('/Applications')">OSX</TargetOS>
<TargetOS Condition="'$(TargetOS)' == ''">$(OS)</TargetOS>
<!-- Detect whether we're running the ILCompiler from a package and if so override the environmental variable to point to the correct assemblies -->
<IlcPath Condition="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Microsoft.DotNet.ILCompiler.nuspec)) != ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Microsoft.DotNet.ILCompiler.nuspec))</IlcPath>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels a bit hacky. There could be a better approach.

Copy link
Member

Choose a reason for hiding this comment

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

Can this be just something like <IlcPath Condition="$(IlcPath) == ''">$(MSBuildThisFileDirectory)/..</IlcPath> ?

@A-And A-And changed the title [WIP] ILCompiler nuget package support ILCompiler nuget package support Nov 30, 2017
@A-And A-And force-pushed the ILCompilerPackageSupport branch from 75d4664 to 03ad3f7 Compare November 30, 2017 22:17

namespace SampleWebApi.Controllers
{
public class ValuesController {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is incorrect here.

return new string[] { "value1", "value2" };
}

// This is the method that crashes, which Sergiy and I mentioned
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please open an issue to track this problem?

</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this reference? I would remove it to keep the sample project simple.

</PropertyGroup>

<ItemGroup>
<IlcArg Include="--noscan" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the "--noscan" compiler option should not be necessary after #5040 is merged. I would remove it from the sample.


``dotnet publish -c <Configuration> -r <RID>``

where ``<Configuration>`` is your project configuratio (such as Debug or Release) and ``<RID>`` is the runtime identifier - one of ``win-x64``, ``win-x86``, ``linux-x64`` or ``osx-x64`` depending on the OS you want to publish for. For example, if you want to publish a release configuration of your app for a 64-bit version of Windows the command would look like:
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently x86 is not supported by CoreRT. I would remove "win-x86"


where path_to_rdxml_file is the location of the file on your disk. Under the second ``<ItemGroup>`` remove the reference to ``Microsoft.AspNetCore.All`` and substitute it with:

<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview1-final" />
Copy link
Contributor

Choose a reason for hiding this comment

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

The version for ASP.NET packages should be Version="2.0.0". What you have is a pre-release versions.

</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview1-final" />
Copy link
Contributor

Choose a reason for hiding this comment

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

The version for ASP.NET packages should be Version="2.0.0".

<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-25929-0" />
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is possible, I would not hardcode a specific version of the compiler package. Ideally, the sample should run against the latest published one.

@sergiy-k
Copy link
Contributor

sergiy-k commented Dec 1, 2017

@A-And, thank you!
If you don't mind, I would suggest to check in the sample as a separate PR. Basically:

  1. Merge the compiler nuget package support
  2. Make sure we have an official build published
  3. Make the sample work against the latest officially published build and check the sample in.

@A-And
Copy link
Contributor Author

A-And commented Dec 1, 2017

@sergiy-k Sure thing! Would make certainly make more sense.

@A-And A-And force-pushed the ILCompilerPackageSupport branch from 3b3c327 to aec5771 Compare December 1, 2017 18:27
@A-And A-And force-pushed the ILCompilerPackageSupport branch from aec5771 to 746cfeb Compare December 1, 2017 18:54
@mikedn
Copy link
Contributor

mikedn commented Dec 1, 2017

FWIW I gave the package (1.0.0-alpha-25930-03, from yesterday) a try and it seems to be working fine, a native executable is produced. There are a number of linker warnings like:

bootstrapper.lib(main.obj) : warning LNK4099: PDB 'bootstrapper.pdb' was not found with 'bootstrapper.lib(main.obj)' or at 'D:\Projects\cda\bin\x64\Release\netcoreapp2.0\win-x64\native\bootstrapper.pdb'; linking object as if no debug info [D:\Projects\cda\cda.csproj]
Runtime.lib(MiscHelpers.obj) : warning LNK4099: PDB 'Runtime.pdb' was not found with 'Runtime.lib(MiscHelpers.obj)' or at 'D:\Projects\cda\bin\x64\Release\netcoreapp2.0\win-x64\native\Runtime.pdb'; linking object as if no debug info [D:\Projects\cda\cda.csproj]

Presumably the .pdb files for native static libraries like runtime.lib should be included in the package as well. The same way that VC++ installs both .lib and .pdb files for its static runtime libraries.

@A-And
Copy link
Contributor Author

A-And commented Dec 1, 2017

@mikedn Thanks for testing it out! The motivation behind excluding them was to keep the package as minimal as possible, but we should avoid linker warnings if possible.

<NativeIntermediateOutputPath Condition="'$(NativeIntermediateOutputPath)' == ''">$(IntermediateOutputPath)native\</NativeIntermediateOutputPath>
<NativeOutputPath Condition="'$(NativeOutputPath)' == ''">$(OutputPath)native\</NativeOutputPath>
<NativeCompilationDuringPublish Condition="'$(NativeCompilationDuringPublish)' == ''">true</NativeCompilationDuringPublish>
<!-- Workaround for lack of current host OS detection - https://github.com/Microsoft/msbuild/issues/539 -->
Copy link
Member

Choose a reason for hiding this comment

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

BTW: This issue was fixed - can this be changed to use [MSBuild]::IsOSPlatform() now?

@sergiy-k
Copy link
Contributor

sergiy-k commented Dec 1, 2017

@A-And, there should be no warning while compiling an app (i.e. the ones that @mikedn mentioned). We should either ship the pdb files or disable the warnings in the target files with a comment. But this should not block merging your PR. It can be done as a separate change. Thank you!

<TargetOS Condition="'$(TargetOS)' == '' and '$(OS)' == 'Unix' and Exists('/Applications')">OSX</TargetOS>
<TargetOS Condition="'$(TargetOS)' == '' and '[MSBuild]::IsOSPlatform('OSX')">OSX</TargetOS>
<TargetOS Condition="'$(TargetOS)' == ''">$(OS)</TargetOS>
<!-- Detect whether we're running the ILCompiler from a package and if so override the environmental variable to point to the correct assemblies -->
Copy link
Member

Choose a reason for hiding this comment

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

Reposting https://github.com/dotnet/corert/pull/4983/files/746cfebb4cd9c19f9a7fd7e87c8f3e65c3ee196f..de7a9432439e46dbcbe65677dbf2267b6f44082c#r154461423 to make sure you have seen it:

Can this be just something like $(MSBuildThisFileDirectory)/.. , and remove the Error below?

@A-And A-And force-pushed the ILCompilerPackageSupport branch 2 times, most recently from 5707e82 to 64cb37d Compare December 2, 2017 01:06
@A-And
Copy link
Contributor Author

A-And commented Dec 2, 2017

@sergiy-k I've manually added the debug symbols for static libraries for now. All .pdbs are already published as part of the nuget symbol package, so we have to consider how a user debugging scenario should work.

<NativeOutputPath Condition="'$(NativeOutputPath)' == ''">$(OutputPath)native\</NativeOutputPath>
<NativeCompilationDuringPublish Condition="'$(NativeCompilationDuringPublish)' == ''">true</NativeCompilationDuringPublish>
<!-- Workaround for lack of current host OS detection - https://github.com/Microsoft/msbuild/issues/539 -->
<TargetOS Condition="'$(TargetOS)' == '' and '$(OS)' == 'Unix' and Exists('/Applications')">OSX</TargetOS>
Copy link
Member

Choose a reason for hiding this comment

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

I am sorry for not being clear ... I mean to replace this line with the one that is using `[MSBuild]::IsOSPlatform. I suspect that this is why the CI tests on OSX are failing.


<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(NativeObject)))" />

Copy link
Member

Choose a reason for hiding this comment

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

Nit: extra whitespace

@mikedn
Copy link
Contributor

mikedn commented Dec 2, 2017

All .pdbs are already published as part of the nuget symbol package

Hmm, it's unlikely that static library .pdbs need to be published, normally the debugger does not look for them, only the linker.

Those static .pdbs might be needed during debugging if the /DEBUG:FASTLINK linker option is used and ILC probably doesn't do that.

And even if it does, this is something that's supposed to work on the developer's machine, where static .pdbs already exist. In "release" scenarios, the .pdb produced by ILC should be a standalone .pdb. The debugger using it is not supposed to need static library .pdbs, .objs or any other intermediate build files.

@A-And A-And force-pushed the ILCompilerPackageSupport branch 3 times, most recently from 3d2605b to 296f798 Compare December 4, 2017 19:05
@jkotas
Copy link
Member

jkotas commented Dec 4, 2017

Sigh, the Windows build is failing with Method '[MSBuild]::IsOSPlatform' not found. Static method invocation should be of the form. The CI machines are not upgraded to latest VS/msbuild yet, and so we cannot remove the workaround.

Could you please keep the workaround in place? (Keep the new proper OS detection code around commented out.)

@A-And A-And force-pushed the ILCompilerPackageSupport branch from 296f798 to baff080 Compare December 4, 2017 21:42
@A-And
Copy link
Contributor Author

A-And commented Dec 4, 2017

@jkotas Thanks for confirming, will do.

@A-And A-And force-pushed the ILCompilerPackageSupport branch 2 times, most recently from b33ad2c to c0f7aea Compare December 4, 2017 21:56
@A-And A-And force-pushed the ILCompilerPackageSupport branch from c0f7aea to 3456f13 Compare December 4, 2017 22:40
@jkotas jkotas merged commit a35d222 into dotnet:master Dec 5, 2017
@A-And A-And mentioned this pull request Dec 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants