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

Simplify icudat file lookup by specifying ICU_DAT_FILE_PATH as a RuntimeHostConfigurationOption #18914

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@
<TargetPlatformSupported Condition=" '$(TargetPlatformIdentifier)' == '$(_PlatformName)' ">true</TargetPlatformSupported>
</PropertyGroup>

<PropertyGroup Condition="'$(_GlobalizationDataFileLocation)' == ''">
<_GlobalizationDataFileLocation Condition="'$(_UseNativeAot)' == 'true'">Resource</_GlobalizationDataFileLocation>
<_GlobalizationDataFileLocation Condition="'$(_UseNativeAot)' != 'true'">Assembly</_GlobalizationDataFileLocation>
</PropertyGroup>

<!-- dotnet publish -->
<Import Project="Xamarin.Shared.Sdk.Publish.targets" />

Expand Down Expand Up @@ -1090,7 +1085,6 @@
<!-- List all the properties passed to xamarin_bridge_vm_initialize in xamarin_vm_initialize (in runtime.m) -->
<_RuntimeConfigReservedProperties Include="APP_PATHS" />
<_RuntimeConfigReservedProperties Include="PINVOKE_OVERRIDE" />
<_RuntimeConfigReservedProperties Include="ICU_DAT_FILE_PATH" />
<_RuntimeConfigReservedProperties Include="TRUSTED_PLATFORM_ASSEMBLIES" />
<_RuntimeConfigReservedProperties Include="NATIVE_DLL_SEARCH_DIRECTORIES" />
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER" />
Expand Down Expand Up @@ -1691,7 +1685,7 @@
'%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)' == '$(_GlobalizationDataFile)' And
'%(ResolvedFileToPublish.NuGetPackageId)' == '$(_MonoNugetPackageId)'
"
PublishFolderType="$(_GlobalizationDataFileLocation)"
PublishFolderType="Assembly"
/>

<!-- Remove the libxamarin-*.dylib files we don't want -->
Expand Down
8 changes: 8 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2870,13 +2870,21 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- needed for GetTargetPath/Build/Rebuild task outputs -->
<_AppExtensionBundlePath>$(MSBuildProjectDirectory)\$(AppBundleDir)</_AppExtensionBundlePath>
</PropertyGroup>
<PropertyGroup>
<_GlobalizationDataFileAppBundleRelativePath Condition="'$(_AppContentsRelativePath)' == ''">$(_GlobalizationDataFile)</_GlobalizationDataFileAppBundleRelativePath>
<_GlobalizationDataFileAppBundleRelativePath Condition="'$(_AppContentsRelativePath)' != ''">$(_AppContentsRelativePath)\$(_GlobalizationDataFile)</_GlobalizationDataFileAppBundleRelativePath>
</PropertyGroup>
<ItemGroup Condition="'$(IsAppExtension)' == 'true'">
<_AppExtensionBundlePath Include="$(MSBuildProjectDirectory)\$(AppBundleDir)">
<!-- We need this metadata to fix the source in VS -->
<BuildSessionId>$(BuildSessionId)</BuildSessionId>
<BuildServerPath>..\..\$(BuildAppName)\$(BuildSessionId)\$(AppBundleDir)</BuildServerPath>
</_AppExtensionBundlePath>
</ItemGroup>
<ItemGroup>
<!-- Replacing backslashes with slashes is required since MSBuild has some issue with resolving backslashes next to a property value: https://github.com/dotnet/msbuild/issues/9200 -->
<RuntimeHostConfigurationOption Include="ICU_DAT_FILE_PATH" Value="$(_GlobalizationDataFileAppBundleRelativePath.Replace('\','/'))" />
emaf marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>
</Target>

