Skip to content

Commit

Permalink
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass …
Browse files Browse the repository at this point in the history
…it to MonoVM/CoreCLR. Fixes #12265. (#12272)

List all the assemblies in the app bundle and pass them to MonoVM/CoreCLR's in
the TRUSTED_PLATFORM_ASSEMBLIES initialization property.

This way CoreCLR knows where to find System.Private.CoreLib.dll for fat apps
(it's in the runtimeidentifier-specific subdirectory, and by default CoreCLR
will only look next to libcoreclr.dylib).

Fixes #12265.
  • Loading branch information
rolfbjarne authored Jul 29, 2021
1 parent 38140f2 commit 3d822de
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@
<_RuntimeConfigReservedProperties Include="APP_PATHS" />
<_RuntimeConfigReservedProperties Include="PINVOKE_OVERRIDE" />
<_RuntimeConfigReservedProperties Include="ICU_DAT_FILE_PATH" />
<_RuntimeConfigReservedProperties Include="TRUSTED_PLATFORM_ASSEMBLIES" />
</ItemGroup>
<RuntimeConfigParserTask
Condition="'$(GenerateRuntimeConfigurationFiles)' == 'true'"
Expand Down
55 changes: 55 additions & 0 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,55 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
#endif // !DOTNET

#if DOTNET

// List all the assemblies that we can find in the app bundle in:
// - The bundle directory
// - The runtimeidentifier-specific subdirectory
// Caller must free the return value using xamarin_free.
char *
xamarin_compute_trusted_platform_assemblies ()
{
const char *bundle_path = xamarin_get_bundle_path ();

NSMutableArray<NSString *> *files = [NSMutableArray array];
NSMutableArray<NSString *> *directories = [NSMutableArray array];
[directories addObject: [NSString stringWithUTF8String: bundle_path]];
[directories addObject: [NSString stringWithFormat: @"%s/.xamarin/%s", bundle_path, RUNTIMEIDENTIFIER]];

NSFileManager *manager = [NSFileManager defaultManager];
for (NSString *dir in directories) {
NSDirectoryEnumerator *enumerator = [manager enumeratorAtURL:[NSURL fileURLWithPath: dir]
includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants
errorHandler:nil];
for (NSURL *file in enumerator) {
// skip subdirectories
NSNumber *isDirectory = nil;
if (![file getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] || [isDirectory boolValue])
continue;

NSString *name = nil;
if (![file getResourceValue:&name forKey:NSURLNameKey error:nil])
continue;

if ([name length] < 4)
continue;

// We want dlls and exes
if ([name compare: @".dll" options: NSCaseInsensitiveSearch range: NSMakeRange ([name length] - 4, 4)] == NSOrderedSame) {
[files addObject: [dir stringByAppendingPathComponent: name]];
} else if ([name compare: @".exe" options: NSCaseInsensitiveSearch range: NSMakeRange ([name length] - 4, 4)] == NSOrderedSame) {
[files addObject: [dir stringByAppendingPathComponent: name]];
}
}
}

// Join them all together with a colon separating them
NSString *joined = [files componentsJoinedByString: @":"];
char *rv = xamarin_strdup_printf ("%s", [joined UTF8String]);
return rv;
}

void
xamarin_vm_initialize ()
{
Expand All @@ -2414,24 +2463,30 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
icu_dat_file_path = path;
}

char *trusted_platform_assemblies = xamarin_compute_trusted_platform_assemblies ();

// All the properties we pass here must also be listed in the _RuntimeConfigReservedProperties item group
// for the _CreateRuntimeConfiguration target in dotnet/targets/Xamarin.Shared.Sdk.targets.
const char *propertyKeys[] = {
"APP_PATHS",
"PINVOKE_OVERRIDE",
"ICU_DAT_FILE_PATH",
"TRUSTED_PLATFORM_ASSEMBLIES",
};
const char *propertyValues[] = {
xamarin_get_bundle_path (),
pinvokeOverride,
icu_dat_file_path,
trusted_platform_assemblies,
};
static_assert (sizeof (propertyKeys) == sizeof (propertyValues), "The number of keys and values must be the same.");

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

xamarin_free (trusted_platform_assemblies);

if (!rv)
xamarin_assertion_message ("Failed to initialize the VM");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIden
[Test]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64")]
// [TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")] // https://github.com/xamarin/xamarin-macios/issues/12265
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
public void BuildCoreCLR (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Expand Down

5 comments on commit 3d822de

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (no change)

Packages generated

View packages

Test results

2 tests failed, 222 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug (static registrar) [dotnet]: Failed
  • Documentation/All: Failed

Pipeline on Agent XAMBOT-1038.BigSur'
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac Mojave (10.14) ✅

Tests passed

All tests on macOS X Mac Mojave (10.14) passed.

Pipeline on Agent
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS Mac High Sierra (10.13) ✅

Tests passed

All tests on macOS X Mac High Sierra (10.13) passed.

Pipeline on Agent
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[runtime] List all assemblies in TRUSTED_PLATFORM_ASSEMBLIES as pass it to MonoVM/CoreCLR. Fixes #12265. (#12272)

Please sign in to comment.