Stop using environment variables to pass information to mono
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Our code passes multiple values to mono using environment variables:
```shell
xamarin-macios/runtime $ git grep "[^n]setenv [(]\""
launcher.m: setenv ("MONO_DISABLE_SHARED_AREA", "", 1);
launcher.m: setenv ("MONO_REGISTRY_PATH", [[appDirectory path] UTF8String], 1);
launcher.m: setenv ("MONO_DEBUG", "no-gdb-backtrace", 0);
launcher.m: setenv ("MONO_CFG_DIR", [monobundle_dir UTF8String], 0);
monotouch-main.m: setenv ("MONO_PATH", c_bundle_path, 1);
monotouch-main.m: setenv ("MONO_XMLSERIALIZER_THS", "no", 1);
monotouch-main.m: setenv ("DYLD_BIND_AT_LAUNCH", "1", 1);
monotouch-main.m: setenv ("MONO_REFLECTION_SERIALIZER", "yes", 1);
xamarin-macios/runtime $ git grep push_env
launcher.m:push_env (const char *variable, NSString *str_value)
launcher.m: push_env ("DYLD_FALLBACK_LIBRARY_PATH", [NSString stringWithFormat: @"%s/lib:/usr/local/lib:/lib:/usr/lib", getenv ("HOME")]);
launcher.m: push_env ("DYLD_FALLBACK_LIBRARY_PATH", [res_dir stringByAppendingPathComponent: @"/lib"]);
launcher.m: push_env ("DYLD_FALLBACK_LIBRARY_PATH", [[NSString stringWithUTF8String: mono_runtime_prefix] stringByAppendingPathComponent: @"/lib"]);
launcher.m: push_env ("PKG_CONFIG_PATH", @"/Library/Frameworks/Mono.framework/External/pkgconfig");
launcher.m: push_env ("PKG_CONFIG_PATH", [res_dir stringByAppendingPathComponent: @"/lib/pkgconfig"]);
launcher.m: push_env ("PKG_CONFIG_PATH", [res_dir stringByAppendingPathComponent: @"/share/pkgconfig"]);
launcher.m: push_env ("MONO_GAC_PREFIX", res_dir);
launcher.m: push_env ("PATH", bin_dir);
```
The problem is that subprocesses inherit environment variables, and the values we set here are unlikely to have the correct values for all possible subprocesses.
So we need to come up with alternative methods of passing information to mono. There are a few possibilities:
* We can use the mono embedding API to set fields/call methods.
* We can add native embedding API to mono to set the desired values.
* If we always disable a particular feature, that feature could be completely removed from our mono builds instead.
* Other ideas?
There's probably not a single solution for all variables, each solution would have to be considered separately.
List of environment variables (from the grep above):
* [ ] MONO_COMPRESSED_INTERFACE_BITMAP
* [ ] MONO_DISABLE_SHARED_AREA
* [ ] MONO_REGISTRY_PATH: this is already known to cause problems, see #6120.
* [ ] MONO_DEBUG
* [ ] MONO_CFG_DIR
* [ ] MONO_PATH
* [ ] MONO_XMLSERIALIZER_THS
* [ ] MONO_REFLECTION_SERIALIZER
* [ ] MONO_GAC_PREFIX
* [ ] DYLD_BIND_AT_LAUNCH: this looks redundant, the setenv call can probably just be removed (because setting dyld variables typically has no effect after the process has launched). This was introduced [here](https://github.com/xamarin/maccore/commit/c6de09523ee3b418c8d3d2b753a76cae1ca75c41) (which doesn't describe much).
* [ ] DYLD_FALLBACK_LIBRARY_PATH: https://xamarinhq.slack.com/archives/C03CCJHCF/p1558685132009000
* [ ] PKG_CONFIG_PATH:
* [ ] PATH: we can probably not touch this one
This is only an issue on macOS, because iOS apps can't launch subprocesses.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.