Skip to content

Commit 67fe854

Browse files
jonpryorgrendello
authored andcommitted
[monodroid] Allow the SGEN Bridge version to be specified (#219)
[Mono has support for improved SGEN GC Bridge behavior][0] which bumps the value of `SGEN_BRIDGE_VERSION` from `4` to `5`, and will be present within Mono 4.8. Xamarin.Android, meanwhile, is currently targeting Mono 4.6, which won't be getting support for this new SGEN bridge version. What is desired is a way to use xamarin-android with Mono 4.7/4.8 to test out the new GC bridge behavior, without breaking existing Mono 4.6 support. The solution is a new MSBuild property, `$(MonoSgenBridgeVersion)`, which allows overriding the `SGEN_BRIDGE_VERSION` value used when building the `libmono-android` native library. By default this MSBuild prpoperty is `4`, for compatibility with Mono 4.6. [0]: https://github.com/mono/mono/pull/3422/files
1 parent e176d19 commit 67fe854

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Configuration.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<NeedMxe Condition=" '$(HostOS)' == 'Darwin' ">true</NeedMxe>
2626
<MakeConcurrency Condition=" '$(MakeConcurrency)' == '' And '$(HostCpuCount)' != '' ">-j$(HostCpuCount)</MakeConcurrency>
2727
<ManagedRuntime Condition=" '$(ManagedRuntime)' == '' And '$(OS)' != 'Windows_NT' ">mono</ManagedRuntime>
28+
<MonoSgenBridgeVersion Condition=" '$(MonoSgenBridgeVersion)' == '' ">4</MonoSgenBridgeVersion>
2829
<TargetFrameworkRootPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\lib\xbuild-frameworks</TargetFrameworkRootPath>
2930
<HOME Condition=" '$(HOME)' == '' ">$(HOMEDRIVE)$(HOMEPATH)</HOME>
3031
<AndroidApiLevel Condition=" '$(AndroidApiLevel)' == '' ">24</AndroidApiLevel>

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ Overridable MSBuild properties include:
9393
`external/Java.Interop` directory, maintained by `git submodule update`.
9494
* `$(MakeConcurrency)`: **make**(1) parameters to use intended to influence
9595
the number of CPU cores used when **make**(1) executes. By default this uses
96-
`-jCOUNT`, where `COUNT` is obtained from `sysctl hw.ncpu`.
96+
`-jCOUNT`, where `COUNT` is obtained from `sysctl hw.ncpu`.
97+
* `$(MonoSgenBridgeVersion)`: The Mono SGEN Bridge version to support.
98+
Valid values include:
99+
100+
* `4`: Mono 4.6 support. This is the default.
101+
* `5`: Mono 4.8 support.
97102

98103
# Build Requirements
99104

src/monodroid/jni/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif
1111
LOCAL_CFLAGS = $(COMMON_CFLAGS) \
1212
-std=c99 \
1313
-DHAVE_LINUX_NETLINK_H=1 -DHAVE_LINUX_RTNETLINK_H=1 \
14+
-DSGEN_BRIDGE_VERSION=$(SGEN_BRIDGE_VERSION) \
1415
-D_REENTRANT -DPLATFORM_ANDROID -DANDROID -DLINUX -Dlinux -D__linux_ \
1516
-DHAVE_CONFIG_H -DJI_DLL_EXPORT -DMONO_DLL_EXPORT \
1617
-I$(topdir)/libmonodroid/zip -I$(BUILDDIR)/include -I$(BUILDDIR)/include/eglib \

src/monodroid/jni/dylib-mono.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ typedef uint8_t mono_byte;
120120
#endif
121121
#endif
122122

123-
enum {
124-
SGEN_BRIDGE_VERSION = 4
125-
};
123+
#ifndef SGEN_BRIDGE_VERSION
124+
#error SGEN_BRIDGE_VERSION must be defined! (Use the `$(MonoSgenBridgeVersion)` MSBuild property)
125+
#endif /* ndef SGEN_BRIDGE_VERSION */
126+
127+
#if (SGEN_BRIDGE_VERSION < 4) || (SGEN_BRIDGE_VERSION >= 6)
128+
#error Only SGEN_BRIDGE_VERSION/$(MonoSgenBridgeVersion) values of 4 or 5 are supported.
129+
#endif /* SGEN_BRIDGE_VERSION check */
126130

127131
typedef enum {
128132
/* Instances of this class should be scanned when computing the transitive dependency among bridges. E.g. List<object>*/

src/monodroid/monodroid.targets

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
Outputs="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.debug.so');@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.release.so')">
1414
<PropertyGroup>
1515
<_AppAbi>@(AndroidSupportedTargetJitAbi->'%(Identity)', ' ')</_AppAbi>
16+
<_NdkBuildArgs>CONFIGURATION=$(Configuration) SGEN_BRIDGE_VERSION=$(MonoSgenBridgeVersion)</_NdkBuildArgs>
1617
</PropertyGroup>
1718
<WriteLinesToFile
1819
File="jni\Application.mk"
1920
Lines="APP_ABI := $(_AppAbi)"
2021
Overwrite="True"
2122
/>
2223
<Exec
23-
Command="$(AndroidToolchainDirectory)\ndk\ndk-build CONFIGURATION=$(Configuration) NDK_LIBS_OUT=./libs/Debug NDK_OUT=./obj/Debug V=1"
24+
Command="$(AndroidToolchainDirectory)\ndk\ndk-build $(_NdkBuildArgs) NDK_LIBS_OUT=./libs/Debug NDK_OUT=./obj/Debug V=1"
2425
/>
2526
<Copy
2627
SourceFiles="@(AndroidSupportedTargetJitAbi->'obj\Debug\local\%(Identity)\libmonodroid.so')"
@@ -31,7 +32,7 @@
3132
DestinationFiles="@(AndroidSupportedTargetJitAbi->'$(OutputPath)\%(Identity)\libmono-android.debug.so')"
3233
/>
3334
<Exec
34-
Command="$(AndroidToolchainDirectory)\ndk\ndk-build CONFIGURATION=$(Configuration) NDK_LIBS_OUT=./libs/Release NDK_OUT=./obj/Release V=1"
35+
Command="$(AndroidToolchainDirectory)\ndk\ndk-build $(_NdkBuildArgs) NDK_LIBS_OUT=./libs/Release NDK_OUT=./obj/Release V=1"
3536
/>
3637
<Copy
3738
SourceFiles="@(AndroidSupportedTargetJitAbi->'obj\Release\local\%(Identity)\libmonodroid.so')"
@@ -45,10 +46,10 @@
4546
<Target Name="_CleanRuntimes"
4647
AfterTargets="Clean">
4748
<Exec
48-
Command="$(AndroidToolchainDirectory)\ndk\ndk-build CONFIGURATION=$(Configuration) NDK_LIBS_OUT=./libs/Debug NDK_OUT=./obj/Debug V=1 clean"
49+
Command="$(AndroidToolchainDirectory)\ndk\ndk-build $(_NdkBuildArgs) NDK_LIBS_OUT=./libs/Debug NDK_OUT=./obj/Debug V=1 clean"
4950
/>
5051
<Exec
51-
Command="$(AndroidToolchainDirectory)\ndk\ndk-build CONFIGURATION=$(Configuration) NDK_LIBS_OUT=./libs/Release NDK_OUT=./obj/Release V=1 clean"
52+
Command="$(AndroidToolchainDirectory)\ndk\ndk-build $(_NdkBuildArgs) NDK_LIBS_OUT=./libs/Release NDK_OUT=./obj/Release V=1 clean"
5253
/>
5354
<RemoveDir Directories="obj\local;libs" />
5455
<Delete Files="jni\config.include;jni\machine.config.include;jni\Application.mk" />

0 commit comments

Comments
 (0)