-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Dipping toes into linker friendliness #24458
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To properly certify asp.net core as linker friendly I think we need functional tests that run with linking enabled. This seems like an easy thing to unknowingly regress.
/// <summary> | ||
/// Configure the connection to host the specified <see cref="Hub"/> type. | ||
/// </summary> | ||
/// <typeparam name="THub">The <see cref="Hub"/> type to host on the connection.</typeparam> | ||
/// <param name="connectionBuilder">The connection to configure.</param> | ||
/// <returns>The same instance of the <see cref="IConnectionBuilder"/> for chaining.</returns> | ||
public static IConnectionBuilder UseHub<THub>(this IConnectionBuilder connectionBuilder) where THub : Hub | ||
public static IConnectionBuilder UseHub<[DynamicallyAccessedMembers(HubAccessibility)]THub>(this IConnectionBuilder connectionBuilder) where THub : Hub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this should be done in gRPC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 things:
This doesn't change any defaults but it allows us to make progress in understanding how to make the framework more linkable. |
UseMiddleware is the most critical because we use it on our own components. The rest is user code which we would probably avoid trimming by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good to me. Nice work.
Do you plan on having tests or analysis turned on in your build to ensure these don't get broken in the future?
@eerhardt trying to decide if I should add a single test in our end to end tests that already publish bits instead of an individual tests. |
In a perfect world - I'd think both. But if you are choosing one, I'd choose end to end. |
- The linker.xml preserves constructors all of the types that are registered in DI. This should be removed once we get the linker friendly DI changes.
OK added a test. It uses a Linker.xml file to keep constructors of types in DI. Most of this file should be gone once we get dotnet/runtime#40227. The last thing looks like options dotnet/runtime#40236. |
- Add Restore option to DeploymentParameters
@davidfowl it might be useful to enable linker warnings which would print if there are more cases to be fixed |
For library authors (like ASP.NET here - and any library in dotnet/runtime that isn't part of the runtimepack) it would be useful to have an official linker option that runs the analysis/warnings on the whole library using the public surface area as the roots (like That way library authors can easily tell which parts of their library aren't linker safe, and need to be fixed. |
I'll submit a follow up PR with any remaining warnings. I really want to try this with @eerhardt 's DI changes to see how close we are to no annotations. |
@@ -38,7 +38,7 @@ public virtual Task<PublishedApplication> Publish(DeploymentParameters deploymen | |||
// avoids triggering builds of dependencies of the test app which could cause issues like https://github.com/dotnet/arcade/issues/2941 | |||
+ $" --no-dependencies" | |||
+ $" /p:TargetArchitecture={deploymentParameters.RuntimeArchitecture}" | |||
+ " --no-restore"; | |||
+ (deploymentParameters.RestoreDependencies ? "" : " --no-restore"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall no-restore is required for all tests on Helix because the test assets need to be pre-built before publishing to helix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works fine on helix as far as I could tell.
- Annotated UseMiddleware and UseStartup to preserve constructors and public methods. - Annotated UseHub and MapHub preserve constructors and public methods. - Added a test to verify UseStartup and UseMiddleware works - The linker.xml preserves constructors all of the types that are registered in DI. This should be removed once we get the linker friendly DI changes.
Experimenting with linker friendliness in ASP.NET Core. This investigation did lead to a single API change around the new overload of UseStartup that takes a func (it was changed a generic).
Here's an example of what this looks like today in aggressive mode https://github.com/rynowak/link-a-thon/blob/master/src/ApiTemplate/Linker.xml