Skip to content

Conversation

agocke
Copy link
Contributor

@agocke agocke commented Jun 17, 2022

Most of serilog is trim-compatible. The main incompatibility is
configuration settings which scan assemblies at run time.
Serilog.Settings.Configuration is the more difficult challenge.

@nblumhardt
Copy link
Member

Thanks @agocke!

To get the build green with these changes, the worker image in AppVeyor.yml will need to be updated to VS2022 (IIRC).

@nblumhardt
Copy link
Member

dev now includes a .NET 6 target so fingers crossed this will all come together 🤞

@agocke
Copy link
Contributor Author

agocke commented Jul 27, 2022

Thanks! Looks like there have been a few changes between when I originally wrote this and now, so it needs a little fixup. I'll move to draft until I can address the last remaining warnings.

@agocke agocke marked this pull request as draft July 27, 2022 21:21
@SimonCropp
Copy link
Contributor

@agocke

i pulled the ITuple parts of this into the main line.

would you mind rebasing

Could you also add a sample app that consumes serilog and uses trimming. So we can smoke test the changes

@agocke
Copy link
Contributor Author

agocke commented Oct 14, 2022

@SimonCropp All updated. Happy to add a sample. Where would you like it? FYI, there should be some correctness assurance via the PublishTrimmed property. That enables the analyzer in .NET 6+, which checks that there aren't any trim warnings. It's much more accurate in .NET 7, so I would recommend building with a .NET 7 SDK version once that releases.

@agocke agocke marked this pull request as ready for review October 14, 2022 22:10
@nblumhardt
Copy link
Member

Great! It looks like there are still some problems to resolve -

C:\projects\serilog\src\Serilog\Settings\KeyValuePairs\SettingValueConversions.cs(33,20): error IL2026: Using member 'System.Type.GetType(string, bool)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [C:\projects\serilog\src\Serilog\Serilog.csproj]
C:\projects\serilog\src\Serilog\Settings\KeyValuePairs\KeyValuePairSettings.cs(95,17): error IL2046: Interface member 'Serilog.Configuration.ILoggerSettings.Configure(Serilog.LoggerConfiguration)' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Serilog.Settings.KeyValuePairs.KeyValuePairSettings.Configure(Serilog.LoggerConfiguration)' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. [C:\projects\serilog\src\Serilog\Serilog.csproj]
C:\projects\serilog\src\Serilog\Settings\KeyValuePairs\SettingValueConversions.cs(33,20): error IL2026: Using member 'System.Type.GetType(string, bool)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [C:\projects\serilog\src\Serilog\Serilog.csproj]
    0 Warning(s)
    3 Error(s)

(From the failed CI build)

@agocke
Copy link
Contributor Author

agocke commented Nov 6, 2022

@nblumhardt Thanks, sorry for the delay, took a little digging to track this down.

The remaining errors appear to be caused by a bug and an unimplemented feature, both of which were fixed in the .NET 7 SDK. Unfortunately, those fixes don't apply in your build because you're using the .NET 6 SDK (and even if you built using .NET 7, your global.json forces the 6.0 version).

I'm not sure what your preferred fix is. I could introduce some hacks, but using the 7.0 SDK seems more reliable.

@SimonCropp
Copy link
Contributor

given 7.0 SDK should be out this week, i dont think hacks to work with 6sdk will be necessary

@agocke
Copy link
Contributor Author

agocke commented Dec 14, 2022

Looks like appveyor Ubuntu is missing .net 7. Not sure if there’s a way to speed that up, or if we just need to wait for them to update.

@agocke
Copy link
Contributor Author

agocke commented Jan 31, 2023

It's been a couple months and I still don't see any updates for Ubuntu .NET. It would be good to know if they have plans to install 7.0, or if they stick on 6.0.

@sungam3r
Copy link
Contributor

@nblumhardt @SimonCropp What do you think about switching from Appveyor to GitHub Actions? I got the impression that GitHub Actions has richer tuning possible and evolves faster.

@sungam3r
Copy link
Contributor

Could you also add a sample app that consumes serilog and uses trimming. So we can smoke test the changes

I suggest to include "smoke test" directly into ci pipeline like it was done here https://github.com/graphql-dotnet/graphql-dotnet/blob/master/.github/workflows/test-code.yml#L74-L83, PR - graphql-dotnet/graphql-dotnet#3506

@sungam3r
Copy link
Contributor

Another suggestion - use PolySharp as was done here https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/Directory.Build.props#L29 . PolySharp allows to get rid of annoying ifdefs scuttered across the codebase.

@agocke
Copy link
Contributor Author

agocke commented Jan 31, 2023

I think I managed to add an apt install command that works. Now things are failing because I think I made 8+ element tuples work on net5+ and there's a test that says they shouldn't 😄

@@ -28,19 +30,19 @@
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<DefineConstants>$(DefineConstants);FEATURE_DEFAULT_INTERFACE;FEATURE_SPAN;FEATURE_ASYNCDISPOSABLE;FEATURE_DICTIONARYTRYADD</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_DEFAULT_INTERFACE;FEATURE_SPAN;FEATURE_ITUPLE;FEATURE_ASYNCDISPOSABLE;FEATURE_DICTIONARYTRYADD</DefineConstants>
Copy link
Contributor

Choose a reason for hiding this comment

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

FEATURE_ITUPLE is not needed anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should I use instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing, this is merge artifact.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's correct; there's still a reference to it in PropertyValueConverter, and the CSPROJ targets .NET 4.6 where it's unsupported.

https://github.com/serilog/serilog/blob/dev/src/Serilog/Capturing/PropertyValueConverter.cs#L249

Still some work to do once we've finalized framework version support.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I confused it with another feature.

appveyor.yml Outdated
@@ -4,6 +4,8 @@ image:
- Visual Studio 2022
- Ubuntu
configuration: Release
install:
- sh: sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0
Copy link
Contributor

Choose a reason for hiding this comment

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

NET7 was configured in #1806

@SimonCropp
Copy link
Contributor

we have net7 installing and running on linux on the main branch. what am i missing?

@agocke
Copy link
Contributor Author

agocke commented Feb 1, 2023

I think I just missed that -- I have to fix up the tests but that may be it.

@nblumhardt
Copy link
Member

nblumhardt commented Feb 3, 2023

This one's now been open a long time; I think there's still more to explore (could we just polyfill DynamicallyAccessedMembers for downlevel targets? Some unnecessary feature constants, etc.) but let's get the code through the pipeline as-is and iterate from dev. I'll have a hack at the failing test, and merge if I can sort it out :-)

Thanks @agocke!

@nblumhardt nblumhardt merged commit 7604c1d into serilog:dev Feb 3, 2023
@sungam3r
Copy link
Contributor

sungam3r commented Feb 3, 2023

could we just polyfill DynamicallyAccessedMembers for downlevel targets?

PolySharp does this

@sungam3r sungam3r mentioned this pull request Feb 3, 2023
@agocke agocke deleted the trimmable branch February 4, 2023 01:01
@nblumhardt nblumhardt mentioned this pull request Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants