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

Add tests for disabling JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true #33757

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis self-assigned this Jul 3, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-ILLink untriaged Request triage from a team member labels Jul 3, 2023
@eerhardt
Copy link
Member

eerhardt commented Jul 5, 2023

The current feature switches that get set when PublishTrimmed=true is actually contained in dotnet/runtime:

https://github.com/dotnet/runtime/blob/d52b3038cd19aab5b95be4f1c76010b91dd07429/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets#L34-L47

Thoughts on putting this one there instead to keep them all in one place?

I think the reason they are in dotnet/runtime is because they version with the runtime version. So if you target net7.0, you get a different set than if you target net8.0.

cc @sbomer @vitek-karas

@eiriktsarpalis
Copy link
Member Author

Does Microsoft.NET.ILLink.targets get included when you run build targets?

@sbomer
Copy link
Member

sbomer commented Jul 5, 2023

Yes - the import is here:

<Import Project="$(ILLinkTargetsPath)" Condition="'$(ILLinkTargetsPath)' != '' and '$(Language)' != 'C++'" />

@eiriktsarpalis
Copy link
Member Author

eiriktsarpalis commented Jul 5, 2023

One more question -- can we set up testing in runtime or should I just make the change there and merge this PR once the sdk repo has absorbed the changes?

@eiriktsarpalis
Copy link
Member Author

Given dotnet/runtime#88480 was merged I've updated this PR to only include the tests. Will merge once an up-to-date built is absorbed and tests are passing.

@eiriktsarpalis eiriktsarpalis changed the title Disable JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true Add tests for disabling JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true Jul 7, 2023
@eerhardt
Copy link
Member

eerhardt commented Jul 7, 2023

Can you remove this line as part of this change?

<!-- Default settings for trimmed and aot'd apps. -->
<PropertyGroup Condition="'$(PublishTrimmed)' == 'true' Or '$(PublishAot)' == 'true'">
<JsonSerializerIsReflectionEnabledByDefault Condition="'$(JsonSerializerIsReflectionEnabledByDefault)' == ''">false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

@eiriktsarpalis
Copy link
Member Author

I could -- just to confirm, is it guaranteed PublishAot == true always implies PublishTrimmed == true?

@eerhardt
Copy link
Member

eerhardt commented Jul 7, 2023

I could -- just to confirm, is it guaranteed PublishAot == true always implies PublishTrimmed == true?

Currently, yes I believe this is true. @MichalStrehovsky and @agocke can confirm. If we ever change that, we would change all the feature switches we default when PublishTrimmed=true to also check for PublishAot.

@vitek-karas
Copy link
Member

I could -- just to confirm, is it guaranteed PublishAot == true always implies PublishTrimmed == true

Currently it probably is... but please don't rely on it. We're discussing setting PublishAot=true even on mono AOTed apps, and I think mono has some cases where it can do AOT without trimming, in which case it should probably not set PublishTrimmed=true. Regardless, you should not make that assumption anyway. If the feature is incompatible with trimming (for example has RequiresUnreferencedCode somewhere) and independently also incompatible with AOT (for example has RequiresDynamicCode somewhere) then you should condition it on both.

@eiriktsarpalis
Copy link
Member Author

@vitek-karas this suggests to me that we should update Microsoft.NET.ILLink.targets in runtime to also condition the feature switch on PublishAot == true. @eerhardt thoughts?

@eiriktsarpalis eiriktsarpalis force-pushed the publishtrimmed-implies-disabledreflection branch from 3b9543b to d2c1d1f Compare July 10, 2023 11:55
@vitek-karas
Copy link
Member

I think the answer is "yes it should be", but the question is where. Currently the ILLink targets only handle trimming. We have a different set of targets for AOT. So maybe this should also be in the AOT targets as well. It would then probably also belong here: https://github.com/dotnet/runtime/blob/36481bfd079093fe7d29ef024b1fb801e6c787fe/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets#L36C7-L42
@MichalStrehovsky ?

@eerhardt
Copy link
Member

I'm fine with defaulting JsonSerializerIsReflectionEnabledByDefault to false for both PublishTrimmed and PublishAot. This switch affects both trimming and AOT - it guards code that is both RequiresUnreferencedCode and RequiresDynamicCode.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM

@eiriktsarpalis eiriktsarpalis merged commit 342078a into dotnet:main Jul 10, 2023
@eiriktsarpalis eiriktsarpalis deleted the publishtrimmed-implies-disabledreflection branch July 10, 2023 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-ILLink untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable JsonSerializer.IsReflectionEnabledByDefault on PublishTrimmed=true
4 participants