[DO NOT MERGE] Better mkbundle interop #1702
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: this PR can be merged ONLY after Xamarin.Android can update its Mono
to a version which includes this commit (the commit is now in the
mono/2018-06branch).It would be best that Mono bump to pull the commit would be added to this PR, so that the tests succeed and we have no broken
builds.
Xamarin.Android side of the Mono's mkbundle update which makes it easier (and
safer) to introduce changes in the template generated by mkbundle when creating
the application bundle.
Code generated by mkbundle calls into the Mono runtime and in order for this to
work on Xamarin.Android, libmonodroid needs to properly initialize the bundle or
the application won't work (
dlsymwon't be able to find the Mono runtimesymbols). This has been done by patching the generated code using plain
search-and-replace which is very fragile even to the slightest changes and it
doesn't guarantee that any new additions won't break the Xamarin.Android
bundle (see #1651)
Mono's mkbundle has been updated (see mono/mono@170e944)
to support third parties, like Xamarin.Android, which need to use special
methods to initialize the bundle. The third party provides a small bit of source
code with a dispatch structure (mkbundle has its own default version of the
structure) which contains pointers to all the Mono runtime methods required by
the initialization code. The provided code is inserted by mkbundle in place of
its default version. If there are any incompatibilities between the two
structures (such as missing pointers, invalid signature, additional pointers
etc) then the bundle will not build, thus allowing the third party to notice the
problem early and update its version of the structure. Likewise, if the build
succeeds but the pointers aren't correctly initialized (i.e. they are
null), aruntime check will discover the fact and fail the application gracefully.
The bit of inserted code also contains platform-specific logging function in
place of the calls to
fprintfused by mkbundle previously. For Xamarin.Androidit means that all the error messages will end up in logcat.
Xamarin.Android's version of the structure and the error logging function are
found in the
mkbundle-api.hC header which is used both when buildinglibmonodroid (to ensure that when initializing the generated bundle libmonodroid
is ABI-compatible with it) and is copied to the framework directory to be used
when generating the application bundle.
Sample of XA-generated bundle code:
https://gist.github.com/grendello/465ecec96b3bee801e6bbc5a28019833