forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One .NET] *.runtimeconfig.json support (dotnet#6009)
Context: https://github.com/dotnet/runtime/blob/d95bfea59ed7d19e9b1db096c9d332005989296b/docs/design/mono/mobile-runtimeconfig-json.md .NET allows including a [`runtimeconfig.json`][0] file in an application, which can be used to control runtime configuration options, provide "backing data" to [`AppContext.GetData()`][1], control configuration values, and more. Update the Xamarin.Android-for-.NET 6 build process to call the new [`<RuntimeConfigParser/>` task][2], which will process the `runtimeconfig.json` files into an efficient binary blob, which will be added to the `.apk` as `assemblies/rc.bin`. During process startup, `assemblies/rc.bin` will be proved to `monovm_runtimeconfig_initialize()`, which will parse `rc.bin`. Certain `runtimeconfig.json` properties are *reserved*: if they're specified within `runtimeconfig.json`, then the `<RuntimeConfigParser/>` task will throw an `ArgumentException`, and the build will fail. The reserved properties are controlled by the `@(_RuntimeConfigReservedProperties)` item group, and are reserved because the Xamarin.Android runtime needs to control the value of these properties for proper app execution, e.g. `PINVOKE_OVERRIDE` (cf84e1b, 0cd890b). Co-authored-by: Marek Habersack <[email protected]> [0]: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/#runtimeconfigjson [1]: https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.getdata?view=net-5.0 [2]: https://github.com/dotnet/runtime/blob/01b7e73cd378145264a7cb7a09365b41ed42b240/src/tasks/RuntimeConfigParser/RuntimeConfigParser.cs
- Loading branch information
1 parent
866f464
commit 1985495
Showing
20 changed files
with
195 additions
and
10 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
50 changes: 50 additions & 0 deletions
50
...oid.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.RuntimeConfig.targets
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,50 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.Android.Sdk.RuntimeConfig.targets | ||
MSBuild logic related to *.runtimeconfig.json files. | ||
See: https://github.com/dotnet/runtime/blob/b13715b6984889a709ba29ea8a1961db469f8805/src/mono/nuget/Microsoft.NET.Runtime.RuntimeConfigParser.Task/README.md | ||
*********************************************************************************************** | ||
--> | ||
<Project> | ||
|
||
<Import Sdk="Microsoft.NET.Runtime.RuntimeConfigParser.Task" Project="Sdk.props" /> | ||
|
||
<PropertyGroup> | ||
<!-- HACK: workaround https://github.com/dotnet/runtime/issues/53811 --> | ||
<RuntimeConfigParserTasksAssemblyPath>$([System.IO.Path]::GetDirectoryName($(RuntimeConfigParserTasksAssemblyPath)))/net6.0/$([System.IO.Path]::GetFileName($(RuntimeConfigParserTasksAssemblyPath)))</RuntimeConfigParserTasksAssemblyPath> | ||
<_BinaryRuntimeConfigPath>$(IntermediateOutputPath)$(ProjectRuntimeConfigFileName).bin</_BinaryRuntimeConfigPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- | ||
See: https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#step-3-%2D-prepare-runtime-properties | ||
These properties shouldn't be used in Xamarin.Android apps as there are no directories the runtime can search, | ||
everything related to assemblies or shared libraries must go through the Xamarin.Android native runtime. | ||
--> | ||
<_RuntimeConfigReservedProperties Include="TRUSTED_PLATFORM_ASSEMBLIES"/> | ||
<_RuntimeConfigReservedProperties Include="APP_PATHS"/> | ||
<_RuntimeConfigReservedProperties Include="APP_NI_PATHS"/> | ||
<_RuntimeConfigReservedProperties Include="NATIVE_DLL_SEARCH_DIRECTORIES"/> | ||
<_RuntimeConfigReservedProperties Include="PLATFORM_RESOURCE_ROOTS"/> | ||
<_RuntimeConfigReservedProperties Include="PINVOKE_OVERRIDE"/> | ||
</ItemGroup> | ||
|
||
<Target Name="_ParseRuntimeConfigFiles" | ||
AfterTargets="GenerateBuildRuntimeConfigurationFiles" | ||
Condition=" '$(GenerateRuntimeConfigurationFiles)' == 'true' " | ||
Inputs="$(ProjectRuntimeConfigFilePath)" | ||
Outputs="$(_BinaryRuntimeConfigPath)"> | ||
<RuntimeConfigParserTask | ||
RuntimeConfigFile="$(ProjectRuntimeConfigFilePath)" | ||
OutputFile="$(_BinaryRuntimeConfigPath)" | ||
RuntimeConfigReservedProperties="@(_RuntimeConfigReservedProperties)" | ||
/> | ||
<ItemGroup> | ||
<FileWrites Include="$(_BinaryRuntimeConfigPath)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
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
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
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
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.