Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace System.IO.Tests
public class DisabledFileLockingSwitchTests
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/114951", typeof(PlatformDetection), nameof(PlatformDetection.IsSingleFile))]
public static void ConfigSwitchIsHonored()
{
Assert.Equal(OperatingSystem.IsWindows(), PlatformDetection.IsFileLockingEnabled);
Expand Down
3 changes: 0 additions & 3 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@
<!-- https://github.com/dotnet/runtime/issues/117045 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
<!-- https://github.com/dotnet/runtime/issues/114951 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Diagnostics.DiagnosticSource\tests\TestWithConfigSwitches\System.Diagnostics.DiagnosticSource.Switches.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime\tests\System.Runtime.Tests\InvariantTimezone\System.Runtime.InvariantTimezone.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime\tests\System.Text.Encoding.Tests\System.Text.Encoding.Tests.csproj" />
<!-- https://github.com/dotnet/runtime/issues/62547 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography\tests\System.Security.Cryptography.Tests.csproj" />
<!-- https://github.com/dotnet/runtime/issues/72908 -->
Expand Down
10 changes: 0 additions & 10 deletions src/mono/msbuild/android/build/AndroidBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@
<_CommonTargetsDir Condition="'$(_CommonTargetsDir)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', '..', 'common'))</_CommonTargetsDir>
</PropertyGroup>

<!-- This ItemGroup defines Android environment variables that are used for .NET feature switches. -->
<ItemGroup>
<AndroidEnv Condition="'$(InvariantGlobalization)' == 'true'" Include="DOTNET_SYSTEM_GLOBALIZATION_INVARIANT">
<Value>true</Value>
</AndroidEnv>
<AndroidEnv Condition="'$(PredefinedCulturesOnly)' == 'false'" Include="DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY">
<Value>false</Value>
</AndroidEnv>
</ItemGroup>

<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' == 'true'" Project="$(_CommonTargetsDir)CommonMobileBuild.props" />
<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(UseMonoRuntime)' == 'true'" Project="$(_CommonTargetsDir)RuntimeComponentManifest.targets" />
<Import Condition="'$(UseNativeAOTRuntime)' != 'true' and ('$(UseMonoRuntime)' == 'true' and '$(RunAOTCompilation)' == 'true')" Project="$(_CommonTargetsDir)MonoAOTCompiler.props" />
Expand Down
71 changes: 70 additions & 1 deletion src/tasks/AndroidAppBuilder/ApkBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.Android.Build;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -381,7 +382,13 @@ public ApkBuilder(TaskLoggingHelper logger)
cmakeLists = cmakeLists.Replace("%Defines%", defines.ToString());

File.WriteAllText(Path.Combine(OutputDir, "CMakeLists.txt"), cmakeLists);
File.WriteAllText(Path.Combine(OutputDir, monodroidSource), Utils.GetEmbeddedResource(monodroidSource));

string monodroidContent = Utils.GetEmbeddedResource(monodroidSource);
if (IsCoreCLR)
{
monodroidContent = RenderMonodroidCoreClrTemplate(monodroidContent);
}
File.WriteAllText(Path.Combine(OutputDir, monodroidSource), monodroidContent);

AndroidProject project = new AndroidProject("monodroid", runtimeIdentifier, AndroidNdk, logger);
project.GenerateCMake(OutputDir, MinApiLevel, StripDebugSymbols);
Expand Down Expand Up @@ -639,4 +646,66 @@ private static string NormalizePathToUnix(string path)

[GeneratedRegex(@"\.(\d)")]
private static partial Regex DotNumberRegex();

private string RenderMonodroidCoreClrTemplate(string monodroidContent)
{
// At the moment, we only set the AppContext properties, so it's all done here for simplicity.
// If we need to add more rendering logic, we can refactor this method later.
var appContextKeys = new StringBuilder();
appContextKeys.AppendLine(" appctx_keys[0] = \"RUNTIME_IDENTIFIER\";");
appContextKeys.AppendLine(" appctx_keys[1] = \"APP_CONTEXT_BASE_DIRECTORY\";");
appContextKeys.AppendLine(" appctx_keys[2] = \"HOST_RUNTIME_CONTRACT\";");

var appContextValues = new StringBuilder();
appContextValues.AppendLine(" appctx_values[0] = ANDROID_RUNTIME_IDENTIFIER;");
appContextValues.AppendLine(" appctx_values[1] = g_bundle_path;");
appContextValues.AppendLine();
appContextValues.AppendLine(" char contract_str[19];"); // 0x + 16 hex digits + '\0'
appContextValues.AppendLine(" snprintf(contract_str, 19, \"0x%zx\", (size_t)(&g_host_contract));");
appContextValues.AppendLine(" appctx_values[2] = contract_str;");
appContextValues.AppendLine();

// Parse runtime config properties and add them to the AppContext keys and values.
Dictionary<string, string> configProperties = ParseRuntimeConfigProperties();
int hardwiredAppContextProperties = 3; // For the hardwired AppContext keys and values above.
int i = 0;
foreach ((string key, string value) in configProperties)
{
appContextKeys.AppendLine($" appctx_keys[{i + hardwiredAppContextProperties}] = \"{key}\";");
appContextValues.AppendLine($" appctx_values[{i + hardwiredAppContextProperties}] = \"{value}\";");
i++;
}

// Replace the template placeholders.
string updatedContent = monodroidContent.Replace("%AppContextPropertyCount%", (configProperties.Count + hardwiredAppContextProperties).ToString())
.Replace("%AppContextKeys%", appContextKeys.ToString().TrimEnd())
.Replace("%AppContextValues%", appContextValues.ToString().TrimEnd());
return updatedContent;
}

private Dictionary<string, string> ParseRuntimeConfigProperties()
{
var configProperties = new Dictionary<string, string>();
string runtimeConfigPath = Path.Combine(AppDir ?? throw new InvalidOperationException("AppDir is not set"), $"{ProjectName}.runtimeconfig.json");

try
{
string jsonContent = File.ReadAllText(runtimeConfigPath);
using JsonDocument doc = JsonDocument.Parse(jsonContent);
JsonElement root = doc.RootElement;
if (root.TryGetProperty("runtimeOptions", out JsonElement runtimeOptions) && runtimeOptions.TryGetProperty("configProperties", out JsonElement propertiesJson))
{
foreach (JsonProperty property in propertiesJson.EnumerateObject())
{
configProperties[property.Name] = property.Value.ToString();
}
}
}
catch (Exception ex)
{
logger.LogMessage(MessageImportance.High, $"Error while parsing runtime config at {runtimeConfigPath}: {ex.Message}");
}

return configProperties;
}
}
13 changes: 3 additions & 10 deletions src/tasks/AndroidAppBuilder/Templates/monodroid-coreclr.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mono_droid_execute_assembly (const char* executable_path, void* coreclr_handle,
return rv;
}

#define PROPERTY_COUNT 3
#define PROPERTY_COUNT %AppContextPropertyCount%

static int
mono_droid_runtime_init (const char* executable)
Expand All @@ -202,17 +202,10 @@ mono_droid_runtime_init (const char* executable)
g_host_contract.external_assembly_probe = &external_assembly_probe;

const char* appctx_keys[PROPERTY_COUNT];
appctx_keys[0] = "RUNTIME_IDENTIFIER";
appctx_keys[1] = "APP_CONTEXT_BASE_DIRECTORY";
appctx_keys[2] = "HOST_RUNTIME_CONTRACT";
%AppContextKeys%

const char* appctx_values[PROPERTY_COUNT];
appctx_values[0] = ANDROID_RUNTIME_IDENTIFIER;
appctx_values[1] = g_bundle_path;

char contract_str[19]; // 0x + 16 hex digits + '\0'
snprintf(contract_str, 19, "0x%zx", (size_t)(&g_host_contract));
appctx_values[2] = contract_str;
%AppContextValues%

LOG_INFO ("Calling coreclr_initialize");
int rv = coreclr_initialize (
Expand Down
Loading