<Target Name="_CompileProductDefinition" Condition="$(CreatePackage)" DependsOnTargets="_WriteAppManifest;_ComputeTargetArchitectures">
Expand Down
28 changes: 2 additions & 26 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
#endif
int xamarin_log_level = 0;
const char *xamarin_executable_name = NULL;
#if DOTNET
const char *xamarin_icu_dat_file_name = NULL;
#endif
#if MONOMAC || TARGET_OS_MACCATALYST
NSString * xamarin_custom_bundle_name = @"MonoBundle";
#endif
Expand Down Expand Up @@ -2585,22 +2582,6 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
xamarin_vm_initialize ()
{
char *pinvokeOverride = xamarin_strdup_printf ("%p", &xamarin_pinvoke_override);
char *icu_dat_file_path = NULL;
int subtractPropertyCount = 0;

if (xamarin_icu_dat_file_name != NULL && *xamarin_icu_dat_file_name != 0) {
#if !defined (NATIVEAOT)
char path [1024];
if (!xamarin_locate_app_resource (xamarin_icu_dat_file_name, path, sizeof (path))) {
LOG (PRODUCT ": Could not locate the ICU data file '%s' in the app bundle.\n", xamarin_icu_dat_file_name);
} else {
icu_dat_file_path = strdup (path);
}
#endif // !defined (NATIVEAOT)
} else {
subtractPropertyCount++;
}

char *trusted_platform_assemblies = xamarin_compute_trusted_platform_assemblies ();
char *native_dll_search_directories = xamarin_compute_native_dll_search_directories ();

Expand All @@ -2613,7 +2594,6 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
"TRUSTED_PLATFORM_ASSEMBLIES",
"NATIVE_DLL_SEARCH_DIRECTORIES",
"RUNTIME_IDENTIFIER",
"ICU_DAT_FILE_PATH", // Must be last.
};
const char *propertyValues[] = {
xamarin_get_bundle_path (),
Expand All @@ -2622,20 +2602,16 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
trusted_platform_assemblies,
native_dll_search_directories,
RUNTIMEIDENTIFIER,
icu_dat_file_path, // might be NULL, if so we say we're passing one property less that what we really are (to skip this last one). This also means that this property must be the last one
};
static_assert (sizeof (propertyKeys) == sizeof (propertyValues), "The number of keys and values must be the same.");

int propertyCount = (int) (sizeof (propertyValues) / sizeof (propertyValues [0])) - subtractPropertyCount;
int propertyCount = (int) (sizeof (propertyValues) / sizeof (propertyValues [0]));
bool rv = xamarin_bridge_vm_initialize (propertyCount, propertyKeys, propertyValues);
xamarin_free (pinvokeOverride);

xamarin_free (pinvokeOverride);
xamarin_free (trusted_platform_assemblies);
xamarin_free (native_dll_search_directories);

if (icu_dat_file_path != NULL)
free (icu_dat_file_path);

if (!rv)
xamarin_assertion_message ("Failed to initialize the VM");
}
Expand Down
9 changes: 0 additions & 9 deletions tools/dotnet-linker/Steps/GenerateMainStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,8 @@ protected override void TryEndProcess ()

contents.AppendLine ("#include <stdlib.h>");
contents.AppendLine ();
contents.AppendLine ("extern \"C\" const char *xamarin_icu_dat_file_name;");
contents.AppendLine ();
contents.AppendLine ("static void xamarin_initialize_dotnet ()");
contents.AppendLine ("{");
if (Configuration.InvariantGlobalization) {
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1);");
} else {
if (Configuration.HybridGlobalization)
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_HYBRID\", \"1\", 1);");
contents.AppendLine ($"\txamarin_icu_dat_file_name = \"{Configuration.GlobalizationDataFile}\";");
}
if (Configuration.Application.PackageManagedDebugSymbols && Configuration.Application.UseInterpreter)
contents.AppendLine ($"\tsetenv (\"DOTNET_MODIFIABLE_ASSEMBLIES\", \"debug\", 1);");
contents.AppendLine ("}");
Expand Down