Skip to content

Use correct CoreLib configuration for shared framework linker trimming #45821

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

Merged
merged 5 commits into from
Jan 25, 2021

Conversation

layomia
Copy link
Contributor

@layomia layomia commented Dec 9, 2020

From #45821 (comment):

GetTargetPath is returning the path to CoreLib based on the libraries configuration (-lc), rather than the runtime configuration (-rc). This means that when we do a build such as build -s clr+libs -rc Release, we are passing Debug libraries and Debug CoreLib, rather than Debug libraries and Release CoreLib to the linker which is not expected.

@ghost
Copy link

ghost commented Dec 9, 2020

Tagging subscribers to this area: @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

Issue Details
Author: layomia
Assignees: layomia
Labels:

area-Infrastructure-libraries

Milestone: -

@ViktorHofer
Copy link
Member

Curious, why does the GetTargetPath target not work for you? What are you trying to solve with this PR?

@layomia
Copy link
Contributor Author

layomia commented Dec 9, 2020

@ViktorHofer - GetTargetPath is returning the path to CoreLib based on the libraries configuration (-lc), rather than the runtime configuration (-rc). This means that when we do a build such as build -s clr+libs -rc Release, we are passing Debug libraries and Debug CoreLib, rather than Debug libraries and Release CoreLib to the linker which is not expected.

Any thoughts on how we could flow the RuntimeConfiguration prop to GetTargetPath, or thoughts on the current approach using CoreCLRArtifactsPath?

cc @eerhardt, @joperezr

@ViktorHofer
Copy link
Member

ViktorHofer commented Dec 9, 2020

Yes, you could do something similar to what we do for the ProjectReference to CoreLib:

<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>

@ViktorHofer
Copy link
Member

You can pass in the "Properties" and "RemoveProperties" properties to the MSBuild task: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-task?view=vs-2019

Pass in $(RuntimeConfiguration) as the value of configuration in the Properties property and just to be on the safe side, remove the Platform and TargetFramework properties.

@ViktorHofer
Copy link
Member

This is a point in time problem until we start binplacing CoreLib...

@layomia
Copy link
Contributor Author

layomia commented Dec 9, 2020

This is a point in time problem until we start binplacing CoreLib...

Yup, #40172 (comment).

@layomia
Copy link
Contributor Author

layomia commented Dec 9, 2020

You can pass in the "Properties" and "RemoveProperties" properties to the MSBuild task: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-task?view=vs-2019

Pass in $(RuntimeConfiguration) as the value of configuration in the Properties property and just to be on the safe side, remove the Platform and TargetFramework properties.

Thanks, trying this out now. What problem do we avoid by removing the Platform and TargetFramework properties?

@layomia layomia marked this pull request as ready for review December 9, 2020 16:24
@ViktorHofer
Copy link
Member

What problem do we avoid by removing the Platform and TargetFramework properties?

We do this for performance as msbuild caches project evaluations based on the global properties passed in. Doing this here might reduce an unnecessary project evaluation of CoreLib by using the same global properties as for the ProjectReference to CoreLib.

<MSBuild Projects="$(CoreLibProject)"
Properties="Configuration=$(RuntimeConfiguration)"
Copy link
Member

Choose a reason for hiding this comment

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

With this, the Configuration property is always passed in as a global property even if the RuntimeConfiguration already matches the current (libraries) configuration. We should keep this in sync with how we set global properties for the ProjectReference to CoreLib.

Copy link
Member

@ViktorHofer ViktorHofer Dec 9, 2020

Choose a reason for hiding this comment

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

add this to a new line before L38.

         <Properties Condition="'$(RuntimeFlavor)' == 'CoreCLR' and 
                                '$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</Properties> 
         <Properties Condition="'$(RuntimeFlavor)' == 'Mono' and 
                                '$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</Properties> 

@ericstj
Copy link
Member

ericstj commented Jan 22, 2021

@layomia @eerhardt @joperezr is this PR still relevant?

@layomia
Copy link
Contributor Author

layomia commented Jan 22, 2021

@ericsj - I believe so. IIRC @eerhardt had a work around locally for the issue, but we need a proper fix checked in for correctness. I'll go ahead and drive this in.

@eerhardt
Copy link
Member

IIRC @eerhardt had a work around locally for the issue

Yes, my workaround was to build a Debug CoreLib.

This is what gets passed to the linker today with dotnet build .\src\libraries\src.proj /t:ILLinkTrimSharedFramework /p:BuildingNetCoreAppVertical=true /p:RuntimeConfiguration=Release. Note the CoreLib path is to Debug even though I said /p:RuntimeConfiguration=Release.
image

@ericstj
Copy link
Member

ericstj commented Jan 22, 2021

I see, I wasn't sure if we had passed this point in time :)

This is a point in time problem until we start binplacing CoreLib...

Can you either close this PR and file an issue, or address @ViktorHofer's feedback and merge?

@layomia
Copy link
Contributor Author

layomia commented Jan 22, 2021

I'll address the feedback and merge, since it's a small effort at this point.

<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
<!-- If conflicting, manually set the Configuration property of the CoreLib project so that it aligns with the specified RuntimeConfiguration in the libraries' build. -->
<Properties Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</Properties>
Copy link
Member

Choose a reason for hiding this comment

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

Just a question, mostly for @ViktorHofer. Why do we have both $(CoreCLRConfiguration) and $(MonoConfiguration)? Why not just have $(RuntimeConfiguration)? Do we expect to be able to build the repo using different configurations for coreclr and mono?

Copy link
Member

Choose a reason for hiding this comment

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

There is a RuntimeConfiguration property but in this case we can't use that as we need to respect the inferred CoreCLRConfiguration and MonoConfiguration properties.

Do we expect to be able to build the repo using different configurations for coreclr and mono?

Yes

@layomia layomia force-pushed the CorrectCoreLibConfig branch from b05b83a to c59fc16 Compare January 25, 2021 17:40
@layomia
Copy link
Contributor Author

layomia commented Jan 25, 2021

CI failures are unrelated - dup of #47374.

@layomia layomia merged commit 5415849 into dotnet:master Jan 25, 2021
@layomia layomia deleted the CorrectCoreLibConfig branch January 25, 2021 21:10
@ghost ghost locked as resolved and limited conversation to collaborators Feb 24, 2021
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.

5 participants