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

[release/6.0] Add reference assembly for System.Private.CoreLib.dll #75311

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

akoeplinger
Copy link
Member

@akoeplinger akoeplinger commented Sep 8, 2022

Backport of #72143 to release/6.0

We now compile against the reference assembly in all places where we were compiling against the mono/coreclr System.Private.CoreLib.dll implementation assembly before.

The new reference assembly consumes sources from the existing contracts to avoid checking in a generated version of SPC.dll (this would add ~20k lines of .cs which is mostly duplicated with System.Runtime.cs)

Since a few contracts have only partially moved types to SPC we wrap contract types with #if !BUILDING_CORELIB_REFERENCE so we can hide them when compiling the SPC reference assembly.

NOTE: to simplify the change for the 6.0 backport this does not include the GenAPI et.al. changes for regenerating the reference assembly sources since we won't be adding new APIs in 6.0.

Customer Impact

Fixes an issue where Xamarin.Android puts duplicate assemblies into the .apk because the MVID-based deduplication logic didn't work anymore due to an ILLinker fix which increased the app size a lot. This is necessary for 6.0 because the 7.0 SDK includes a new ILLinker which is used even when building a 6.0 app.

Risk

Low, it is a build-related change that should be transparent outside of dotnet/runtime.

Testing

Manual testing confirmed it fixes the issue.

We now compile against the reference assembly in all places where we were compiling against the mono/coreclr System.Private.CoreLib.dll implementation assembly before.

The new reference assembly consumes sources from the existing contracts to avoid checking in a generated version of SPC.dll (this would add ~20k lines of .cs which is mostly duplicated with System.Runtime.cs)

Since a few contracts have only partially moved types to SPC we wrap contract types with `#if !BUILDING_CORELIB_REFERENCE` so we can hide them when compiling the SPC reference assembly.
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned akoeplinger Sep 8, 2022
@ghost
Copy link

ghost commented Sep 8, 2022

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #72143 to release/6.0

We now compile against the reference assembly in all places where we were compiling against the mono/coreclr System.Private.CoreLib.dll implementation assembly before.

The new reference assembly consumes sources from the existing contracts to avoid checking in a generated version of SPC.dll (this would add ~20k lines of .cs which is mostly duplicated with System.Runtime.cs)

Since a few contracts have only partially moved types to SPC we wrap contract types with #if !BUILDING_CORELIB_REFERENCE so we can hide them when compiling the SPC reference assembly.

Customer Impact

Fixes an issue where Xamarin.Android has duplicate assemblies.

Risk

TODO

Author: akoeplinger
Assignees: -
Labels:

area-Infrastructure-libraries, new-api-needs-documentation

Milestone: -

@akoeplinger akoeplinger marked this pull request as ready for review September 9, 2022 12:00
@akoeplinger
Copy link
Member Author

@marek-safar @steveisok

@akoeplinger akoeplinger added this to the 6.0.x milestone Sep 9, 2022
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Sep 9, 2022
Fixes: dotnet#7302
Context: dotnet/linker#2203
Context: dotnet/runtime#67660
Context: dotnet#6598

This partially backports 745214d.

In addition to this backport to dotnet/runtime/release/6.0:

dotnet/runtime#75311

We also have another change in .NET 7 that opts into
`$(TrimmerRemoveSymbols)` by default for `Release` builds. This allows
the .NET 7 linker to have stable MVIDs for assemblies for each
architecture.

There may potentially be a dotnet/linker issue here to look into
further. However, this seems to be the best fix for getting .NET 6
projects building under .NET 7 at the moment.
jonathanpeppers added a commit to dotnet/android that referenced this pull request Sep 9, 2022
Fixes: #7302
Context: dotnet/linker#2203
Context: dotnet/runtime#67660
Context: #6598

This partially backports 745214d.

Building a `net6.0-android` app in `Release` mode with .NET 7 can fail with many errors like:

    error XA4215: The Java type `androidx.activity.contextaware.OnContextAvailableListener` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.

This happens because we end up with multiple assemblies, such as:

    obj/Release/net6.0-android/android-arm/linked/Xamarin.AndroidX.Activity.dll
    obj/Release/net6.0-android/android-arm64/linked/Xamarin.AndroidX.Activity.dll
    obj/Release/net6.0-android/android-x64/linked/Xamarin.AndroidX.Activity.dll
    obj/Release/net6.0-android/android-x86/linked/Xamarin.AndroidX.Activity.dll

To fix this, in addition to this backport to dotnet/runtime/release/6.0:

dotnet/runtime#75311

In .NET 7 we opt into `$(TrimmerRemoveSymbols)` by default for `Release`
builds. This allows the .NET 7 linker to have stable MVIDs for assemblies
for each architecture. Somehow when the linker outputs `.pdb` files,
it creates different MVIDs per architecture.

There may potentially be a dotnet/linker issue here to look into
further. However, this seems to be the best fix for getting .NET 6
projects building under .NET 7 at the moment.
Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

@ViktorHofer gave your PR a like but not a sign-off 😄 . I'll sign-off. But just in case, @ericstj @lewing @steveisok would you mind also providing a review?

@marek-safar marek-safar added the Servicing-consider Issue for next servicing release review label Sep 12, 2022
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 13, 2022
@rbhanda rbhanda modified the milestones: 6.0.x, 6.0.10 Sep 13, 2022
@carlossanlop
Copy link
Member

@akoeplinger do you think the CI failure is related to this change? Happened on System.Runtime.InteropServices.NFloat.Internal.Tests

@steveisok
Copy link
Member

@akoeplinger do you think the CI failure is related to this change? Happened on System.Runtime.InteropServices.NFloat.Internal.Tests

No, it's unrelated. I believe they are disabled upstream and just didn't make it here.

@carlossanlop
Copy link
Member

Ok thanks. Let's get this merged then. :shipit:

@carlossanlop carlossanlop merged commit 7e31494 into dotnet:release/6.0 Sep 13, 2022
@akoeplinger akoeplinger deleted the corelib-refasm-6.0 branch September 27, 2022 15:22
@ghost ghost locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants