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

Support feature conditions on XML descriptors #1268

Closed
sbomer opened this issue Jun 11, 2020 · 5 comments · Fixed by #1277
Closed

Support feature conditions on XML descriptors #1268

sbomer opened this issue Jun 11, 2020 · 5 comments · Fixed by #1277
Assignees
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Jun 11, 2020

This would allow us to use the embedded ILLink.Descriptors.xml to root "global" dependencies for which we don't have a great place to put DynamicDependencyAttribute, while allowing them to be linked out using feature settings. From discussion with @vitek-karas, it sounds like this will be useful for removing debugger support, COM, etc.

@marek-safar what do you think of this?

@vitek-karas
Copy link
Member

I'm all for doing this 😄

@vitek-karas vitek-karas added this to the .NET5.0 milestone Jun 12, 2020
@vitek-karas
Copy link
Member

/cc @eerhardt

@marek-safar
Copy link
Contributor

I agree that this would be a useful extension of XML descriptors.

@eerhardt
Copy link
Member

If we take this approach, we should be able to close dotnet/runtime#37352, right?

The motivation behind dotnet/runtime#37352 was being able to "root" types globally, but also conditionally. See the discussion here: dotnet/runtime#37288 (comment).

So if there are scenarios where we need to preserve a type globally under certain conditions (Debug, COM, JS, etc), we can use the XML descriptor + feature switch mechanism, instead of putting a [DynamicDependency("foo", Condition = "feature switch")].

Note that the advantage of having [DynamicDependency] on the Type vs having a global XML descriptor, is that the global XML descriptor will keep the dependency even if the Type isn't being used. With the [DynamicDependency] on the Type approach, if the whole Type could be trimmed, so could its dependencies.

@marek-safar
Copy link
Contributor

So if there are scenarios where we need to preserve a type globally under certain conditions (Debug, COM, JS, etc), we can use the XML descriptor + feature switch mechanism, instead of putting a [DynamicDependency("foo", Condition = "feature switch")].

This scenario should be used only for cases where the source of the dependency is outside of src/libraries (e.g. external code, different runtime, etc) for anything else DynamicDependency is the preference

global XML descriptor will keep the dependency even if the Type isn't being used.

That's not true. See https://github.com/mono/linker/blob/master/docs/data-formats.md#preserve-a-type

sbomer added a commit to sbomer/linker that referenced this issue Jun 16, 2020
sbomer added a commit to sbomer/linker that referenced this issue Jun 16, 2020
sbomer added a commit to sbomer/linker that referenced this issue Jun 16, 2020
sbomer added a commit that referenced this issue Jun 23, 2020
* Support feature settings on descriptor files

Fixes #1268.

* Disable feature descriptors for mono

Since they conflict with the --exclude-feature "feature" attributes in
the descriptor XML.

* Revert "Disable feature descriptors for mono"

This reverts commit 78c2f52.

* Support featuredefault="true"

To indicate that a substitution or descriptor should be applied in the
absence of a feature setting. Note that this is restricted to still
require the featurevalue attribute, to prevent the definition of
default substitutions that are never applied for any feature settings.

Also address PR feedback:
- Move the feature checks into a separate class
- #ifdef an implementation instead of callsites

* Fix signatures in tests

* Update data format docs

* Fix whitespace

* PR feedback

Add comments about order of checking assemblyname and feature attributes,
and make processing consistent in LinkAttributesStep.

* Clarify featuredefault behavior in documentation
tkapin pushed a commit to tkapin/runtime that referenced this issue Jan 31, 2023
* Support feature settings on descriptor files

Fixes dotnet/linker#1268.

* Disable feature descriptors for mono

Since they conflict with the --exclude-feature "feature" attributes in
the descriptor XML.

* Revert "Disable feature descriptors for mono"

This reverts commit dotnet/linker@78c2f52.

* Support featuredefault="true"

To indicate that a substitution or descriptor should be applied in the
absence of a feature setting. Note that this is restricted to still
require the featurevalue attribute, to prevent the definition of
default substitutions that are never applied for any feature settings.

Also address PR feedback:
- Move the feature checks into a separate class
- #ifdef an implementation instead of callsites

* Fix signatures in tests

* Update data format docs

* Fix whitespace

* PR feedback

Add comments about order of checking assemblyname and feature attributes,
and make processing consistent in LinkAttributesStep.

* Clarify featuredefault behavior in documentation

Commit migrated from dotnet/linker@f87cfa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants