-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from joperezr/Utf8String-ingestion
Dotnet runtime master ingestion into Utf8String experiment
- Loading branch information
Showing
1,175 changed files
with
97,677 additions
and
11,926 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Libraries Feature Switches | ||
|
||
Starting with .NET 5 there are several [feature-switches](https://github.com/dotnet/designs/blob/master/accepted/2020/feature-switch.md) available which | ||
can be used to control the size of the final binary. They are available in all | ||
configurations but their defaults might vary as any SDK can set the defaults differently. | ||
|
||
## Available Feature Switches | ||
|
||
| MSBuild Property Name | AppContext Setting | Description | | ||
|-|-|-| | ||
| DebuggerSupport | System.Diagnostics.Debugger.IsSupported | Any dependency that enables better debugging experience to be trimmed when set to false | | ||
| EnableUnsafeUTF7Encoding | System.Text.Encoding.EnableUnsafeUTF7Encoding | Insecure UTF-7 encoding is trimmed when set to false | | ||
| EnableUnsafeBinaryFormatterSerialization | System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization | BinaryFormatter serialization support is trimmed when set to false | | ||
| EventSourceSupport | System.Diagnostics.Tracing.EventSource.IsSupported | Any EventSource related code or logic is trimmed when set to false | | ||
| InvariantGlobalization | System.Globalization.Invariant | All globalization specific code and data is trimmed when set to true | | ||
| UseSystemResourceKeys | System.Resources.UseSystemResourceKeys | Any localizable resources for system assemblies is trimmed when set to true | | ||
| - | System.Net.Http.EnableActivityPropagation | Any dependency related to diagnostics support for System.Net.Http is trimmed when set to false | | ||
|
||
Any feature-switch which defines property can be set in csproj file or | ||
on the command line as any other MSBuild property. Those without predefined property name | ||
the value can be set with following XML tag in csproj file. | ||
|
||
```xml | ||
<RuntimeHostConfigurationOption Include="<AppContext-Setting>" | ||
Value="false" | ||
Trim="true" /> | ||
``` | ||
|
||
## Adding New Feature Switch | ||
|
||
The primary goal of features switches is to produce smaller output by removing code which is | ||
unreachable under feature condition. The typical approach is to introduce static bool like | ||
property which is used to guard the dependencies which can be trimmed when the value is flipped. | ||
Ideally, the static property should be located in type which does not have any static constructor | ||
logic. Once you are done with the code changes following steps connects the code with trimming | ||
settings. | ||
|
||
Add XML settings for the features switch to assembly substitution. It's usually located in | ||
`src/ILLink/ILLink.Substitutions.xml` file for each library. The example of the syntax used to control | ||
`EnableUnsafeUTF7Encoding` property is following. | ||
|
||
```xml | ||
<method signature="System.Boolean get_EnableUnsafeUTF7Encoding()" body="stub" value="false" feature="System.Text.Encoding.EnableUnsafeUTF7Encoding" featurevalue="false" /> | ||
``` | ||
|
||
Add MSBuild integration by adding new RuntimeHostConfigurationOption entry. The file is located in | ||
[Microsoft.NET.Sdk.targets](https://github.com/dotnet/sdk/blob/33ce6234e6bf45bce16f610c441679252d309189/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L348-L401) file and includes all | ||
other public feature-switches. You can add a new one by simply adding a new XML tag | ||
|
||
```xml | ||
<RuntimeHostConfigurationOption Include="<AppContext-Setting>" | ||
Condition="'$(<msbuild-property-name>)' != ''" | ||
Value="$(<msbuild-property-name>)" | ||
Trim="true" /> | ||
``` | ||
|
||
Please don't forget to update the table with available features-switches when you are done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.