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

Enable running libraries tests with crossgen2 compiled runtime #34365

Closed

Conversation

janvorli
Copy link
Member

@janvorli janvorli commented Apr 1, 2020

This change adds support for precompiling testhost assemblies
for libraries tests with crossgen2. The msbuild property Crossgen2Host
is used to enable that (passing /p:Crossgen2Host=true to the build command)

This change adds support for precompiling testhost assemblies with
crossgen2. The msbuild property Crossgen2Host is used to enable
that (passing /p:Crossgen2Host=true to the build command)
@janvorli janvorli added this to the 5.0 milestone Apr 1, 2020
@janvorli janvorli self-assigned this Apr 1, 2020
</ItemGroup>

<Move SourceFiles="@(FilesToCopy)" DestinationFolder="$(TestHostRuntimePath)" />
<RemoveDir Directories="$(TestHostRuntimePath)\crossgen2out" />
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the same name that we used for System.Private.CoreLib which is/was native to store the crossgend assemblies. Also should we backup the IL version inside an IL folder and allow to get back to the IL state? Ie coverage measurement doesn't work with the crossgend assemblies and getting back to the non-crossgend state without rebuilding libraries would be desirable.

What about building crossgend without replacing the IL ones and allow to run on both modes with the switch? cc @ericstj

Copy link
Member Author

Choose a reason for hiding this comment

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

We actually do the same thing in coreclr build-test.cmd - we just overwrite the assemblies in Core_Root with their crossgened versions and don't save anything. I think that keeping them in a different folder would be quite difficult as I think it would require to make a copy of the whole testhost folder and then changing all the references to the testhost in our scripts to this new one.

We could possibly keep the IL versions, but it seems it would be tricky to manage that. At the beginning of test run without the crossgened assemblies, we would need to check if the IL folder was present and copy stuff from it back. That could result in stale files being copied - consider the following sequence:

  • I build libraries with crossgening the testhost. That would create the IL folder with copies of the assemblies.
  • I make some changes to coreclr or libraries and rebuild them without crossgening. Now the testhost contains updated non-crossgened assemblies.
  • I execute the tests - we find that there is an IL folder and copy the files back, overwriting the new ones with the stale ones. We cannot use time stamp of the files to check that, because we don't know if the files in the testhost are the crossgened ones or new IL ones.

I guess that we can find a way to make it work, but I doubt it is worth the hassle. I doubt that the flow when someone would need to run with and without crossgen without rebuilding libraries in between is important.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so what's the overall plan here? Will we add scheduled runs that set the property to true to test with crossgend?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, that's what I would do once I fix the issues in crossgen2 that it has discovered.

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw, since the crossgen2out is just a temporary folder that's deleted after the crossgen completes, would you still want to rename it to native? I don't really care about the name.

Copy link
Member

Choose a reason for hiding this comment

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

No if it's just temporary then it shouldn't matter. Thanks. If possible let's wait for ericstj's review.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, no need to rush.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is complex because you imagine modifying in place. It’s actually easier if you imagine crossgen producing a new shared framework with a different root (eg: testhost_crossgen vs testhost). Then it’s just a freshness check: is the non-CG newer? -> rerun crossgen. In general we try make the build consume immutable assets and produce new immutable assets. I’d prefer if we have a second folder.

@ViktorHofer ViktorHofer requested a review from ericstj April 1, 2020 11:28
Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

To me this looks good.

@janvorli
Copy link
Member Author

janvorli commented Apr 3, 2020

@ericstj can you please take a look? @ViktorHofer has asked me to wait for your review.

</ItemGroup>

<MakeDir Directories="$(TestHostRuntimePath)\crossgen2out" />
<Exec Command="$(TestHostRootPath)\dotnet $(TestHostRuntimePath)\crossgen2.dll %(FilesToCrossgen.FullPath) --targetarch=x64 -O --inputbubble -r:$(TestHostRuntimePath)\System.*.dll -r:$(TestHostRuntimePath)\Microsoft.*.dll -r:$(TestHostRuntimePath)\mscorlib.dll -r:$(TestHostRuntimePath)\netstandard.dll -o:$(TestHostRuntimePath)\crossgen2out\%(FilesToCrossgen.Filename)%(FilesToCrossgen.Extension)"
Copy link
Member

Choose a reason for hiding this comment

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

This is running on the shared framework that it is modifying at the same time. Typically we do not use the built product to perform build operations. Should you use the stable build framework under .dotnet instead?

This command line probably needs quotes around paths. Also, can crossgen2 just accept a folder for -r? Seems fragile to require named references when it could just probe for them. Probing seems simpler than resolving the wildcard in the app which it seems to be doing now.

<CoreCLRFiles Include="$(CoreCLRArtifactsPath)/crossgen2/*mscordaccore_*.*" />
<CoreCLRFiles Include="$(CoreCLRArtifactsPath)/crossgen2/*jitinterface.*" />
<CoreCLRFiles Include="$(CoreCLRArtifactsPath)/crossgen2/*clrjitilc.*" />
<ReferenceCopyLocalPaths Include="@(CoreCLRFiles)" />
Copy link
Member

Choose a reason for hiding this comment

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

Why copy this? Does it need to be in the test shared framework? I would prefer to move in the direction of making our test framework closer to the real thing rather than dump more test specific changes to it.

</ItemGroup>

<Move SourceFiles="@(FilesToCopy)" DestinationFolder="$(TestHostRuntimePath)" />
<RemoveDir Directories="$(TestHostRuntimePath)\crossgen2out" />
Copy link
Member

Choose a reason for hiding this comment

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

I think this is complex because you imagine modifying in place. It’s actually easier if you imagine crossgen producing a new shared framework with a different root (eg: testhost_crossgen vs testhost). Then it’s just a freshness check: is the non-CG newer? -> rerun crossgen. In general we try make the build consume immutable assets and produce new immutable assets. I’d prefer if we have a second folder.

@@ -68,11 +68,31 @@
ContinueOnError="ErrorAndContinue" />
</Target>

<Target Name="RunCrossgen2OnHost" Condition="'$(Crossgen2Host)' == 'true'">
Copy link
Member

Choose a reason for hiding this comment

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

Why Pretest and not a step in each libraries project file? This makes things harder on inner loop if you care about crossgen2.

Copy link
Member

Choose a reason for hiding this comment

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

With #31712, we are going to be illink trimming all the assemblies in the shared framework together in a "post build" step.

We can't crossgen in a step in each libraries project file because that will run before we run the linker. We will need to run crossgen on the output of the linker.

@janvorli janvorli marked this pull request as draft June 22, 2020 19:45
@davidwrighton
Copy link
Member

@janvorli Jan, are you planning to do work on this? If not, please consider closing the PR.

@janvorli janvorli closed this Oct 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants