Skip to content

Commit 7f2010a

Browse files
committed
android: Set up Mono buildsystem
Adds support for building Mono templates for Android in 3.2/master. We use the script from https://github.com/godotengine/godot-mono-builds to build Mono for all arches with the right options, and a patch included from https://github.com/godotengine/godot/blob/master/modules/mono/build_scripts/patches/fix-mono-android-tkill.diff which is also necessary. I also moved the SDK to a `sdk` folder to make the `$HOME` more tidy, especially since the Mono build scripts install the mono toolchains in `$HOME` too by default. Using a git clone for specific mono version tag, as the upstream tarballs are iffy (the 5.18.1.3 tarball lacks files needed to build on Android).
1 parent a62e856 commit 7f2010a

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

Dockerfile.android

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
FROM godot-fedora:latest
1+
ARG mono_version
2+
FROM godot-mono:${mono_version}
3+
ARG mono_version
24

35
RUN dnf -y install scons java-1.8.0-openjdk-devel ncurses-compat-libs unzip which gcc gcc-c++ && \
6+
mkdir sdk && cd sdk && \
47
curl -LO https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip && \
58
unzip sdk-tools-linux-4333796.zip && \
69
rm sdk-tools-linux-4333796.zip && \
710
yes | tools/bin/sdkmanager --licenses && \
8-
tools/bin/sdkmanager ndk-bundle 'platforms;android-23' 'build-tools;19.1.0' 'build-tools;28.0.3' 'platforms;android-28'
11+
tools/bin/sdkmanager ndk-bundle 'build-tools;28.0.3' 'platforms;android-28' 'cmake;3.10.2.4988404' && \
12+
cd ..
913

10-
ENV ANDROID_HOME=/root/
11-
ENV ANDROID_NDK_ROOT=/root/ndk-bundle/
14+
ENV ANDROID_HOME=/root/sdk/
15+
ENV ANDROID_NDK_ROOT=/root/sdk/ndk-bundle/
16+
17+
RUN dnf -y install git patch && \
18+
git clone https://github.com/mono/mono --branch mono-${mono_version} --single-branch && \
19+
cd mono && git submodule update --init && \
20+
patch -p1 < /root/files/patches/fix-mono-android-tkill.diff && \
21+
cd .. && \
22+
git clone https://github.com/godotengine/godot-mono-builds && \
23+
cd godot-mono-builds && \
24+
git checkout 9efec19e6b61fdc7201067cff4dd5b741399ae31 && \
25+
./build_mono_android.py configure --target=all --mono-sources=/root/mono && \
26+
./build_mono_android.py make --target=all --mono-sources=/root/mono && \
27+
cd .. && \
28+
rm -rf /root/mono /root/godot-mono-builds
1229

1330
CMD ['/bin/bash']

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ $podman build --build-arg mono_version=${mono_version} -t godot-mono-glue:latest
3030
$podman build --build-arg mono_version=${mono_version} -v $(pwd)/files:/root/files -t godot-windows:latest -f Dockerfile.windows .
3131
$podman build --build-arg mono_version=${mono_version} -t godot-ubuntu-32:latest -f Dockerfile.ubuntu-32 .
3232
$podman build --build-arg mono_version=${mono_version} -t godot-ubuntu-64:latest -f Dockerfile.ubuntu-64 .
33+
$podman build --build-arg mono_version=${mono_version} -t godot-android:latest -f Dockerfile.android .
3334

34-
$podman build -t godot-android:latest -f Dockerfile.android .
3535
$podman build -t godot-javascript:latest -f Dockerfile.javascript .
3636

3737
$podman build -t godot-xcode-packer:latest -f Dockerfile.xcode -v $(pwd)/files:/root/files .
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
diff --git a/libgc/include/private/gcconfig.h b/libgc/include/private/gcconfig.h
2+
index e2bdf13ac3e..f962200ba4e 100644
3+
--- a/libgc/include/private/gcconfig.h
4+
+++ b/libgc/include/private/gcconfig.h
5+
@@ -2255,6 +2255,14 @@
6+
# define GETPAGESIZE() getpagesize()
7+
# endif
8+
9+
+#if defined(HOST_ANDROID) && !(__ANDROID_API__ >= 23) \
10+
+ && ((defined(MIPS) && (CPP_WORDSZ == 32)) \
11+
+ || defined(ARM32) || defined(I386) /* but not x32 */)
12+
+ /* tkill() exists only on arm32/mips(32)/x86. */
13+
+ /* NDK r11+ deprecates tkill() but keeps it for Mono clients. */
14+
+# define USE_TKILL_ON_ANDROID
15+
+#endif
16+
+
17+
# if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
18+
/* OS has SVR4 generic features. Probably others also qualify. */
19+
# define SVR4
20+
diff --git a/libgc/pthread_stop_world.c b/libgc/pthread_stop_world.c
21+
index f93ce26b562..4a49a6d578c 100644
22+
--- a/libgc/pthread_stop_world.c
23+
+++ b/libgc/pthread_stop_world.c
24+
@@ -336,7 +336,7 @@ void GC_push_all_stacks()
25+
pthread_t GC_stopping_thread;
26+
int GC_stopping_pid;
27+
28+
-#ifdef HOST_ANDROID
29+
+#ifdef USE_TKILL_ON_ANDROID
30+
static
31+
int android_thread_kill(pid_t tid, int sig)
32+
{
33+
diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c
34+
index ad9b8823f8f..3542b32b540 100644
35+
--- a/mono/metadata/threads.c
36+
+++ b/mono/metadata/threads.c
37+
@@ -77,8 +77,12 @@ mono_native_thread_join_handle (HANDLE thread_handle, gboolean close_handle);
38+
#include <zircon/syscalls.h>
39+
#endif
40+
41+
-#if defined(HOST_ANDROID) && !defined(TARGET_ARM64) && !defined(TARGET_AMD64)
42+
-#define USE_TKILL_ON_ANDROID 1
43+
+#if defined(HOST_ANDROID) && !(__ANDROID_API__ >= 23) \
44+
+ && ((defined(MIPS) && (CPP_WORDSZ == 32)) \
45+
+ || defined(ARM32) || defined(I386) /* but not x32 */)
46+
+ /* tkill() exists only on arm32/mips(32)/x86. */
47+
+ /* NDK r11+ deprecates tkill() but keeps it for Mono clients. */
48+
+# define USE_TKILL_ON_ANDROID
49+
#endif
50+
51+
#ifdef HOST_ANDROID
52+
diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c
53+
index 3e4bf93de5f..79c9f731fe7 100644
54+
--- a/mono/utils/mono-threads-posix.c
55+
+++ b/mono/utils/mono-threads-posix.c
56+
@@ -31,8 +31,12 @@
57+
58+
#include <errno.h>
59+
60+
-#if defined(HOST_ANDROID) && !defined(TARGET_ARM64) && !defined(TARGET_AMD64)
61+
-#define USE_TKILL_ON_ANDROID 1
62+
+#if defined(HOST_ANDROID) && !(__ANDROID_API__ >= 23) \
63+
+ && ((defined(MIPS) && (CPP_WORDSZ == 32)) \
64+
+ || defined(ARM32) || defined(I386) /* but not x32 */)
65+
+ /* tkill() exists only on arm32/mips(32)/x86. */
66+
+ /* NDK r11+ deprecates tkill() but keeps it for Mono clients. */
67+
+# define USE_TKILL_ON_ANDROID
68+
#endif
69+
70+
#ifdef USE_TKILL_ON_ANDROID

0 commit comments

Comments
 (0)