Skip to content

Commit

Permalink
[ObjCRuntime] Remove unnecessary macOS code from .NET. (#18967)
Browse files Browse the repository at this point in the history
In Xamarin.Mac we have some code to support unusual ways of creating app
bundles while including Xamarin.Mac, and also dynamic loading of the Mono
runtime.

In .NET, we don't support these unusual app bundle creating logic for any
platform, and the Mono runtime isn't even an option for macOS, so exclude some
of the corresponding code from .NET.

This fixes a few warnings in NativeAOT about this code not being trimmer-safe.
  • Loading branch information
rolfbjarne authored Sep 11, 2023
1 parent de762d6 commit d6eb395
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ unsafe static void Initialize (InitializationOptions* options)
if (options->Size != Marshal.SizeOf<InitializationOptions> ()) {
var msg = $"Version mismatch between the native {ProductName} runtime and {AssemblyName}. Please reinstall {ProductName}.";
NSLog (msg);
#if MONOMAC
#if MONOMAC && !NET
try {
// Print out where Xamarin.Mac.dll and the native runtime was loaded from.
NSLog ($"{AssemblyName} was loaded from {typeof (NSObject).Assembly.Location}");
Expand Down
4 changes: 4 additions & 0 deletions src/ObjCRuntime/Runtime.mac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ static void VerifyMonoVersion ()

unsafe static void InitializePlatform (InitializationOptions* options)
{
#if !NET
// BaseDirectory may not be set in some Mono embedded environments
// so try some reasonable fallbacks in these cases.
#endif
string basePath = AppDomain.CurrentDomain.BaseDirectory;
#if !NET
if(!string.IsNullOrEmpty(basePath))
basePath = Path.Combine (basePath, "..");
else {
Expand All @@ -189,6 +192,7 @@ unsafe static void InitializePlatform (InitializationOptions* options)
basePath = Path.Combine (Environment.CurrentDirectory, "..");
}
}
#endif

ResourcesPath = Path.Combine (basePath, "Resources");
FrameworksPath = Path.Combine (basePath, "Frameworks");
Expand Down

6 comments on commit d6eb395

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.