diff options
author | therzok <marius.ungureanu@xamarin.com> | 2018-01-23 17:48:38 +0300 |
---|---|---|
committer | therzok <marius.ungureanu@xamarin.com> | 2018-02-08 13:44:27 +0300 |
commit | 5559c98459fb43d28115b16863032618fd6ad2fe (patch) | |
tree | 91c395a795e911154dd73b407a40ca6bab8994eb /main/build/MacOSX/monostub.mm | |
parent | 4daa08a2f8305b11dc944b512658aea0a59b5a34 (diff) |
[Launcher] Statically link in libxammac-system.a
This avoids shipping libxammac.dylib and uses a xammac static
lib which works with a system wide mono.
Thus, most of monostub code is now obsolete. To clean up later
once other users of monostub don't use this file anymore
Diffstat (limited to 'main/build/MacOSX/monostub.mm')
-rw-r--r-- | main/build/MacOSX/monostub.mm | 108 |
1 files changed, 64 insertions, 44 deletions
diff --git a/main/build/MacOSX/monostub.mm b/main/build/MacOSX/monostub.mm index db58b5f57a..bc24d663d1 100644 --- a/main/build/MacOSX/monostub.mm +++ b/main/build/MacOSX/monostub.mm @@ -12,15 +12,21 @@ #include <ctype.h> #include <time.h> -#include "monostub-utils.h" - -#import <Foundation/Foundation.h> - +#if XM_SYSTEM +#include <main.h> +#include <launch.h> +#include <runtime.h> +#else typedef int (* mono_main) (int argc, char **argv); typedef void (* mono_free) (void *ptr); typedef char * (* mono_get_runtime_build_info) (void); +#endif typedef void (* gobject_tracker_init) (void *libmono); +#include "monostub-utils.h" + +#import <Foundation/Foundation.h> + #if XM_REGISTRAR extern #if EXTERN_C @@ -37,7 +43,7 @@ extern void xamarin_create_classes (); #endif -void *libmono, *libxammac; +void *libmono; static void exit_with_message (const char *reason, char *argv0) @@ -269,6 +275,56 @@ try_load_gobject_tracker (void *libmono, char *entry_executable) } } +static void +run_md_bundle_if_needed(NSString *appDir, int argc, char **argv) +{ + // if we are running inside an app bundle and --start-app-bundle has been passed + // run the actual bundle and exit. + if (![appDir isEqualToString:@"."] && argc > 1 && !strcmp(argv[1], "--start-app-bundle")) { + NSArray *arguments = [NSArray array]; + if (argc > 2) { + NSString *strings[argc-2]; + for (int i = 0; i < argc-2; i++) + strings [i] = [[NSString alloc] initWithUTF8String:argv[i+2]]; + arguments = [NSArray arrayWithObjects:strings count:argc-2]; + } + run_md_bundle (appDir, arguments); + } +} + +static void +init_registrar() +{ +#if XM_REGISTRAR + xamarin_create_classes_Xamarin_Mac (); +#elif STATIC_REGISTRAR + xamarin_create_classes (); +#endif +} + +#ifdef XM_SYSTEM +extern "C" +void xamarin_app_initialize(xamarin_initialize_data *data) +{ + setenv ("MONO_GC_PARAMS", "major=marksweep-conc,nursery-size=8m", 0); + + run_md_bundle_if_needed(data->app_dir, data->argc, data->argv); + + data->requires_relaunch = update_environment ([[data->app_dir stringByAppendingPathComponent:@"Contents"] UTF8String], true); + + if (data->requires_relaunch) + return; + + correct_locale(); +} + +extern "C" int +xammac_setup () +{ + init_registrar(); + return 0; +} +#else int main (int argc, char **argv) { //clock_t start = clock(); @@ -286,18 +342,7 @@ int main (int argc, char **argv) NSString *appDir = [[NSBundle mainBundle] bundlePath]; - // if we are running inside an app bundle and --start-app-bundle has been passed - // run the actual bundle and exit. - if (![appDir isEqualToString:@"."] && argc > 1 && !strcmp(argv[1],"--start-app-bundle")) { - NSArray *arguments = [NSArray array]; - if (argc > 2) { - NSString *strings[argc-2]; - for (int i = 0; i < argc-2; i++) - strings [i] = [[NSString alloc] initWithUTF8String:argv[i+2]]; - arguments = [NSArray arrayWithObjects:strings count:argc-2]; - } - run_md_bundle (appDir, arguments); - } + run_md_bundle_if_needed(appDir, argc, argv); // can be overridden with plist string MonoMinVersion NSString *req_mono_version = @"5.2.0.171"; @@ -368,33 +413,7 @@ int main (int argc, char **argv) exit_with_message ((char *)[msg UTF8String], argv[0]); } -#if XM_REGISTRAR - libxammac = dlopen ("@loader_path/libxammac.dylib", RTLD_LAZY); - if (!libxammac) { - libxammac = dlopen ("@loader_path/../Resources/lib/monodevelop/bin/libxammac.dylib", RTLD_LAZY); - if (!libxammac) { - fprintf (stderr, "Failed to load libxammac.dylib: %s\n", dlerror ()); - NSString *msg = @"This application requires Xamarin.Mac native library side-by-side."; - exit_with_message ((char *)[msg UTF8String], argv[0]); - } - } - - xamarin_create_classes_Xamarin_Mac (); -#endif - -#if STATIC_REGISTRAR - libxammac = dlopen ("@loader_path/libxammac.dylib", RTLD_LAZY); - if (!libxammac) { - libxammac = dlopen ("@loader_path/../Resources/lib/monodevelop/bin/libxammac.dylib", RTLD_LAZY); - if (!libxammac) { - fprintf (stderr, "Failed to load libxammac.dylib: %s\n", dlerror ()); - NSString *msg = @"This application requires Xamarin.Mac native library side-by-side."; - exit_with_message ((char *)[msg UTF8String], argv[0]); - } - } - - xamarin_create_classes (); -#endif + init_registrar(); try_load_gobject_tracker (libmono, argv [0]); @@ -449,3 +468,4 @@ int main (int argc, char **argv) return _mono_main (argc + extra_argc + injected, new_argv); } +#endif |